hw.c 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313
  1. /*
  2. * Copyright (c) 2008-2009 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/io.h>
  17. #include <asm/unaligned.h>
  18. #include <linux/pci.h>
  19. #include "ath9k.h"
  20. #include "initvals.h"
  21. #define ATH9K_CLOCK_RATE_CCK 22
  22. #define ATH9K_CLOCK_RATE_5GHZ_OFDM 40
  23. #define ATH9K_CLOCK_RATE_2GHZ_OFDM 44
  24. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
  25. static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
  26. enum ath9k_ht_macmode macmode);
  27. static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
  28. struct ar5416_eeprom_def *pEepData,
  29. u32 reg, u32 value);
  30. static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
  31. static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan);
  32. /********************/
  33. /* Helper Functions */
  34. /********************/
  35. static u32 ath9k_hw_mac_usec(struct ath_hw *ah, u32 clks)
  36. {
  37. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  38. if (!ah->curchan) /* should really check for CCK instead */
  39. return clks / ATH9K_CLOCK_RATE_CCK;
  40. if (conf->channel->band == IEEE80211_BAND_2GHZ)
  41. return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
  42. return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
  43. }
  44. static u32 ath9k_hw_mac_to_usec(struct ath_hw *ah, u32 clks)
  45. {
  46. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  47. if (conf_is_ht40(conf))
  48. return ath9k_hw_mac_usec(ah, clks) / 2;
  49. else
  50. return ath9k_hw_mac_usec(ah, clks);
  51. }
  52. static u32 ath9k_hw_mac_clks(struct ath_hw *ah, u32 usecs)
  53. {
  54. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  55. if (!ah->curchan) /* should really check for CCK instead */
  56. return usecs *ATH9K_CLOCK_RATE_CCK;
  57. if (conf->channel->band == IEEE80211_BAND_2GHZ)
  58. return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
  59. return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
  60. }
  61. static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
  62. {
  63. struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
  64. if (conf_is_ht40(conf))
  65. return ath9k_hw_mac_clks(ah, usecs) * 2;
  66. else
  67. return ath9k_hw_mac_clks(ah, usecs);
  68. }
  69. /*
  70. * Read and write, they both share the same lock. We do this to serialize
  71. * reads and writes on Atheros 802.11n PCI devices only. This is required
  72. * as the FIFO on these devices can only accept sanely 2 requests. After
  73. * that the device goes bananas. Serializing the reads/writes prevents this
  74. * from happening.
  75. */
  76. void ath9k_iowrite32(struct ath_hw *ah, u32 reg_offset, u32 val)
  77. {
  78. if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
  79. unsigned long flags;
  80. spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
  81. iowrite32(val, ah->ah_sc->mem + reg_offset);
  82. spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
  83. } else
  84. iowrite32(val, ah->ah_sc->mem + reg_offset);
  85. }
  86. unsigned int ath9k_ioread32(struct ath_hw *ah, u32 reg_offset)
  87. {
  88. u32 val;
  89. if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
  90. unsigned long flags;
  91. spin_lock_irqsave(&ah->ah_sc->sc_serial_rw, flags);
  92. val = ioread32(ah->ah_sc->mem + reg_offset);
  93. spin_unlock_irqrestore(&ah->ah_sc->sc_serial_rw, flags);
  94. } else
  95. val = ioread32(ah->ah_sc->mem + reg_offset);
  96. return val;
  97. }
  98. bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
  99. {
  100. int i;
  101. BUG_ON(timeout < AH_TIME_QUANTUM);
  102. for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
  103. if ((REG_READ(ah, reg) & mask) == val)
  104. return true;
  105. udelay(AH_TIME_QUANTUM);
  106. }
  107. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  108. "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
  109. timeout, reg, REG_READ(ah, reg), mask, val);
  110. return false;
  111. }
  112. u32 ath9k_hw_reverse_bits(u32 val, u32 n)
  113. {
  114. u32 retval;
  115. int i;
  116. for (i = 0, retval = 0; i < n; i++) {
  117. retval = (retval << 1) | (val & 1);
  118. val >>= 1;
  119. }
  120. return retval;
  121. }
  122. bool ath9k_get_channel_edges(struct ath_hw *ah,
  123. u16 flags, u16 *low,
  124. u16 *high)
  125. {
  126. struct ath9k_hw_capabilities *pCap = &ah->caps;
  127. if (flags & CHANNEL_5GHZ) {
  128. *low = pCap->low_5ghz_chan;
  129. *high = pCap->high_5ghz_chan;
  130. return true;
  131. }
  132. if ((flags & CHANNEL_2GHZ)) {
  133. *low = pCap->low_2ghz_chan;
  134. *high = pCap->high_2ghz_chan;
  135. return true;
  136. }
  137. return false;
  138. }
  139. u16 ath9k_hw_computetxtime(struct ath_hw *ah,
  140. const struct ath_rate_table *rates,
  141. u32 frameLen, u16 rateix,
  142. bool shortPreamble)
  143. {
  144. u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
  145. u32 kbps;
  146. kbps = rates->info[rateix].ratekbps;
  147. if (kbps == 0)
  148. return 0;
  149. switch (rates->info[rateix].phy) {
  150. case WLAN_RC_PHY_CCK:
  151. phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
  152. if (shortPreamble && rates->info[rateix].short_preamble)
  153. phyTime >>= 1;
  154. numBits = frameLen << 3;
  155. txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
  156. break;
  157. case WLAN_RC_PHY_OFDM:
  158. if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
  159. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
  160. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  161. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  162. txTime = OFDM_SIFS_TIME_QUARTER
  163. + OFDM_PREAMBLE_TIME_QUARTER
  164. + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
  165. } else if (ah->curchan &&
  166. IS_CHAN_HALF_RATE(ah->curchan)) {
  167. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
  168. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  169. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  170. txTime = OFDM_SIFS_TIME_HALF +
  171. OFDM_PREAMBLE_TIME_HALF
  172. + (numSymbols * OFDM_SYMBOL_TIME_HALF);
  173. } else {
  174. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
  175. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  176. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  177. txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
  178. + (numSymbols * OFDM_SYMBOL_TIME);
  179. }
  180. break;
  181. default:
  182. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  183. "Unknown phy %u (rate ix %u)\n",
  184. rates->info[rateix].phy, rateix);
  185. txTime = 0;
  186. break;
  187. }
  188. return txTime;
  189. }
  190. void ath9k_hw_get_channel_centers(struct ath_hw *ah,
  191. struct ath9k_channel *chan,
  192. struct chan_centers *centers)
  193. {
  194. int8_t extoff;
  195. if (!IS_CHAN_HT40(chan)) {
  196. centers->ctl_center = centers->ext_center =
  197. centers->synth_center = chan->channel;
  198. return;
  199. }
  200. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  201. (chan->chanmode == CHANNEL_G_HT40PLUS)) {
  202. centers->synth_center =
  203. chan->channel + HT40_CHANNEL_CENTER_SHIFT;
  204. extoff = 1;
  205. } else {
  206. centers->synth_center =
  207. chan->channel - HT40_CHANNEL_CENTER_SHIFT;
  208. extoff = -1;
  209. }
  210. centers->ctl_center =
  211. centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
  212. centers->ext_center =
  213. centers->synth_center + (extoff *
  214. ((ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_20) ?
  215. HT40_CHANNEL_CENTER_SHIFT : 15));
  216. }
  217. /******************/
  218. /* Chip Revisions */
  219. /******************/
  220. static void ath9k_hw_read_revisions(struct ath_hw *ah)
  221. {
  222. u32 val;
  223. val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
  224. if (val == 0xFF) {
  225. val = REG_READ(ah, AR_SREV);
  226. ah->hw_version.macVersion =
  227. (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
  228. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  229. ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
  230. } else {
  231. if (!AR_SREV_9100(ah))
  232. ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
  233. ah->hw_version.macRev = val & AR_SREV_REVISION;
  234. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
  235. ah->is_pciexpress = true;
  236. }
  237. }
  238. static int ath9k_hw_get_radiorev(struct ath_hw *ah)
  239. {
  240. u32 val;
  241. int i;
  242. REG_WRITE(ah, AR_PHY(0x36), 0x00007058);
  243. for (i = 0; i < 8; i++)
  244. REG_WRITE(ah, AR_PHY(0x20), 0x00010000);
  245. val = (REG_READ(ah, AR_PHY(256)) >> 24) & 0xff;
  246. val = ((val & 0xf0) >> 4) | ((val & 0x0f) << 4);
  247. return ath9k_hw_reverse_bits(val, 8);
  248. }
  249. /************************************/
  250. /* HW Attach, Detach, Init Routines */
  251. /************************************/
  252. static void ath9k_hw_disablepcie(struct ath_hw *ah)
  253. {
  254. if (AR_SREV_9100(ah))
  255. return;
  256. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  257. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  258. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
  259. REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
  260. REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
  261. REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
  262. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  263. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  264. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
  265. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  266. }
  267. static bool ath9k_hw_chip_test(struct ath_hw *ah)
  268. {
  269. u32 regAddr[2] = { AR_STA_ID0, AR_PHY_BASE + (8 << 2) };
  270. u32 regHold[2];
  271. u32 patternData[4] = { 0x55555555,
  272. 0xaaaaaaaa,
  273. 0x66666666,
  274. 0x99999999 };
  275. int i, j;
  276. for (i = 0; i < 2; i++) {
  277. u32 addr = regAddr[i];
  278. u32 wrData, rdData;
  279. regHold[i] = REG_READ(ah, addr);
  280. for (j = 0; j < 0x100; j++) {
  281. wrData = (j << 16) | j;
  282. REG_WRITE(ah, addr, wrData);
  283. rdData = REG_READ(ah, addr);
  284. if (rdData != wrData) {
  285. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  286. "address test failed "
  287. "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  288. addr, wrData, rdData);
  289. return false;
  290. }
  291. }
  292. for (j = 0; j < 4; j++) {
  293. wrData = patternData[j];
  294. REG_WRITE(ah, addr, wrData);
  295. rdData = REG_READ(ah, addr);
  296. if (wrData != rdData) {
  297. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  298. "address test failed "
  299. "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  300. addr, wrData, rdData);
  301. return false;
  302. }
  303. }
  304. REG_WRITE(ah, regAddr[i], regHold[i]);
  305. }
  306. udelay(100);
  307. return true;
  308. }
  309. static const char *ath9k_hw_devname(u16 devid)
  310. {
  311. switch (devid) {
  312. case AR5416_DEVID_PCI:
  313. return "Atheros 5416";
  314. case AR5416_DEVID_PCIE:
  315. return "Atheros 5418";
  316. case AR9160_DEVID_PCI:
  317. return "Atheros 9160";
  318. case AR5416_AR9100_DEVID:
  319. return "Atheros 9100";
  320. case AR9280_DEVID_PCI:
  321. case AR9280_DEVID_PCIE:
  322. return "Atheros 9280";
  323. case AR9285_DEVID_PCIE:
  324. return "Atheros 9285";
  325. case AR5416_DEVID_AR9287_PCI:
  326. case AR5416_DEVID_AR9287_PCIE:
  327. return "Atheros 9287";
  328. }
  329. return NULL;
  330. }
  331. static void ath9k_hw_init_config(struct ath_hw *ah)
  332. {
  333. int i;
  334. ah->config.dma_beacon_response_time = 2;
  335. ah->config.sw_beacon_response_time = 10;
  336. ah->config.additional_swba_backoff = 0;
  337. ah->config.ack_6mb = 0x0;
  338. ah->config.cwm_ignore_extcca = 0;
  339. ah->config.pcie_powersave_enable = 0;
  340. ah->config.pcie_clock_req = 0;
  341. ah->config.pcie_waen = 0;
  342. ah->config.analog_shiftreg = 1;
  343. ah->config.ht_enable = 1;
  344. ah->config.ofdm_trig_low = 200;
  345. ah->config.ofdm_trig_high = 500;
  346. ah->config.cck_trig_high = 200;
  347. ah->config.cck_trig_low = 100;
  348. ah->config.enable_ani = 1;
  349. ah->config.diversity_control = ATH9K_ANT_VARIABLE;
  350. ah->config.antenna_switch_swap = 0;
  351. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  352. ah->config.spurchans[i][0] = AR_NO_SPUR;
  353. ah->config.spurchans[i][1] = AR_NO_SPUR;
  354. }
  355. ah->config.intr_mitigation = true;
  356. /*
  357. * We need this for PCI devices only (Cardbus, PCI, miniPCI)
  358. * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
  359. * This means we use it for all AR5416 devices, and the few
  360. * minor PCI AR9280 devices out there.
  361. *
  362. * Serialization is required because these devices do not handle
  363. * well the case of two concurrent reads/writes due to the latency
  364. * involved. During one read/write another read/write can be issued
  365. * on another CPU while the previous read/write may still be working
  366. * on our hardware, if we hit this case the hardware poops in a loop.
  367. * We prevent this by serializing reads and writes.
  368. *
  369. * This issue is not present on PCI-Express devices or pre-AR5416
  370. * devices (legacy, 802.11abg).
  371. */
  372. if (num_possible_cpus() > 1)
  373. ah->config.serialize_regmode = SER_REG_MODE_AUTO;
  374. }
  375. static void ath9k_hw_init_defaults(struct ath_hw *ah)
  376. {
  377. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  378. regulatory->country_code = CTRY_DEFAULT;
  379. regulatory->power_limit = MAX_RATE_POWER;
  380. regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
  381. ah->hw_version.magic = AR5416_MAGIC;
  382. ah->hw_version.subvendorid = 0;
  383. ah->ah_flags = 0;
  384. if (ah->hw_version.devid == AR5416_AR9100_DEVID)
  385. ah->hw_version.macVersion = AR_SREV_VERSION_9100;
  386. if (!AR_SREV_9100(ah))
  387. ah->ah_flags = AH_USE_EEPROM;
  388. ah->atim_window = 0;
  389. ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE;
  390. ah->beacon_interval = 100;
  391. ah->enable_32kHz_clock = DONT_USE_32KHZ;
  392. ah->slottime = (u32) -1;
  393. ah->acktimeout = (u32) -1;
  394. ah->ctstimeout = (u32) -1;
  395. ah->globaltxtimeout = (u32) -1;
  396. ah->gbeacon_rate = 0;
  397. ah->power_mode = ATH9K_PM_UNDEFINED;
  398. }
  399. static int ath9k_hw_rfattach(struct ath_hw *ah)
  400. {
  401. bool rfStatus = false;
  402. int ecode = 0;
  403. rfStatus = ath9k_hw_init_rf(ah, &ecode);
  404. if (!rfStatus) {
  405. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  406. "RF setup failed, status: %u\n", ecode);
  407. return ecode;
  408. }
  409. return 0;
  410. }
  411. static int ath9k_hw_rf_claim(struct ath_hw *ah)
  412. {
  413. u32 val;
  414. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  415. val = ath9k_hw_get_radiorev(ah);
  416. switch (val & AR_RADIO_SREV_MAJOR) {
  417. case 0:
  418. val = AR_RAD5133_SREV_MAJOR;
  419. break;
  420. case AR_RAD5133_SREV_MAJOR:
  421. case AR_RAD5122_SREV_MAJOR:
  422. case AR_RAD2133_SREV_MAJOR:
  423. case AR_RAD2122_SREV_MAJOR:
  424. break;
  425. default:
  426. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  427. "Radio Chip Rev 0x%02X not supported\n",
  428. val & AR_RADIO_SREV_MAJOR);
  429. return -EOPNOTSUPP;
  430. }
  431. ah->hw_version.analog5GhzRev = val;
  432. return 0;
  433. }
  434. static int ath9k_hw_init_macaddr(struct ath_hw *ah)
  435. {
  436. u32 sum;
  437. int i;
  438. u16 eeval;
  439. sum = 0;
  440. for (i = 0; i < 3; i++) {
  441. eeval = ah->eep_ops->get_eeprom(ah, AR_EEPROM_MAC(i));
  442. sum += eeval;
  443. ah->macaddr[2 * i] = eeval >> 8;
  444. ah->macaddr[2 * i + 1] = eeval & 0xff;
  445. }
  446. if (sum == 0 || sum == 0xffff * 3)
  447. return -EADDRNOTAVAIL;
  448. return 0;
  449. }
  450. static void ath9k_hw_init_rxgain_ini(struct ath_hw *ah)
  451. {
  452. u32 rxgain_type;
  453. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_17) {
  454. rxgain_type = ah->eep_ops->get_eeprom(ah, EEP_RXGAIN_TYPE);
  455. if (rxgain_type == AR5416_EEP_RXGAIN_13DB_BACKOFF)
  456. INIT_INI_ARRAY(&ah->iniModesRxGain,
  457. ar9280Modes_backoff_13db_rxgain_9280_2,
  458. ARRAY_SIZE(ar9280Modes_backoff_13db_rxgain_9280_2), 6);
  459. else if (rxgain_type == AR5416_EEP_RXGAIN_23DB_BACKOFF)
  460. INIT_INI_ARRAY(&ah->iniModesRxGain,
  461. ar9280Modes_backoff_23db_rxgain_9280_2,
  462. ARRAY_SIZE(ar9280Modes_backoff_23db_rxgain_9280_2), 6);
  463. else
  464. INIT_INI_ARRAY(&ah->iniModesRxGain,
  465. ar9280Modes_original_rxgain_9280_2,
  466. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
  467. } else {
  468. INIT_INI_ARRAY(&ah->iniModesRxGain,
  469. ar9280Modes_original_rxgain_9280_2,
  470. ARRAY_SIZE(ar9280Modes_original_rxgain_9280_2), 6);
  471. }
  472. }
  473. static void ath9k_hw_init_txgain_ini(struct ath_hw *ah)
  474. {
  475. u32 txgain_type;
  476. if (ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) >= AR5416_EEP_MINOR_VER_19) {
  477. txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  478. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER)
  479. INIT_INI_ARRAY(&ah->iniModesTxGain,
  480. ar9280Modes_high_power_tx_gain_9280_2,
  481. ARRAY_SIZE(ar9280Modes_high_power_tx_gain_9280_2), 6);
  482. else
  483. INIT_INI_ARRAY(&ah->iniModesTxGain,
  484. ar9280Modes_original_tx_gain_9280_2,
  485. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
  486. } else {
  487. INIT_INI_ARRAY(&ah->iniModesTxGain,
  488. ar9280Modes_original_tx_gain_9280_2,
  489. ARRAY_SIZE(ar9280Modes_original_tx_gain_9280_2), 6);
  490. }
  491. }
  492. static int ath9k_hw_post_init(struct ath_hw *ah)
  493. {
  494. int ecode;
  495. if (!ath9k_hw_chip_test(ah))
  496. return -ENODEV;
  497. ecode = ath9k_hw_rf_claim(ah);
  498. if (ecode != 0)
  499. return ecode;
  500. ecode = ath9k_hw_eeprom_init(ah);
  501. if (ecode != 0)
  502. return ecode;
  503. DPRINTF(ah->ah_sc, ATH_DBG_CONFIG, "Eeprom VER: %d, REV: %d\n",
  504. ah->eep_ops->get_eeprom_ver(ah), ah->eep_ops->get_eeprom_rev(ah));
  505. ecode = ath9k_hw_rfattach(ah);
  506. if (ecode != 0)
  507. return ecode;
  508. if (!AR_SREV_9100(ah)) {
  509. ath9k_hw_ani_setup(ah);
  510. ath9k_hw_ani_init(ah);
  511. }
  512. return 0;
  513. }
  514. static bool ath9k_hw_devid_supported(u16 devid)
  515. {
  516. switch (devid) {
  517. case AR5416_DEVID_PCI:
  518. case AR5416_DEVID_PCIE:
  519. case AR5416_AR9100_DEVID:
  520. case AR9160_DEVID_PCI:
  521. case AR9280_DEVID_PCI:
  522. case AR9280_DEVID_PCIE:
  523. case AR9285_DEVID_PCIE:
  524. case AR5416_DEVID_AR9287_PCI:
  525. case AR5416_DEVID_AR9287_PCIE:
  526. return true;
  527. default:
  528. break;
  529. }
  530. return false;
  531. }
  532. static bool ath9k_hw_macversion_supported(u32 macversion)
  533. {
  534. switch (macversion) {
  535. case AR_SREV_VERSION_5416_PCI:
  536. case AR_SREV_VERSION_5416_PCIE:
  537. case AR_SREV_VERSION_9160:
  538. case AR_SREV_VERSION_9100:
  539. case AR_SREV_VERSION_9280:
  540. case AR_SREV_VERSION_9285:
  541. case AR_SREV_VERSION_9287:
  542. return true;
  543. /* Not yet */
  544. case AR_SREV_VERSION_9271:
  545. default:
  546. break;
  547. }
  548. return false;
  549. }
  550. static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
  551. {
  552. if (AR_SREV_9160_10_OR_LATER(ah)) {
  553. if (AR_SREV_9280_10_OR_LATER(ah)) {
  554. ah->iq_caldata.calData = &iq_cal_single_sample;
  555. ah->adcgain_caldata.calData =
  556. &adc_gain_cal_single_sample;
  557. ah->adcdc_caldata.calData =
  558. &adc_dc_cal_single_sample;
  559. ah->adcdc_calinitdata.calData =
  560. &adc_init_dc_cal;
  561. } else {
  562. ah->iq_caldata.calData = &iq_cal_multi_sample;
  563. ah->adcgain_caldata.calData =
  564. &adc_gain_cal_multi_sample;
  565. ah->adcdc_caldata.calData =
  566. &adc_dc_cal_multi_sample;
  567. ah->adcdc_calinitdata.calData =
  568. &adc_init_dc_cal;
  569. }
  570. ah->supp_cals = ADC_GAIN_CAL | ADC_DC_CAL | IQ_MISMATCH_CAL;
  571. }
  572. }
  573. static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
  574. {
  575. if (AR_SREV_9271(ah)) {
  576. INIT_INI_ARRAY(&ah->iniModes, ar9271Modes_9271_1_0,
  577. ARRAY_SIZE(ar9271Modes_9271_1_0), 6);
  578. INIT_INI_ARRAY(&ah->iniCommon, ar9271Common_9271_1_0,
  579. ARRAY_SIZE(ar9271Common_9271_1_0), 2);
  580. return;
  581. }
  582. if (AR_SREV_9287_11_OR_LATER(ah)) {
  583. INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_1,
  584. ARRAY_SIZE(ar9287Modes_9287_1_1), 6);
  585. INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_1,
  586. ARRAY_SIZE(ar9287Common_9287_1_1), 2);
  587. if (ah->config.pcie_clock_req)
  588. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  589. ar9287PciePhy_clkreq_off_L1_9287_1_1,
  590. ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_1), 2);
  591. else
  592. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  593. ar9287PciePhy_clkreq_always_on_L1_9287_1_1,
  594. ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_1),
  595. 2);
  596. } else if (AR_SREV_9287_10_OR_LATER(ah)) {
  597. INIT_INI_ARRAY(&ah->iniModes, ar9287Modes_9287_1_0,
  598. ARRAY_SIZE(ar9287Modes_9287_1_0), 6);
  599. INIT_INI_ARRAY(&ah->iniCommon, ar9287Common_9287_1_0,
  600. ARRAY_SIZE(ar9287Common_9287_1_0), 2);
  601. if (ah->config.pcie_clock_req)
  602. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  603. ar9287PciePhy_clkreq_off_L1_9287_1_0,
  604. ARRAY_SIZE(ar9287PciePhy_clkreq_off_L1_9287_1_0), 2);
  605. else
  606. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  607. ar9287PciePhy_clkreq_always_on_L1_9287_1_0,
  608. ARRAY_SIZE(ar9287PciePhy_clkreq_always_on_L1_9287_1_0),
  609. 2);
  610. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  611. INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285_1_2,
  612. ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
  613. INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285_1_2,
  614. ARRAY_SIZE(ar9285Common_9285_1_2), 2);
  615. if (ah->config.pcie_clock_req) {
  616. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  617. ar9285PciePhy_clkreq_off_L1_9285_1_2,
  618. ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
  619. } else {
  620. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  621. ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
  622. ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
  623. 2);
  624. }
  625. } else if (AR_SREV_9285_10_OR_LATER(ah)) {
  626. INIT_INI_ARRAY(&ah->iniModes, ar9285Modes_9285,
  627. ARRAY_SIZE(ar9285Modes_9285), 6);
  628. INIT_INI_ARRAY(&ah->iniCommon, ar9285Common_9285,
  629. ARRAY_SIZE(ar9285Common_9285), 2);
  630. if (ah->config.pcie_clock_req) {
  631. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  632. ar9285PciePhy_clkreq_off_L1_9285,
  633. ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
  634. } else {
  635. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  636. ar9285PciePhy_clkreq_always_on_L1_9285,
  637. ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
  638. }
  639. } else if (AR_SREV_9280_20_OR_LATER(ah)) {
  640. INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280_2,
  641. ARRAY_SIZE(ar9280Modes_9280_2), 6);
  642. INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280_2,
  643. ARRAY_SIZE(ar9280Common_9280_2), 2);
  644. if (ah->config.pcie_clock_req) {
  645. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  646. ar9280PciePhy_clkreq_off_L1_9280,
  647. ARRAY_SIZE(ar9280PciePhy_clkreq_off_L1_9280),2);
  648. } else {
  649. INIT_INI_ARRAY(&ah->iniPcieSerdes,
  650. ar9280PciePhy_clkreq_always_on_L1_9280,
  651. ARRAY_SIZE(ar9280PciePhy_clkreq_always_on_L1_9280), 2);
  652. }
  653. INIT_INI_ARRAY(&ah->iniModesAdditional,
  654. ar9280Modes_fast_clock_9280_2,
  655. ARRAY_SIZE(ar9280Modes_fast_clock_9280_2), 3);
  656. } else if (AR_SREV_9280_10_OR_LATER(ah)) {
  657. INIT_INI_ARRAY(&ah->iniModes, ar9280Modes_9280,
  658. ARRAY_SIZE(ar9280Modes_9280), 6);
  659. INIT_INI_ARRAY(&ah->iniCommon, ar9280Common_9280,
  660. ARRAY_SIZE(ar9280Common_9280), 2);
  661. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  662. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9160,
  663. ARRAY_SIZE(ar5416Modes_9160), 6);
  664. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9160,
  665. ARRAY_SIZE(ar5416Common_9160), 2);
  666. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9160,
  667. ARRAY_SIZE(ar5416Bank0_9160), 2);
  668. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9160,
  669. ARRAY_SIZE(ar5416BB_RfGain_9160), 3);
  670. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9160,
  671. ARRAY_SIZE(ar5416Bank1_9160), 2);
  672. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9160,
  673. ARRAY_SIZE(ar5416Bank2_9160), 2);
  674. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9160,
  675. ARRAY_SIZE(ar5416Bank3_9160), 3);
  676. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9160,
  677. ARRAY_SIZE(ar5416Bank6_9160), 3);
  678. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9160,
  679. ARRAY_SIZE(ar5416Bank6TPC_9160), 3);
  680. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9160,
  681. ARRAY_SIZE(ar5416Bank7_9160), 2);
  682. if (AR_SREV_9160_11(ah)) {
  683. INIT_INI_ARRAY(&ah->iniAddac,
  684. ar5416Addac_91601_1,
  685. ARRAY_SIZE(ar5416Addac_91601_1), 2);
  686. } else {
  687. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9160,
  688. ARRAY_SIZE(ar5416Addac_9160), 2);
  689. }
  690. } else if (AR_SREV_9100_OR_LATER(ah)) {
  691. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes_9100,
  692. ARRAY_SIZE(ar5416Modes_9100), 6);
  693. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common_9100,
  694. ARRAY_SIZE(ar5416Common_9100), 2);
  695. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0_9100,
  696. ARRAY_SIZE(ar5416Bank0_9100), 2);
  697. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain_9100,
  698. ARRAY_SIZE(ar5416BB_RfGain_9100), 3);
  699. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1_9100,
  700. ARRAY_SIZE(ar5416Bank1_9100), 2);
  701. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2_9100,
  702. ARRAY_SIZE(ar5416Bank2_9100), 2);
  703. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3_9100,
  704. ARRAY_SIZE(ar5416Bank3_9100), 3);
  705. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6_9100,
  706. ARRAY_SIZE(ar5416Bank6_9100), 3);
  707. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC_9100,
  708. ARRAY_SIZE(ar5416Bank6TPC_9100), 3);
  709. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7_9100,
  710. ARRAY_SIZE(ar5416Bank7_9100), 2);
  711. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac_9100,
  712. ARRAY_SIZE(ar5416Addac_9100), 2);
  713. } else {
  714. INIT_INI_ARRAY(&ah->iniModes, ar5416Modes,
  715. ARRAY_SIZE(ar5416Modes), 6);
  716. INIT_INI_ARRAY(&ah->iniCommon, ar5416Common,
  717. ARRAY_SIZE(ar5416Common), 2);
  718. INIT_INI_ARRAY(&ah->iniBank0, ar5416Bank0,
  719. ARRAY_SIZE(ar5416Bank0), 2);
  720. INIT_INI_ARRAY(&ah->iniBB_RfGain, ar5416BB_RfGain,
  721. ARRAY_SIZE(ar5416BB_RfGain), 3);
  722. INIT_INI_ARRAY(&ah->iniBank1, ar5416Bank1,
  723. ARRAY_SIZE(ar5416Bank1), 2);
  724. INIT_INI_ARRAY(&ah->iniBank2, ar5416Bank2,
  725. ARRAY_SIZE(ar5416Bank2), 2);
  726. INIT_INI_ARRAY(&ah->iniBank3, ar5416Bank3,
  727. ARRAY_SIZE(ar5416Bank3), 3);
  728. INIT_INI_ARRAY(&ah->iniBank6, ar5416Bank6,
  729. ARRAY_SIZE(ar5416Bank6), 3);
  730. INIT_INI_ARRAY(&ah->iniBank6TPC, ar5416Bank6TPC,
  731. ARRAY_SIZE(ar5416Bank6TPC), 3);
  732. INIT_INI_ARRAY(&ah->iniBank7, ar5416Bank7,
  733. ARRAY_SIZE(ar5416Bank7), 2);
  734. INIT_INI_ARRAY(&ah->iniAddac, ar5416Addac,
  735. ARRAY_SIZE(ar5416Addac), 2);
  736. }
  737. }
  738. static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
  739. {
  740. if (AR_SREV_9287_11(ah))
  741. INIT_INI_ARRAY(&ah->iniModesRxGain,
  742. ar9287Modes_rx_gain_9287_1_1,
  743. ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_1), 6);
  744. else if (AR_SREV_9287_10(ah))
  745. INIT_INI_ARRAY(&ah->iniModesRxGain,
  746. ar9287Modes_rx_gain_9287_1_0,
  747. ARRAY_SIZE(ar9287Modes_rx_gain_9287_1_0), 6);
  748. else if (AR_SREV_9280_20(ah))
  749. ath9k_hw_init_rxgain_ini(ah);
  750. if (AR_SREV_9287_11(ah)) {
  751. INIT_INI_ARRAY(&ah->iniModesTxGain,
  752. ar9287Modes_tx_gain_9287_1_1,
  753. ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_1), 6);
  754. } else if (AR_SREV_9287_10(ah)) {
  755. INIT_INI_ARRAY(&ah->iniModesTxGain,
  756. ar9287Modes_tx_gain_9287_1_0,
  757. ARRAY_SIZE(ar9287Modes_tx_gain_9287_1_0), 6);
  758. } else if (AR_SREV_9280_20(ah)) {
  759. ath9k_hw_init_txgain_ini(ah);
  760. } else if (AR_SREV_9285_12_OR_LATER(ah)) {
  761. u32 txgain_type = ah->eep_ops->get_eeprom(ah, EEP_TXGAIN_TYPE);
  762. /* txgain table */
  763. if (txgain_type == AR5416_EEP_TXGAIN_HIGH_POWER) {
  764. INIT_INI_ARRAY(&ah->iniModesTxGain,
  765. ar9285Modes_high_power_tx_gain_9285_1_2,
  766. ARRAY_SIZE(ar9285Modes_high_power_tx_gain_9285_1_2), 6);
  767. } else {
  768. INIT_INI_ARRAY(&ah->iniModesTxGain,
  769. ar9285Modes_original_tx_gain_9285_1_2,
  770. ARRAY_SIZE(ar9285Modes_original_tx_gain_9285_1_2), 6);
  771. }
  772. }
  773. }
  774. static void ath9k_hw_init_11a_eeprom_fix(struct ath_hw *ah)
  775. {
  776. u32 i, j;
  777. if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
  778. test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes)) {
  779. /* EEPROM Fixup */
  780. for (i = 0; i < ah->iniModes.ia_rows; i++) {
  781. u32 reg = INI_RA(&ah->iniModes, i, 0);
  782. for (j = 1; j < ah->iniModes.ia_columns; j++) {
  783. u32 val = INI_RA(&ah->iniModes, i, j);
  784. INI_RA(&ah->iniModes, i, j) =
  785. ath9k_hw_ini_fixup(ah,
  786. &ah->eeprom.def,
  787. reg, val);
  788. }
  789. }
  790. }
  791. }
  792. int ath9k_hw_init(struct ath_hw *ah)
  793. {
  794. int r = 0;
  795. if (!ath9k_hw_devid_supported(ah->hw_version.devid))
  796. return -EOPNOTSUPP;
  797. ath9k_hw_init_defaults(ah);
  798. ath9k_hw_init_config(ah);
  799. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  800. DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Couldn't reset chip\n");
  801. return -EIO;
  802. }
  803. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
  804. DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Couldn't wakeup chip\n");
  805. return -EIO;
  806. }
  807. if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
  808. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
  809. (AR_SREV_9280(ah) && !ah->is_pciexpress)) {
  810. ah->config.serialize_regmode =
  811. SER_REG_MODE_ON;
  812. } else {
  813. ah->config.serialize_regmode =
  814. SER_REG_MODE_OFF;
  815. }
  816. }
  817. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "serialize_regmode is %d\n",
  818. ah->config.serialize_regmode);
  819. if (!ath9k_hw_macversion_supported(ah->hw_version.macVersion)) {
  820. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  821. "Mac Chip Rev 0x%02x.%x is not supported by "
  822. "this driver\n", ah->hw_version.macVersion,
  823. ah->hw_version.macRev);
  824. return -EOPNOTSUPP;
  825. }
  826. if (AR_SREV_9100(ah)) {
  827. ah->iq_caldata.calData = &iq_cal_multi_sample;
  828. ah->supp_cals = IQ_MISMATCH_CAL;
  829. ah->is_pciexpress = false;
  830. }
  831. if (AR_SREV_9271(ah))
  832. ah->is_pciexpress = false;
  833. ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
  834. ath9k_hw_init_cal_settings(ah);
  835. ah->ani_function = ATH9K_ANI_ALL;
  836. if (AR_SREV_9280_10_OR_LATER(ah))
  837. ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
  838. ath9k_hw_init_mode_regs(ah);
  839. if (ah->is_pciexpress)
  840. ath9k_hw_configpcipowersave(ah, 0);
  841. else
  842. ath9k_hw_disablepcie(ah);
  843. r = ath9k_hw_post_init(ah);
  844. if (r)
  845. return r;
  846. ath9k_hw_init_mode_gain_regs(ah);
  847. ath9k_hw_fill_cap_info(ah);
  848. ath9k_hw_init_11a_eeprom_fix(ah);
  849. r = ath9k_hw_init_macaddr(ah);
  850. if (r) {
  851. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  852. "Failed to initialize MAC address\n");
  853. return r;
  854. }
  855. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  856. ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
  857. else
  858. ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
  859. ath9k_init_nfcal_hist_buffer(ah);
  860. return 0;
  861. }
  862. static void ath9k_hw_init_bb(struct ath_hw *ah,
  863. struct ath9k_channel *chan)
  864. {
  865. u32 synthDelay;
  866. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  867. if (IS_CHAN_B(chan))
  868. synthDelay = (4 * synthDelay) / 22;
  869. else
  870. synthDelay /= 10;
  871. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  872. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  873. }
  874. static void ath9k_hw_init_qos(struct ath_hw *ah)
  875. {
  876. REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
  877. REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
  878. REG_WRITE(ah, AR_QOS_NO_ACK,
  879. SM(2, AR_QOS_NO_ACK_TWO_BIT) |
  880. SM(5, AR_QOS_NO_ACK_BIT_OFF) |
  881. SM(0, AR_QOS_NO_ACK_BYTE_OFF));
  882. REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
  883. REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
  884. REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
  885. REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
  886. REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
  887. }
  888. static void ath9k_hw_init_pll(struct ath_hw *ah,
  889. struct ath9k_channel *chan)
  890. {
  891. u32 pll;
  892. if (AR_SREV_9100(ah)) {
  893. if (chan && IS_CHAN_5GHZ(chan))
  894. pll = 0x1450;
  895. else
  896. pll = 0x1458;
  897. } else {
  898. if (AR_SREV_9280_10_OR_LATER(ah)) {
  899. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  900. if (chan && IS_CHAN_HALF_RATE(chan))
  901. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  902. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  903. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  904. if (chan && IS_CHAN_5GHZ(chan)) {
  905. pll |= SM(0x28, AR_RTC_9160_PLL_DIV);
  906. if (AR_SREV_9280_20(ah)) {
  907. if (((chan->channel % 20) == 0)
  908. || ((chan->channel % 10) == 0))
  909. pll = 0x2850;
  910. else
  911. pll = 0x142c;
  912. }
  913. } else {
  914. pll |= SM(0x2c, AR_RTC_9160_PLL_DIV);
  915. }
  916. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  917. pll = SM(0x5, AR_RTC_9160_PLL_REFDIV);
  918. if (chan && IS_CHAN_HALF_RATE(chan))
  919. pll |= SM(0x1, AR_RTC_9160_PLL_CLKSEL);
  920. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  921. pll |= SM(0x2, AR_RTC_9160_PLL_CLKSEL);
  922. if (chan && IS_CHAN_5GHZ(chan))
  923. pll |= SM(0x50, AR_RTC_9160_PLL_DIV);
  924. else
  925. pll |= SM(0x58, AR_RTC_9160_PLL_DIV);
  926. } else {
  927. pll = AR_RTC_PLL_REFDIV_5 | AR_RTC_PLL_DIV2;
  928. if (chan && IS_CHAN_HALF_RATE(chan))
  929. pll |= SM(0x1, AR_RTC_PLL_CLKSEL);
  930. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  931. pll |= SM(0x2, AR_RTC_PLL_CLKSEL);
  932. if (chan && IS_CHAN_5GHZ(chan))
  933. pll |= SM(0xa, AR_RTC_PLL_DIV);
  934. else
  935. pll |= SM(0xb, AR_RTC_PLL_DIV);
  936. }
  937. }
  938. REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
  939. udelay(RTC_PLL_SETTLE_DELAY);
  940. REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
  941. }
  942. static void ath9k_hw_init_chain_masks(struct ath_hw *ah)
  943. {
  944. int rx_chainmask, tx_chainmask;
  945. rx_chainmask = ah->rxchainmask;
  946. tx_chainmask = ah->txchainmask;
  947. switch (rx_chainmask) {
  948. case 0x5:
  949. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  950. AR_PHY_SWAP_ALT_CHAIN);
  951. case 0x3:
  952. if (((ah)->hw_version.macVersion <= AR_SREV_VERSION_9160)) {
  953. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, 0x7);
  954. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, 0x7);
  955. break;
  956. }
  957. case 0x1:
  958. case 0x2:
  959. case 0x7:
  960. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  961. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  962. break;
  963. default:
  964. break;
  965. }
  966. REG_WRITE(ah, AR_SELFGEN_MASK, tx_chainmask);
  967. if (tx_chainmask == 0x5) {
  968. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  969. AR_PHY_SWAP_ALT_CHAIN);
  970. }
  971. if (AR_SREV_9100(ah))
  972. REG_WRITE(ah, AR_PHY_ANALOG_SWAP,
  973. REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
  974. }
  975. static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
  976. enum nl80211_iftype opmode)
  977. {
  978. ah->mask_reg = AR_IMR_TXERR |
  979. AR_IMR_TXURN |
  980. AR_IMR_RXERR |
  981. AR_IMR_RXORN |
  982. AR_IMR_BCNMISC;
  983. if (ah->config.intr_mitigation)
  984. ah->mask_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  985. else
  986. ah->mask_reg |= AR_IMR_RXOK;
  987. ah->mask_reg |= AR_IMR_TXOK;
  988. if (opmode == NL80211_IFTYPE_AP)
  989. ah->mask_reg |= AR_IMR_MIB;
  990. REG_WRITE(ah, AR_IMR, ah->mask_reg);
  991. REG_WRITE(ah, AR_IMR_S2, REG_READ(ah, AR_IMR_S2) | AR_IMR_S2_GTT);
  992. if (!AR_SREV_9100(ah)) {
  993. REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
  994. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, AR_INTR_SYNC_DEFAULT);
  995. REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
  996. }
  997. }
  998. static bool ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
  999. {
  1000. if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
  1001. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad ack timeout %u\n", us);
  1002. ah->acktimeout = (u32) -1;
  1003. return false;
  1004. } else {
  1005. REG_RMW_FIELD(ah, AR_TIME_OUT,
  1006. AR_TIME_OUT_ACK, ath9k_hw_mac_to_clks(ah, us));
  1007. ah->acktimeout = us;
  1008. return true;
  1009. }
  1010. }
  1011. static bool ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
  1012. {
  1013. if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
  1014. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad cts timeout %u\n", us);
  1015. ah->ctstimeout = (u32) -1;
  1016. return false;
  1017. } else {
  1018. REG_RMW_FIELD(ah, AR_TIME_OUT,
  1019. AR_TIME_OUT_CTS, ath9k_hw_mac_to_clks(ah, us));
  1020. ah->ctstimeout = us;
  1021. return true;
  1022. }
  1023. }
  1024. static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
  1025. {
  1026. if (tu > 0xFFFF) {
  1027. DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
  1028. "bad global tx timeout %u\n", tu);
  1029. ah->globaltxtimeout = (u32) -1;
  1030. return false;
  1031. } else {
  1032. REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
  1033. ah->globaltxtimeout = tu;
  1034. return true;
  1035. }
  1036. }
  1037. static void ath9k_hw_init_user_settings(struct ath_hw *ah)
  1038. {
  1039. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "ah->misc_mode 0x%x\n",
  1040. ah->misc_mode);
  1041. if (ah->misc_mode != 0)
  1042. REG_WRITE(ah, AR_PCU_MISC,
  1043. REG_READ(ah, AR_PCU_MISC) | ah->misc_mode);
  1044. if (ah->slottime != (u32) -1)
  1045. ath9k_hw_setslottime(ah, ah->slottime);
  1046. if (ah->acktimeout != (u32) -1)
  1047. ath9k_hw_set_ack_timeout(ah, ah->acktimeout);
  1048. if (ah->ctstimeout != (u32) -1)
  1049. ath9k_hw_set_cts_timeout(ah, ah->ctstimeout);
  1050. if (ah->globaltxtimeout != (u32) -1)
  1051. ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
  1052. }
  1053. const char *ath9k_hw_probe(u16 vendorid, u16 devid)
  1054. {
  1055. return vendorid == ATHEROS_VENDOR_ID ?
  1056. ath9k_hw_devname(devid) : NULL;
  1057. }
  1058. void ath9k_hw_detach(struct ath_hw *ah)
  1059. {
  1060. if (!AR_SREV_9100(ah))
  1061. ath9k_hw_ani_disable(ah);
  1062. ath9k_hw_rf_free(ah);
  1063. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  1064. kfree(ah);
  1065. ah = NULL;
  1066. }
  1067. /*******/
  1068. /* INI */
  1069. /*******/
  1070. static void ath9k_hw_override_ini(struct ath_hw *ah,
  1071. struct ath9k_channel *chan)
  1072. {
  1073. u32 val;
  1074. if (AR_SREV_9271(ah)) {
  1075. /*
  1076. * Enable spectral scan to solution for issues with stuck
  1077. * beacons on AR9271 1.0. The beacon stuck issue is not seeon on
  1078. * AR9271 1.1
  1079. */
  1080. if (AR_SREV_9271_10(ah)) {
  1081. val = REG_READ(ah, AR_PHY_SPECTRAL_SCAN) | AR_PHY_SPECTRAL_SCAN_ENABLE;
  1082. REG_WRITE(ah, AR_PHY_SPECTRAL_SCAN, val);
  1083. }
  1084. else if (AR_SREV_9271_11(ah))
  1085. /*
  1086. * change AR_PHY_RF_CTL3 setting to fix MAC issue
  1087. * present on AR9271 1.1
  1088. */
  1089. REG_WRITE(ah, AR_PHY_RF_CTL3, 0x3a020001);
  1090. return;
  1091. }
  1092. /*
  1093. * Set the RX_ABORT and RX_DIS and clear if off only after
  1094. * RXE is set for MAC. This prevents frames with corrupted
  1095. * descriptor status.
  1096. */
  1097. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  1098. if (!AR_SREV_5416_20_OR_LATER(ah) ||
  1099. AR_SREV_9280_10_OR_LATER(ah))
  1100. return;
  1101. /*
  1102. * Disable BB clock gating
  1103. * Necessary to avoid issues on AR5416 2.0
  1104. */
  1105. REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
  1106. }
  1107. static u32 ath9k_hw_def_ini_fixup(struct ath_hw *ah,
  1108. struct ar5416_eeprom_def *pEepData,
  1109. u32 reg, u32 value)
  1110. {
  1111. struct base_eep_header *pBase = &(pEepData->baseEepHeader);
  1112. switch (ah->hw_version.devid) {
  1113. case AR9280_DEVID_PCI:
  1114. if (reg == 0x7894) {
  1115. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1116. "ini VAL: %x EEPROM: %x\n", value,
  1117. (pBase->version & 0xff));
  1118. if ((pBase->version & 0xff) > 0x0a) {
  1119. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1120. "PWDCLKIND: %d\n",
  1121. pBase->pwdclkind);
  1122. value &= ~AR_AN_TOP2_PWDCLKIND;
  1123. value |= AR_AN_TOP2_PWDCLKIND &
  1124. (pBase->pwdclkind << AR_AN_TOP2_PWDCLKIND_S);
  1125. } else {
  1126. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1127. "PWDCLKIND Earlier Rev\n");
  1128. }
  1129. DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
  1130. "final ini VAL: %x\n", value);
  1131. }
  1132. break;
  1133. }
  1134. return value;
  1135. }
  1136. static u32 ath9k_hw_ini_fixup(struct ath_hw *ah,
  1137. struct ar5416_eeprom_def *pEepData,
  1138. u32 reg, u32 value)
  1139. {
  1140. if (ah->eep_map == EEP_MAP_4KBITS)
  1141. return value;
  1142. else
  1143. return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
  1144. }
  1145. static void ath9k_olc_init(struct ath_hw *ah)
  1146. {
  1147. u32 i;
  1148. if (OLC_FOR_AR9287_10_LATER) {
  1149. REG_SET_BIT(ah, AR_PHY_TX_PWRCTRL9,
  1150. AR_PHY_TX_PWRCTRL9_RES_DC_REMOVAL);
  1151. ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TXPC0,
  1152. AR9287_AN_TXPC0_TXPCMODE,
  1153. AR9287_AN_TXPC0_TXPCMODE_S,
  1154. AR9287_AN_TXPC0_TXPCMODE_TEMPSENSE);
  1155. udelay(100);
  1156. } else {
  1157. for (i = 0; i < AR9280_TX_GAIN_TABLE_SIZE; i++)
  1158. ah->originalGain[i] =
  1159. MS(REG_READ(ah, AR_PHY_TX_GAIN_TBL1 + i * 4),
  1160. AR_PHY_TX_GAIN);
  1161. ah->PDADCdelta = 0;
  1162. }
  1163. }
  1164. static u32 ath9k_regd_get_ctl(struct ath_regulatory *reg,
  1165. struct ath9k_channel *chan)
  1166. {
  1167. u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
  1168. if (IS_CHAN_B(chan))
  1169. ctl |= CTL_11B;
  1170. else if (IS_CHAN_G(chan))
  1171. ctl |= CTL_11G;
  1172. else
  1173. ctl |= CTL_11A;
  1174. return ctl;
  1175. }
  1176. static int ath9k_hw_process_ini(struct ath_hw *ah,
  1177. struct ath9k_channel *chan,
  1178. enum ath9k_ht_macmode macmode)
  1179. {
  1180. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1181. int i, regWrites = 0;
  1182. struct ieee80211_channel *channel = chan->chan;
  1183. u32 modesIndex, freqIndex;
  1184. switch (chan->chanmode) {
  1185. case CHANNEL_A:
  1186. case CHANNEL_A_HT20:
  1187. modesIndex = 1;
  1188. freqIndex = 1;
  1189. break;
  1190. case CHANNEL_A_HT40PLUS:
  1191. case CHANNEL_A_HT40MINUS:
  1192. modesIndex = 2;
  1193. freqIndex = 1;
  1194. break;
  1195. case CHANNEL_G:
  1196. case CHANNEL_G_HT20:
  1197. case CHANNEL_B:
  1198. modesIndex = 4;
  1199. freqIndex = 2;
  1200. break;
  1201. case CHANNEL_G_HT40PLUS:
  1202. case CHANNEL_G_HT40MINUS:
  1203. modesIndex = 3;
  1204. freqIndex = 2;
  1205. break;
  1206. default:
  1207. return -EINVAL;
  1208. }
  1209. REG_WRITE(ah, AR_PHY(0), 0x00000007);
  1210. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_EXTERNAL_RADIO);
  1211. ah->eep_ops->set_addac(ah, chan);
  1212. if (AR_SREV_5416_22_OR_LATER(ah)) {
  1213. REG_WRITE_ARRAY(&ah->iniAddac, 1, regWrites);
  1214. } else {
  1215. struct ar5416IniArray temp;
  1216. u32 addacSize =
  1217. sizeof(u32) * ah->iniAddac.ia_rows *
  1218. ah->iniAddac.ia_columns;
  1219. memcpy(ah->addac5416_21,
  1220. ah->iniAddac.ia_array, addacSize);
  1221. (ah->addac5416_21)[31 * ah->iniAddac.ia_columns + 1] = 0;
  1222. temp.ia_array = ah->addac5416_21;
  1223. temp.ia_columns = ah->iniAddac.ia_columns;
  1224. temp.ia_rows = ah->iniAddac.ia_rows;
  1225. REG_WRITE_ARRAY(&temp, 1, regWrites);
  1226. }
  1227. REG_WRITE(ah, AR_PHY_ADC_SERIAL_CTL, AR_PHY_SEL_INTERNAL_ADDAC);
  1228. for (i = 0; i < ah->iniModes.ia_rows; i++) {
  1229. u32 reg = INI_RA(&ah->iniModes, i, 0);
  1230. u32 val = INI_RA(&ah->iniModes, i, modesIndex);
  1231. REG_WRITE(ah, reg, val);
  1232. if (reg >= 0x7800 && reg < 0x78a0
  1233. && ah->config.analog_shiftreg) {
  1234. udelay(100);
  1235. }
  1236. DO_DELAY(regWrites);
  1237. }
  1238. if (AR_SREV_9280(ah) || AR_SREV_9287_10_OR_LATER(ah))
  1239. REG_WRITE_ARRAY(&ah->iniModesRxGain, modesIndex, regWrites);
  1240. if (AR_SREV_9280(ah) || AR_SREV_9285_12_OR_LATER(ah) ||
  1241. AR_SREV_9287_10_OR_LATER(ah))
  1242. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  1243. for (i = 0; i < ah->iniCommon.ia_rows; i++) {
  1244. u32 reg = INI_RA(&ah->iniCommon, i, 0);
  1245. u32 val = INI_RA(&ah->iniCommon, i, 1);
  1246. REG_WRITE(ah, reg, val);
  1247. if (reg >= 0x7800 && reg < 0x78a0
  1248. && ah->config.analog_shiftreg) {
  1249. udelay(100);
  1250. }
  1251. DO_DELAY(regWrites);
  1252. }
  1253. ath9k_hw_write_regs(ah, modesIndex, freqIndex, regWrites);
  1254. if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan)) {
  1255. REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex,
  1256. regWrites);
  1257. }
  1258. ath9k_hw_override_ini(ah, chan);
  1259. ath9k_hw_set_regs(ah, chan, macmode);
  1260. ath9k_hw_init_chain_masks(ah);
  1261. if (OLC_FOR_AR9280_20_LATER)
  1262. ath9k_olc_init(ah);
  1263. ah->eep_ops->set_txpower(ah, chan,
  1264. ath9k_regd_get_ctl(regulatory, chan),
  1265. channel->max_antenna_gain * 2,
  1266. channel->max_power * 2,
  1267. min((u32) MAX_RATE_POWER,
  1268. (u32) regulatory->power_limit));
  1269. if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
  1270. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1271. "ar5416SetRfRegs failed\n");
  1272. return -EIO;
  1273. }
  1274. return 0;
  1275. }
  1276. /****************************************/
  1277. /* Reset and Channel Switching Routines */
  1278. /****************************************/
  1279. static void ath9k_hw_set_rfmode(struct ath_hw *ah, struct ath9k_channel *chan)
  1280. {
  1281. u32 rfMode = 0;
  1282. if (chan == NULL)
  1283. return;
  1284. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  1285. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  1286. if (!AR_SREV_9280_10_OR_LATER(ah))
  1287. rfMode |= (IS_CHAN_5GHZ(chan)) ?
  1288. AR_PHY_MODE_RF5GHZ : AR_PHY_MODE_RF2GHZ;
  1289. if (AR_SREV_9280_20(ah) && IS_CHAN_A_5MHZ_SPACED(chan))
  1290. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  1291. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  1292. }
  1293. static void ath9k_hw_mark_phy_inactive(struct ath_hw *ah)
  1294. {
  1295. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  1296. }
  1297. static inline void ath9k_hw_set_dma(struct ath_hw *ah)
  1298. {
  1299. u32 regval;
  1300. /*
  1301. * set AHB_MODE not to do cacheline prefetches
  1302. */
  1303. regval = REG_READ(ah, AR_AHB_MODE);
  1304. REG_WRITE(ah, AR_AHB_MODE, regval | AR_AHB_PREFETCH_RD_EN);
  1305. /*
  1306. * let mac dma reads be in 128 byte chunks
  1307. */
  1308. regval = REG_READ(ah, AR_TXCFG) & ~AR_TXCFG_DMASZ_MASK;
  1309. REG_WRITE(ah, AR_TXCFG, regval | AR_TXCFG_DMASZ_128B);
  1310. /*
  1311. * Restore TX Trigger Level to its pre-reset value.
  1312. * The initial value depends on whether aggregation is enabled, and is
  1313. * adjusted whenever underruns are detected.
  1314. */
  1315. REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
  1316. /*
  1317. * let mac dma writes be in 128 byte chunks
  1318. */
  1319. regval = REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_DMASZ_MASK;
  1320. REG_WRITE(ah, AR_RXCFG, regval | AR_RXCFG_DMASZ_128B);
  1321. /*
  1322. * Setup receive FIFO threshold to hold off TX activities
  1323. */
  1324. REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
  1325. /*
  1326. * reduce the number of usable entries in PCU TXBUF to avoid
  1327. * wrap around issues.
  1328. */
  1329. if (AR_SREV_9285(ah)) {
  1330. /* For AR9285 the number of Fifos are reduced to half.
  1331. * So set the usable tx buf size also to half to
  1332. * avoid data/delimiter underruns
  1333. */
  1334. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1335. AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
  1336. } else if (!AR_SREV_9271(ah)) {
  1337. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  1338. AR_PCU_TXBUF_CTRL_USABLE_SIZE);
  1339. }
  1340. }
  1341. static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
  1342. {
  1343. u32 val;
  1344. val = REG_READ(ah, AR_STA_ID1);
  1345. val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
  1346. switch (opmode) {
  1347. case NL80211_IFTYPE_AP:
  1348. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
  1349. | AR_STA_ID1_KSRCH_MODE);
  1350. REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1351. break;
  1352. case NL80211_IFTYPE_ADHOC:
  1353. case NL80211_IFTYPE_MESH_POINT:
  1354. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
  1355. | AR_STA_ID1_KSRCH_MODE);
  1356. REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1357. break;
  1358. case NL80211_IFTYPE_STATION:
  1359. case NL80211_IFTYPE_MONITOR:
  1360. REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
  1361. break;
  1362. }
  1363. }
  1364. static inline void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah,
  1365. u32 coef_scaled,
  1366. u32 *coef_mantissa,
  1367. u32 *coef_exponent)
  1368. {
  1369. u32 coef_exp, coef_man;
  1370. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  1371. if ((coef_scaled >> coef_exp) & 0x1)
  1372. break;
  1373. coef_exp = 14 - (coef_exp - COEF_SCALE_S);
  1374. coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
  1375. *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
  1376. *coef_exponent = coef_exp - 16;
  1377. }
  1378. static void ath9k_hw_set_delta_slope(struct ath_hw *ah,
  1379. struct ath9k_channel *chan)
  1380. {
  1381. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  1382. u32 clockMhzScaled = 0x64000000;
  1383. struct chan_centers centers;
  1384. if (IS_CHAN_HALF_RATE(chan))
  1385. clockMhzScaled = clockMhzScaled >> 1;
  1386. else if (IS_CHAN_QUARTER_RATE(chan))
  1387. clockMhzScaled = clockMhzScaled >> 2;
  1388. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1389. coef_scaled = clockMhzScaled / centers.synth_center;
  1390. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  1391. &ds_coef_exp);
  1392. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  1393. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  1394. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  1395. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  1396. coef_scaled = (9 * coef_scaled) / 10;
  1397. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  1398. &ds_coef_exp);
  1399. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  1400. AR_PHY_HALFGI_DSC_MAN, ds_coef_man);
  1401. REG_RMW_FIELD(ah, AR_PHY_HALFGI,
  1402. AR_PHY_HALFGI_DSC_EXP, ds_coef_exp);
  1403. }
  1404. static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
  1405. {
  1406. u32 rst_flags;
  1407. u32 tmpReg;
  1408. if (AR_SREV_9100(ah)) {
  1409. u32 val = REG_READ(ah, AR_RTC_DERIVED_CLK);
  1410. val &= ~AR_RTC_DERIVED_CLK_PERIOD;
  1411. val |= SM(1, AR_RTC_DERIVED_CLK_PERIOD);
  1412. REG_WRITE(ah, AR_RTC_DERIVED_CLK, val);
  1413. (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
  1414. }
  1415. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1416. AR_RTC_FORCE_WAKE_ON_INT);
  1417. if (AR_SREV_9100(ah)) {
  1418. rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
  1419. AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
  1420. } else {
  1421. tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  1422. if (tmpReg &
  1423. (AR_INTR_SYNC_LOCAL_TIMEOUT |
  1424. AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
  1425. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  1426. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  1427. } else {
  1428. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1429. }
  1430. rst_flags = AR_RTC_RC_MAC_WARM;
  1431. if (type == ATH9K_RESET_COLD)
  1432. rst_flags |= AR_RTC_RC_MAC_COLD;
  1433. }
  1434. REG_WRITE(ah, AR_RTC_RC, rst_flags);
  1435. udelay(50);
  1436. REG_WRITE(ah, AR_RTC_RC, 0);
  1437. if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
  1438. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  1439. "RTC stuck in MAC reset\n");
  1440. return false;
  1441. }
  1442. if (!AR_SREV_9100(ah))
  1443. REG_WRITE(ah, AR_RC, 0);
  1444. ath9k_hw_init_pll(ah, NULL);
  1445. if (AR_SREV_9100(ah))
  1446. udelay(50);
  1447. return true;
  1448. }
  1449. static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
  1450. {
  1451. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1452. AR_RTC_FORCE_WAKE_ON_INT);
  1453. if (!AR_SREV_9100(ah))
  1454. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1455. REG_WRITE(ah, AR_RTC_RESET, 0);
  1456. udelay(2);
  1457. if (!AR_SREV_9100(ah))
  1458. REG_WRITE(ah, AR_RC, 0);
  1459. REG_WRITE(ah, AR_RTC_RESET, 1);
  1460. if (!ath9k_hw_wait(ah,
  1461. AR_RTC_STATUS,
  1462. AR_RTC_STATUS_M,
  1463. AR_RTC_STATUS_ON,
  1464. AH_WAIT_TIMEOUT)) {
  1465. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "RTC not waking up\n");
  1466. return false;
  1467. }
  1468. ath9k_hw_read_revisions(ah);
  1469. return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
  1470. }
  1471. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
  1472. {
  1473. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1474. AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
  1475. switch (type) {
  1476. case ATH9K_RESET_POWER_ON:
  1477. return ath9k_hw_set_reset_power_on(ah);
  1478. case ATH9K_RESET_WARM:
  1479. case ATH9K_RESET_COLD:
  1480. return ath9k_hw_set_reset(ah, type);
  1481. default:
  1482. return false;
  1483. }
  1484. }
  1485. static void ath9k_hw_set_regs(struct ath_hw *ah, struct ath9k_channel *chan,
  1486. enum ath9k_ht_macmode macmode)
  1487. {
  1488. u32 phymode;
  1489. u32 enableDacFifo = 0;
  1490. if (AR_SREV_9285_10_OR_LATER(ah))
  1491. enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
  1492. AR_PHY_FC_ENABLE_DAC_FIFO);
  1493. phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
  1494. | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
  1495. if (IS_CHAN_HT40(chan)) {
  1496. phymode |= AR_PHY_FC_DYN2040_EN;
  1497. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  1498. (chan->chanmode == CHANNEL_G_HT40PLUS))
  1499. phymode |= AR_PHY_FC_DYN2040_PRI_CH;
  1500. if (ah->extprotspacing == ATH9K_HT_EXTPROTSPACING_25)
  1501. phymode |= AR_PHY_FC_DYN2040_EXT_CH;
  1502. }
  1503. REG_WRITE(ah, AR_PHY_TURBO, phymode);
  1504. ath9k_hw_set11nmac2040(ah, macmode);
  1505. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  1506. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  1507. }
  1508. static bool ath9k_hw_chip_reset(struct ath_hw *ah,
  1509. struct ath9k_channel *chan)
  1510. {
  1511. if (OLC_FOR_AR9280_20_LATER) {
  1512. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
  1513. return false;
  1514. } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  1515. return false;
  1516. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1517. return false;
  1518. ah->chip_fullsleep = false;
  1519. ath9k_hw_init_pll(ah, chan);
  1520. ath9k_hw_set_rfmode(ah, chan);
  1521. return true;
  1522. }
  1523. static bool ath9k_hw_channel_change(struct ath_hw *ah,
  1524. struct ath9k_channel *chan,
  1525. enum ath9k_ht_macmode macmode)
  1526. {
  1527. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1528. struct ieee80211_channel *channel = chan->chan;
  1529. u32 synthDelay, qnum;
  1530. for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
  1531. if (ath9k_hw_numtxpending(ah, qnum)) {
  1532. DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
  1533. "Transmit frames pending on queue %d\n", qnum);
  1534. return false;
  1535. }
  1536. }
  1537. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  1538. if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  1539. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT)) {
  1540. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1541. "Could not kill baseband RX\n");
  1542. return false;
  1543. }
  1544. ath9k_hw_set_regs(ah, chan, macmode);
  1545. if (AR_SREV_9280_10_OR_LATER(ah)) {
  1546. ath9k_hw_ar9280_set_channel(ah, chan);
  1547. } else {
  1548. if (!(ath9k_hw_set_channel(ah, chan))) {
  1549. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  1550. "Failed to set channel\n");
  1551. return false;
  1552. }
  1553. }
  1554. ah->eep_ops->set_txpower(ah, chan,
  1555. ath9k_regd_get_ctl(regulatory, chan),
  1556. channel->max_antenna_gain * 2,
  1557. channel->max_power * 2,
  1558. min((u32) MAX_RATE_POWER,
  1559. (u32) regulatory->power_limit));
  1560. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  1561. if (IS_CHAN_B(chan))
  1562. synthDelay = (4 * synthDelay) / 22;
  1563. else
  1564. synthDelay /= 10;
  1565. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  1566. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  1567. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  1568. ath9k_hw_set_delta_slope(ah, chan);
  1569. if (AR_SREV_9280_10_OR_LATER(ah))
  1570. ath9k_hw_9280_spur_mitigate(ah, chan);
  1571. else
  1572. ath9k_hw_spur_mitigate(ah, chan);
  1573. if (!chan->oneTimeCalsDone)
  1574. chan->oneTimeCalsDone = true;
  1575. return true;
  1576. }
  1577. static void ath9k_hw_9280_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
  1578. {
  1579. int bb_spur = AR_NO_SPUR;
  1580. int freq;
  1581. int bin, cur_bin;
  1582. int bb_spur_off, spur_subchannel_sd;
  1583. int spur_freq_sd;
  1584. int spur_delta_phase;
  1585. int denominator;
  1586. int upper, lower, cur_vit_mask;
  1587. int tmp, newVal;
  1588. int i;
  1589. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  1590. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  1591. };
  1592. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  1593. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  1594. };
  1595. int inc[4] = { 0, 100, 0, 0 };
  1596. struct chan_centers centers;
  1597. int8_t mask_m[123];
  1598. int8_t mask_p[123];
  1599. int8_t mask_amt;
  1600. int tmp_mask;
  1601. int cur_bb_spur;
  1602. bool is2GHz = IS_CHAN_2GHZ(chan);
  1603. memset(&mask_m, 0, sizeof(int8_t) * 123);
  1604. memset(&mask_p, 0, sizeof(int8_t) * 123);
  1605. ath9k_hw_get_channel_centers(ah, chan, &centers);
  1606. freq = centers.synth_center;
  1607. ah->config.spurmode = SPUR_ENABLE_EEPROM;
  1608. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  1609. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  1610. if (is2GHz)
  1611. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_2GHZ;
  1612. else
  1613. cur_bb_spur = (cur_bb_spur / 10) + AR_BASE_FREQ_5GHZ;
  1614. if (AR_NO_SPUR == cur_bb_spur)
  1615. break;
  1616. cur_bb_spur = cur_bb_spur - freq;
  1617. if (IS_CHAN_HT40(chan)) {
  1618. if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT40) &&
  1619. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT40)) {
  1620. bb_spur = cur_bb_spur;
  1621. break;
  1622. }
  1623. } else if ((cur_bb_spur > -AR_SPUR_FEEQ_BOUND_HT20) &&
  1624. (cur_bb_spur < AR_SPUR_FEEQ_BOUND_HT20)) {
  1625. bb_spur = cur_bb_spur;
  1626. break;
  1627. }
  1628. }
  1629. if (AR_NO_SPUR == bb_spur) {
  1630. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  1631. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  1632. return;
  1633. } else {
  1634. REG_CLR_BIT(ah, AR_PHY_FORCE_CLKEN_CCK,
  1635. AR_PHY_FORCE_CLKEN_CCK_MRC_MUX);
  1636. }
  1637. bin = bb_spur * 320;
  1638. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  1639. newVal = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  1640. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  1641. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  1642. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  1643. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), newVal);
  1644. newVal = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  1645. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  1646. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  1647. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  1648. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  1649. REG_WRITE(ah, AR_PHY_SPUR_REG, newVal);
  1650. if (IS_CHAN_HT40(chan)) {
  1651. if (bb_spur < 0) {
  1652. spur_subchannel_sd = 1;
  1653. bb_spur_off = bb_spur + 10;
  1654. } else {
  1655. spur_subchannel_sd = 0;
  1656. bb_spur_off = bb_spur - 10;
  1657. }
  1658. } else {
  1659. spur_subchannel_sd = 0;
  1660. bb_spur_off = bb_spur;
  1661. }
  1662. if (IS_CHAN_HT40(chan))
  1663. spur_delta_phase =
  1664. ((bb_spur * 262144) /
  1665. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1666. else
  1667. spur_delta_phase =
  1668. ((bb_spur * 524288) /
  1669. 10) & AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1670. denominator = IS_CHAN_2GHZ(chan) ? 44 : 40;
  1671. spur_freq_sd = ((bb_spur_off * 2048) / denominator) & 0x3ff;
  1672. newVal = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  1673. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  1674. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  1675. REG_WRITE(ah, AR_PHY_TIMING11, newVal);
  1676. newVal = spur_subchannel_sd << AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S;
  1677. REG_WRITE(ah, AR_PHY_SFCORR_EXT, newVal);
  1678. cur_bin = -6000;
  1679. upper = bin + 100;
  1680. lower = bin - 100;
  1681. for (i = 0; i < 4; i++) {
  1682. int pilot_mask = 0;
  1683. int chan_mask = 0;
  1684. int bp = 0;
  1685. for (bp = 0; bp < 30; bp++) {
  1686. if ((cur_bin > lower) && (cur_bin < upper)) {
  1687. pilot_mask = pilot_mask | 0x1 << bp;
  1688. chan_mask = chan_mask | 0x1 << bp;
  1689. }
  1690. cur_bin += 100;
  1691. }
  1692. cur_bin += inc[i];
  1693. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  1694. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  1695. }
  1696. cur_vit_mask = 6100;
  1697. upper = bin + 120;
  1698. lower = bin - 120;
  1699. for (i = 0; i < 123; i++) {
  1700. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  1701. /* workaround for gcc bug #37014 */
  1702. volatile int tmp_v = abs(cur_vit_mask - bin);
  1703. if (tmp_v < 75)
  1704. mask_amt = 1;
  1705. else
  1706. mask_amt = 0;
  1707. if (cur_vit_mask < 0)
  1708. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  1709. else
  1710. mask_p[cur_vit_mask / 100] = mask_amt;
  1711. }
  1712. cur_vit_mask -= 100;
  1713. }
  1714. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  1715. | (mask_m[48] << 26) | (mask_m[49] << 24)
  1716. | (mask_m[50] << 22) | (mask_m[51] << 20)
  1717. | (mask_m[52] << 18) | (mask_m[53] << 16)
  1718. | (mask_m[54] << 14) | (mask_m[55] << 12)
  1719. | (mask_m[56] << 10) | (mask_m[57] << 8)
  1720. | (mask_m[58] << 6) | (mask_m[59] << 4)
  1721. | (mask_m[60] << 2) | (mask_m[61] << 0);
  1722. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  1723. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  1724. tmp_mask = (mask_m[31] << 28)
  1725. | (mask_m[32] << 26) | (mask_m[33] << 24)
  1726. | (mask_m[34] << 22) | (mask_m[35] << 20)
  1727. | (mask_m[36] << 18) | (mask_m[37] << 16)
  1728. | (mask_m[48] << 14) | (mask_m[39] << 12)
  1729. | (mask_m[40] << 10) | (mask_m[41] << 8)
  1730. | (mask_m[42] << 6) | (mask_m[43] << 4)
  1731. | (mask_m[44] << 2) | (mask_m[45] << 0);
  1732. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  1733. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  1734. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  1735. | (mask_m[18] << 26) | (mask_m[18] << 24)
  1736. | (mask_m[20] << 22) | (mask_m[20] << 20)
  1737. | (mask_m[22] << 18) | (mask_m[22] << 16)
  1738. | (mask_m[24] << 14) | (mask_m[24] << 12)
  1739. | (mask_m[25] << 10) | (mask_m[26] << 8)
  1740. | (mask_m[27] << 6) | (mask_m[28] << 4)
  1741. | (mask_m[29] << 2) | (mask_m[30] << 0);
  1742. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  1743. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  1744. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  1745. | (mask_m[2] << 26) | (mask_m[3] << 24)
  1746. | (mask_m[4] << 22) | (mask_m[5] << 20)
  1747. | (mask_m[6] << 18) | (mask_m[7] << 16)
  1748. | (mask_m[8] << 14) | (mask_m[9] << 12)
  1749. | (mask_m[10] << 10) | (mask_m[11] << 8)
  1750. | (mask_m[12] << 6) | (mask_m[13] << 4)
  1751. | (mask_m[14] << 2) | (mask_m[15] << 0);
  1752. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  1753. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  1754. tmp_mask = (mask_p[15] << 28)
  1755. | (mask_p[14] << 26) | (mask_p[13] << 24)
  1756. | (mask_p[12] << 22) | (mask_p[11] << 20)
  1757. | (mask_p[10] << 18) | (mask_p[9] << 16)
  1758. | (mask_p[8] << 14) | (mask_p[7] << 12)
  1759. | (mask_p[6] << 10) | (mask_p[5] << 8)
  1760. | (mask_p[4] << 6) | (mask_p[3] << 4)
  1761. | (mask_p[2] << 2) | (mask_p[1] << 0);
  1762. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  1763. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  1764. tmp_mask = (mask_p[30] << 28)
  1765. | (mask_p[29] << 26) | (mask_p[28] << 24)
  1766. | (mask_p[27] << 22) | (mask_p[26] << 20)
  1767. | (mask_p[25] << 18) | (mask_p[24] << 16)
  1768. | (mask_p[23] << 14) | (mask_p[22] << 12)
  1769. | (mask_p[21] << 10) | (mask_p[20] << 8)
  1770. | (mask_p[19] << 6) | (mask_p[18] << 4)
  1771. | (mask_p[17] << 2) | (mask_p[16] << 0);
  1772. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  1773. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  1774. tmp_mask = (mask_p[45] << 28)
  1775. | (mask_p[44] << 26) | (mask_p[43] << 24)
  1776. | (mask_p[42] << 22) | (mask_p[41] << 20)
  1777. | (mask_p[40] << 18) | (mask_p[39] << 16)
  1778. | (mask_p[38] << 14) | (mask_p[37] << 12)
  1779. | (mask_p[36] << 10) | (mask_p[35] << 8)
  1780. | (mask_p[34] << 6) | (mask_p[33] << 4)
  1781. | (mask_p[32] << 2) | (mask_p[31] << 0);
  1782. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  1783. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  1784. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  1785. | (mask_p[59] << 26) | (mask_p[58] << 24)
  1786. | (mask_p[57] << 22) | (mask_p[56] << 20)
  1787. | (mask_p[55] << 18) | (mask_p[54] << 16)
  1788. | (mask_p[53] << 14) | (mask_p[52] << 12)
  1789. | (mask_p[51] << 10) | (mask_p[50] << 8)
  1790. | (mask_p[49] << 6) | (mask_p[48] << 4)
  1791. | (mask_p[47] << 2) | (mask_p[46] << 0);
  1792. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  1793. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  1794. }
  1795. static void ath9k_hw_spur_mitigate(struct ath_hw *ah, struct ath9k_channel *chan)
  1796. {
  1797. int bb_spur = AR_NO_SPUR;
  1798. int bin, cur_bin;
  1799. int spur_freq_sd;
  1800. int spur_delta_phase;
  1801. int denominator;
  1802. int upper, lower, cur_vit_mask;
  1803. int tmp, new;
  1804. int i;
  1805. int pilot_mask_reg[4] = { AR_PHY_TIMING7, AR_PHY_TIMING8,
  1806. AR_PHY_PILOT_MASK_01_30, AR_PHY_PILOT_MASK_31_60
  1807. };
  1808. int chan_mask_reg[4] = { AR_PHY_TIMING9, AR_PHY_TIMING10,
  1809. AR_PHY_CHANNEL_MASK_01_30, AR_PHY_CHANNEL_MASK_31_60
  1810. };
  1811. int inc[4] = { 0, 100, 0, 0 };
  1812. int8_t mask_m[123];
  1813. int8_t mask_p[123];
  1814. int8_t mask_amt;
  1815. int tmp_mask;
  1816. int cur_bb_spur;
  1817. bool is2GHz = IS_CHAN_2GHZ(chan);
  1818. memset(&mask_m, 0, sizeof(int8_t) * 123);
  1819. memset(&mask_p, 0, sizeof(int8_t) * 123);
  1820. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  1821. cur_bb_spur = ah->eep_ops->get_spur_channel(ah, i, is2GHz);
  1822. if (AR_NO_SPUR == cur_bb_spur)
  1823. break;
  1824. cur_bb_spur = cur_bb_spur - (chan->channel * 10);
  1825. if ((cur_bb_spur > -95) && (cur_bb_spur < 95)) {
  1826. bb_spur = cur_bb_spur;
  1827. break;
  1828. }
  1829. }
  1830. if (AR_NO_SPUR == bb_spur)
  1831. return;
  1832. bin = bb_spur * 32;
  1833. tmp = REG_READ(ah, AR_PHY_TIMING_CTRL4(0));
  1834. new = tmp | (AR_PHY_TIMING_CTRL4_ENABLE_SPUR_RSSI |
  1835. AR_PHY_TIMING_CTRL4_ENABLE_SPUR_FILTER |
  1836. AR_PHY_TIMING_CTRL4_ENABLE_CHAN_MASK |
  1837. AR_PHY_TIMING_CTRL4_ENABLE_PILOT_MASK);
  1838. REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0), new);
  1839. new = (AR_PHY_SPUR_REG_MASK_RATE_CNTL |
  1840. AR_PHY_SPUR_REG_ENABLE_MASK_PPM |
  1841. AR_PHY_SPUR_REG_MASK_RATE_SELECT |
  1842. AR_PHY_SPUR_REG_ENABLE_VIT_SPUR_RSSI |
  1843. SM(SPUR_RSSI_THRESH, AR_PHY_SPUR_REG_SPUR_RSSI_THRESH));
  1844. REG_WRITE(ah, AR_PHY_SPUR_REG, new);
  1845. spur_delta_phase = ((bb_spur * 524288) / 100) &
  1846. AR_PHY_TIMING11_SPUR_DELTA_PHASE;
  1847. denominator = IS_CHAN_2GHZ(chan) ? 440 : 400;
  1848. spur_freq_sd = ((bb_spur * 2048) / denominator) & 0x3ff;
  1849. new = (AR_PHY_TIMING11_USE_SPUR_IN_AGC |
  1850. SM(spur_freq_sd, AR_PHY_TIMING11_SPUR_FREQ_SD) |
  1851. SM(spur_delta_phase, AR_PHY_TIMING11_SPUR_DELTA_PHASE));
  1852. REG_WRITE(ah, AR_PHY_TIMING11, new);
  1853. cur_bin = -6000;
  1854. upper = bin + 100;
  1855. lower = bin - 100;
  1856. for (i = 0; i < 4; i++) {
  1857. int pilot_mask = 0;
  1858. int chan_mask = 0;
  1859. int bp = 0;
  1860. for (bp = 0; bp < 30; bp++) {
  1861. if ((cur_bin > lower) && (cur_bin < upper)) {
  1862. pilot_mask = pilot_mask | 0x1 << bp;
  1863. chan_mask = chan_mask | 0x1 << bp;
  1864. }
  1865. cur_bin += 100;
  1866. }
  1867. cur_bin += inc[i];
  1868. REG_WRITE(ah, pilot_mask_reg[i], pilot_mask);
  1869. REG_WRITE(ah, chan_mask_reg[i], chan_mask);
  1870. }
  1871. cur_vit_mask = 6100;
  1872. upper = bin + 120;
  1873. lower = bin - 120;
  1874. for (i = 0; i < 123; i++) {
  1875. if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
  1876. /* workaround for gcc bug #37014 */
  1877. volatile int tmp_v = abs(cur_vit_mask - bin);
  1878. if (tmp_v < 75)
  1879. mask_amt = 1;
  1880. else
  1881. mask_amt = 0;
  1882. if (cur_vit_mask < 0)
  1883. mask_m[abs(cur_vit_mask / 100)] = mask_amt;
  1884. else
  1885. mask_p[cur_vit_mask / 100] = mask_amt;
  1886. }
  1887. cur_vit_mask -= 100;
  1888. }
  1889. tmp_mask = (mask_m[46] << 30) | (mask_m[47] << 28)
  1890. | (mask_m[48] << 26) | (mask_m[49] << 24)
  1891. | (mask_m[50] << 22) | (mask_m[51] << 20)
  1892. | (mask_m[52] << 18) | (mask_m[53] << 16)
  1893. | (mask_m[54] << 14) | (mask_m[55] << 12)
  1894. | (mask_m[56] << 10) | (mask_m[57] << 8)
  1895. | (mask_m[58] << 6) | (mask_m[59] << 4)
  1896. | (mask_m[60] << 2) | (mask_m[61] << 0);
  1897. REG_WRITE(ah, AR_PHY_BIN_MASK_1, tmp_mask);
  1898. REG_WRITE(ah, AR_PHY_VIT_MASK2_M_46_61, tmp_mask);
  1899. tmp_mask = (mask_m[31] << 28)
  1900. | (mask_m[32] << 26) | (mask_m[33] << 24)
  1901. | (mask_m[34] << 22) | (mask_m[35] << 20)
  1902. | (mask_m[36] << 18) | (mask_m[37] << 16)
  1903. | (mask_m[48] << 14) | (mask_m[39] << 12)
  1904. | (mask_m[40] << 10) | (mask_m[41] << 8)
  1905. | (mask_m[42] << 6) | (mask_m[43] << 4)
  1906. | (mask_m[44] << 2) | (mask_m[45] << 0);
  1907. REG_WRITE(ah, AR_PHY_BIN_MASK_2, tmp_mask);
  1908. REG_WRITE(ah, AR_PHY_MASK2_M_31_45, tmp_mask);
  1909. tmp_mask = (mask_m[16] << 30) | (mask_m[16] << 28)
  1910. | (mask_m[18] << 26) | (mask_m[18] << 24)
  1911. | (mask_m[20] << 22) | (mask_m[20] << 20)
  1912. | (mask_m[22] << 18) | (mask_m[22] << 16)
  1913. | (mask_m[24] << 14) | (mask_m[24] << 12)
  1914. | (mask_m[25] << 10) | (mask_m[26] << 8)
  1915. | (mask_m[27] << 6) | (mask_m[28] << 4)
  1916. | (mask_m[29] << 2) | (mask_m[30] << 0);
  1917. REG_WRITE(ah, AR_PHY_BIN_MASK_3, tmp_mask);
  1918. REG_WRITE(ah, AR_PHY_MASK2_M_16_30, tmp_mask);
  1919. tmp_mask = (mask_m[0] << 30) | (mask_m[1] << 28)
  1920. | (mask_m[2] << 26) | (mask_m[3] << 24)
  1921. | (mask_m[4] << 22) | (mask_m[5] << 20)
  1922. | (mask_m[6] << 18) | (mask_m[7] << 16)
  1923. | (mask_m[8] << 14) | (mask_m[9] << 12)
  1924. | (mask_m[10] << 10) | (mask_m[11] << 8)
  1925. | (mask_m[12] << 6) | (mask_m[13] << 4)
  1926. | (mask_m[14] << 2) | (mask_m[15] << 0);
  1927. REG_WRITE(ah, AR_PHY_MASK_CTL, tmp_mask);
  1928. REG_WRITE(ah, AR_PHY_MASK2_M_00_15, tmp_mask);
  1929. tmp_mask = (mask_p[15] << 28)
  1930. | (mask_p[14] << 26) | (mask_p[13] << 24)
  1931. | (mask_p[12] << 22) | (mask_p[11] << 20)
  1932. | (mask_p[10] << 18) | (mask_p[9] << 16)
  1933. | (mask_p[8] << 14) | (mask_p[7] << 12)
  1934. | (mask_p[6] << 10) | (mask_p[5] << 8)
  1935. | (mask_p[4] << 6) | (mask_p[3] << 4)
  1936. | (mask_p[2] << 2) | (mask_p[1] << 0);
  1937. REG_WRITE(ah, AR_PHY_BIN_MASK2_1, tmp_mask);
  1938. REG_WRITE(ah, AR_PHY_MASK2_P_15_01, tmp_mask);
  1939. tmp_mask = (mask_p[30] << 28)
  1940. | (mask_p[29] << 26) | (mask_p[28] << 24)
  1941. | (mask_p[27] << 22) | (mask_p[26] << 20)
  1942. | (mask_p[25] << 18) | (mask_p[24] << 16)
  1943. | (mask_p[23] << 14) | (mask_p[22] << 12)
  1944. | (mask_p[21] << 10) | (mask_p[20] << 8)
  1945. | (mask_p[19] << 6) | (mask_p[18] << 4)
  1946. | (mask_p[17] << 2) | (mask_p[16] << 0);
  1947. REG_WRITE(ah, AR_PHY_BIN_MASK2_2, tmp_mask);
  1948. REG_WRITE(ah, AR_PHY_MASK2_P_30_16, tmp_mask);
  1949. tmp_mask = (mask_p[45] << 28)
  1950. | (mask_p[44] << 26) | (mask_p[43] << 24)
  1951. | (mask_p[42] << 22) | (mask_p[41] << 20)
  1952. | (mask_p[40] << 18) | (mask_p[39] << 16)
  1953. | (mask_p[38] << 14) | (mask_p[37] << 12)
  1954. | (mask_p[36] << 10) | (mask_p[35] << 8)
  1955. | (mask_p[34] << 6) | (mask_p[33] << 4)
  1956. | (mask_p[32] << 2) | (mask_p[31] << 0);
  1957. REG_WRITE(ah, AR_PHY_BIN_MASK2_3, tmp_mask);
  1958. REG_WRITE(ah, AR_PHY_MASK2_P_45_31, tmp_mask);
  1959. tmp_mask = (mask_p[61] << 30) | (mask_p[60] << 28)
  1960. | (mask_p[59] << 26) | (mask_p[58] << 24)
  1961. | (mask_p[57] << 22) | (mask_p[56] << 20)
  1962. | (mask_p[55] << 18) | (mask_p[54] << 16)
  1963. | (mask_p[53] << 14) | (mask_p[52] << 12)
  1964. | (mask_p[51] << 10) | (mask_p[50] << 8)
  1965. | (mask_p[49] << 6) | (mask_p[48] << 4)
  1966. | (mask_p[47] << 2) | (mask_p[46] << 0);
  1967. REG_WRITE(ah, AR_PHY_BIN_MASK2_4, tmp_mask);
  1968. REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
  1969. }
  1970. static void ath9k_enable_rfkill(struct ath_hw *ah)
  1971. {
  1972. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
  1973. AR_GPIO_INPUT_EN_VAL_RFSILENT_BB);
  1974. REG_CLR_BIT(ah, AR_GPIO_INPUT_MUX2,
  1975. AR_GPIO_INPUT_MUX2_RFSILENT);
  1976. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  1977. REG_SET_BIT(ah, AR_PHY_TEST, RFSILENT_BB);
  1978. }
  1979. int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
  1980. bool bChannelChange)
  1981. {
  1982. u32 saveLedState;
  1983. struct ath_softc *sc = ah->ah_sc;
  1984. struct ath9k_channel *curchan = ah->curchan;
  1985. u32 saveDefAntenna;
  1986. u32 macStaId1;
  1987. int i, rx_chainmask, r;
  1988. ah->extprotspacing = sc->ht_extprotspacing;
  1989. ah->txchainmask = sc->tx_chainmask;
  1990. ah->rxchainmask = sc->rx_chainmask;
  1991. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1992. return -EIO;
  1993. if (curchan)
  1994. ath9k_hw_getnf(ah, curchan);
  1995. if (bChannelChange &&
  1996. (ah->chip_fullsleep != true) &&
  1997. (ah->curchan != NULL) &&
  1998. (chan->channel != ah->curchan->channel) &&
  1999. ((chan->channelFlags & CHANNEL_ALL) ==
  2000. (ah->curchan->channelFlags & CHANNEL_ALL)) &&
  2001. (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
  2002. !IS_CHAN_A_5MHZ_SPACED(ah->curchan)))) {
  2003. if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
  2004. ath9k_hw_loadnf(ah, ah->curchan);
  2005. ath9k_hw_start_nfcal(ah);
  2006. return 0;
  2007. }
  2008. }
  2009. saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
  2010. if (saveDefAntenna == 0)
  2011. saveDefAntenna = 1;
  2012. macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
  2013. saveLedState = REG_READ(ah, AR_CFG_LED) &
  2014. (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
  2015. AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
  2016. ath9k_hw_mark_phy_inactive(ah);
  2017. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  2018. REG_WRITE(ah,
  2019. AR9271_RESET_POWER_DOWN_CONTROL,
  2020. AR9271_RADIO_RF_RST);
  2021. udelay(50);
  2022. }
  2023. if (!ath9k_hw_chip_reset(ah, chan)) {
  2024. DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Chip reset failed\n");
  2025. return -EINVAL;
  2026. }
  2027. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  2028. ah->htc_reset_init = false;
  2029. REG_WRITE(ah,
  2030. AR9271_RESET_POWER_DOWN_CONTROL,
  2031. AR9271_GATE_MAC_CTL);
  2032. udelay(50);
  2033. }
  2034. if (AR_SREV_9280_10_OR_LATER(ah))
  2035. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  2036. if (AR_SREV_9287_12_OR_LATER(ah)) {
  2037. /* Enable ASYNC FIFO */
  2038. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  2039. AR_MAC_PCU_ASYNC_FIFO_REG3_DATAPATH_SEL);
  2040. REG_SET_BIT(ah, AR_PHY_MODE, AR_PHY_MODE_ASYNCFIFO);
  2041. REG_CLR_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  2042. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  2043. REG_SET_BIT(ah, AR_MAC_PCU_ASYNC_FIFO_REG3,
  2044. AR_MAC_PCU_ASYNC_FIFO_REG3_SOFT_RESET);
  2045. }
  2046. r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
  2047. if (r)
  2048. return r;
  2049. /* Setup MFP options for CCMP */
  2050. if (AR_SREV_9280_20_OR_LATER(ah)) {
  2051. /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
  2052. * frames when constructing CCMP AAD. */
  2053. REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
  2054. 0xc7ff);
  2055. ah->sw_mgmt_crypto = false;
  2056. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  2057. /* Disable hardware crypto for management frames */
  2058. REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
  2059. AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
  2060. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  2061. AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
  2062. ah->sw_mgmt_crypto = true;
  2063. } else
  2064. ah->sw_mgmt_crypto = true;
  2065. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  2066. ath9k_hw_set_delta_slope(ah, chan);
  2067. if (AR_SREV_9280_10_OR_LATER(ah))
  2068. ath9k_hw_9280_spur_mitigate(ah, chan);
  2069. else
  2070. ath9k_hw_spur_mitigate(ah, chan);
  2071. ah->eep_ops->set_board_values(ah, chan);
  2072. ath9k_hw_decrease_chain_power(ah, chan);
  2073. REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(ah->macaddr));
  2074. REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(ah->macaddr + 4)
  2075. | macStaId1
  2076. | AR_STA_ID1_RTS_USE_DEF
  2077. | (ah->config.
  2078. ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
  2079. | ah->sta_id1_defaults);
  2080. ath9k_hw_set_operating_mode(ah, ah->opmode);
  2081. REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(sc->bssidmask));
  2082. REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(sc->bssidmask + 4));
  2083. REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
  2084. REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(sc->curbssid));
  2085. REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(sc->curbssid + 4) |
  2086. ((sc->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
  2087. REG_WRITE(ah, AR_ISR, ~0);
  2088. REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
  2089. if (AR_SREV_9280_10_OR_LATER(ah))
  2090. ath9k_hw_ar9280_set_channel(ah, chan);
  2091. else
  2092. if (!(ath9k_hw_set_channel(ah, chan)))
  2093. return -EIO;
  2094. for (i = 0; i < AR_NUM_DCU; i++)
  2095. REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
  2096. ah->intr_txqs = 0;
  2097. for (i = 0; i < ah->caps.total_queues; i++)
  2098. ath9k_hw_resettxqueue(ah, i);
  2099. ath9k_hw_init_interrupt_masks(ah, ah->opmode);
  2100. ath9k_hw_init_qos(ah);
  2101. if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  2102. ath9k_enable_rfkill(ah);
  2103. ath9k_hw_init_user_settings(ah);
  2104. if (AR_SREV_9287_12_OR_LATER(ah)) {
  2105. REG_WRITE(ah, AR_D_GBL_IFS_SIFS,
  2106. AR_D_GBL_IFS_SIFS_ASYNC_FIFO_DUR);
  2107. REG_WRITE(ah, AR_D_GBL_IFS_SLOT,
  2108. AR_D_GBL_IFS_SLOT_ASYNC_FIFO_DUR);
  2109. REG_WRITE(ah, AR_D_GBL_IFS_EIFS,
  2110. AR_D_GBL_IFS_EIFS_ASYNC_FIFO_DUR);
  2111. REG_WRITE(ah, AR_TIME_OUT, AR_TIME_OUT_ACK_CTS_ASYNC_FIFO_DUR);
  2112. REG_WRITE(ah, AR_USEC, AR_USEC_ASYNC_FIFO_DUR);
  2113. REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
  2114. AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
  2115. REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
  2116. AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
  2117. }
  2118. if (AR_SREV_9287_12_OR_LATER(ah)) {
  2119. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  2120. AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
  2121. }
  2122. REG_WRITE(ah, AR_STA_ID1,
  2123. REG_READ(ah, AR_STA_ID1) | AR_STA_ID1_PRESERVE_SEQNUM);
  2124. ath9k_hw_set_dma(ah);
  2125. REG_WRITE(ah, AR_OBS, 8);
  2126. if (ah->config.intr_mitigation) {
  2127. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
  2128. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
  2129. }
  2130. ath9k_hw_init_bb(ah, chan);
  2131. if (!ath9k_hw_init_cal(ah, chan))
  2132. return -EIO;
  2133. rx_chainmask = ah->rxchainmask;
  2134. if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
  2135. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
  2136. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
  2137. }
  2138. REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
  2139. /*
  2140. * For big endian systems turn on swapping for descriptors
  2141. */
  2142. if (AR_SREV_9100(ah)) {
  2143. u32 mask;
  2144. mask = REG_READ(ah, AR_CFG);
  2145. if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
  2146. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  2147. "CFG Byte Swap Set 0x%x\n", mask);
  2148. } else {
  2149. mask =
  2150. INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
  2151. REG_WRITE(ah, AR_CFG, mask);
  2152. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  2153. "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
  2154. }
  2155. } else {
  2156. /* Configure AR9271 target WLAN */
  2157. if (AR_SREV_9271(ah))
  2158. REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
  2159. #ifdef __BIG_ENDIAN
  2160. else
  2161. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  2162. #endif
  2163. }
  2164. if (ah->ah_sc->sc_flags & SC_OP_BTCOEX_ENABLED)
  2165. ath9k_hw_btcoex_enable(ah);
  2166. return 0;
  2167. }
  2168. /************************/
  2169. /* Key Cache Management */
  2170. /************************/
  2171. bool ath9k_hw_keyreset(struct ath_hw *ah, u16 entry)
  2172. {
  2173. u32 keyType;
  2174. if (entry >= ah->caps.keycache_size) {
  2175. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2176. "keychache entry %u out of range\n", entry);
  2177. return false;
  2178. }
  2179. keyType = REG_READ(ah, AR_KEYTABLE_TYPE(entry));
  2180. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), 0);
  2181. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), 0);
  2182. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), 0);
  2183. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), 0);
  2184. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), 0);
  2185. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), AR_KEYTABLE_TYPE_CLR);
  2186. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), 0);
  2187. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), 0);
  2188. if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
  2189. u16 micentry = entry + 64;
  2190. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), 0);
  2191. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  2192. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), 0);
  2193. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  2194. }
  2195. return true;
  2196. }
  2197. bool ath9k_hw_keysetmac(struct ath_hw *ah, u16 entry, const u8 *mac)
  2198. {
  2199. u32 macHi, macLo;
  2200. if (entry >= ah->caps.keycache_size) {
  2201. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2202. "keychache entry %u out of range\n", entry);
  2203. return false;
  2204. }
  2205. if (mac != NULL) {
  2206. macHi = (mac[5] << 8) | mac[4];
  2207. macLo = (mac[3] << 24) |
  2208. (mac[2] << 16) |
  2209. (mac[1] << 8) |
  2210. mac[0];
  2211. macLo >>= 1;
  2212. macLo |= (macHi & 1) << 31;
  2213. macHi >>= 1;
  2214. } else {
  2215. macLo = macHi = 0;
  2216. }
  2217. REG_WRITE(ah, AR_KEYTABLE_MAC0(entry), macLo);
  2218. REG_WRITE(ah, AR_KEYTABLE_MAC1(entry), macHi | AR_KEYTABLE_VALID);
  2219. return true;
  2220. }
  2221. bool ath9k_hw_set_keycache_entry(struct ath_hw *ah, u16 entry,
  2222. const struct ath9k_keyval *k,
  2223. const u8 *mac)
  2224. {
  2225. const struct ath9k_hw_capabilities *pCap = &ah->caps;
  2226. u32 key0, key1, key2, key3, key4;
  2227. u32 keyType;
  2228. if (entry >= pCap->keycache_size) {
  2229. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2230. "keycache entry %u out of range\n", entry);
  2231. return false;
  2232. }
  2233. switch (k->kv_type) {
  2234. case ATH9K_CIPHER_AES_OCB:
  2235. keyType = AR_KEYTABLE_TYPE_AES;
  2236. break;
  2237. case ATH9K_CIPHER_AES_CCM:
  2238. if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
  2239. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  2240. "AES-CCM not supported by mac rev 0x%x\n",
  2241. ah->hw_version.macRev);
  2242. return false;
  2243. }
  2244. keyType = AR_KEYTABLE_TYPE_CCM;
  2245. break;
  2246. case ATH9K_CIPHER_TKIP:
  2247. keyType = AR_KEYTABLE_TYPE_TKIP;
  2248. if (ATH9K_IS_MIC_ENABLED(ah)
  2249. && entry + 64 >= pCap->keycache_size) {
  2250. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  2251. "entry %u inappropriate for TKIP\n", entry);
  2252. return false;
  2253. }
  2254. break;
  2255. case ATH9K_CIPHER_WEP:
  2256. if (k->kv_len < WLAN_KEY_LEN_WEP40) {
  2257. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  2258. "WEP key length %u too small\n", k->kv_len);
  2259. return false;
  2260. }
  2261. if (k->kv_len <= WLAN_KEY_LEN_WEP40)
  2262. keyType = AR_KEYTABLE_TYPE_40;
  2263. else if (k->kv_len <= WLAN_KEY_LEN_WEP104)
  2264. keyType = AR_KEYTABLE_TYPE_104;
  2265. else
  2266. keyType = AR_KEYTABLE_TYPE_128;
  2267. break;
  2268. case ATH9K_CIPHER_CLR:
  2269. keyType = AR_KEYTABLE_TYPE_CLR;
  2270. break;
  2271. default:
  2272. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2273. "cipher %u not supported\n", k->kv_type);
  2274. return false;
  2275. }
  2276. key0 = get_unaligned_le32(k->kv_val + 0);
  2277. key1 = get_unaligned_le16(k->kv_val + 4);
  2278. key2 = get_unaligned_le32(k->kv_val + 6);
  2279. key3 = get_unaligned_le16(k->kv_val + 10);
  2280. key4 = get_unaligned_le32(k->kv_val + 12);
  2281. if (k->kv_len <= WLAN_KEY_LEN_WEP104)
  2282. key4 &= 0xff;
  2283. /*
  2284. * Note: Key cache registers access special memory area that requires
  2285. * two 32-bit writes to actually update the values in the internal
  2286. * memory. Consequently, the exact order and pairs used here must be
  2287. * maintained.
  2288. */
  2289. if (keyType == AR_KEYTABLE_TYPE_TKIP && ATH9K_IS_MIC_ENABLED(ah)) {
  2290. u16 micentry = entry + 64;
  2291. /*
  2292. * Write inverted key[47:0] first to avoid Michael MIC errors
  2293. * on frames that could be sent or received at the same time.
  2294. * The correct key will be written in the end once everything
  2295. * else is ready.
  2296. */
  2297. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), ~key0);
  2298. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), ~key1);
  2299. /* Write key[95:48] */
  2300. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  2301. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  2302. /* Write key[127:96] and key type */
  2303. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  2304. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  2305. /* Write MAC address for the entry */
  2306. (void) ath9k_hw_keysetmac(ah, entry, mac);
  2307. if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) {
  2308. /*
  2309. * TKIP uses two key cache entries:
  2310. * Michael MIC TX/RX keys in the same key cache entry
  2311. * (idx = main index + 64):
  2312. * key0 [31:0] = RX key [31:0]
  2313. * key1 [15:0] = TX key [31:16]
  2314. * key1 [31:16] = reserved
  2315. * key2 [31:0] = RX key [63:32]
  2316. * key3 [15:0] = TX key [15:0]
  2317. * key3 [31:16] = reserved
  2318. * key4 [31:0] = TX key [63:32]
  2319. */
  2320. u32 mic0, mic1, mic2, mic3, mic4;
  2321. mic0 = get_unaligned_le32(k->kv_mic + 0);
  2322. mic2 = get_unaligned_le32(k->kv_mic + 4);
  2323. mic1 = get_unaligned_le16(k->kv_txmic + 2) & 0xffff;
  2324. mic3 = get_unaligned_le16(k->kv_txmic + 0) & 0xffff;
  2325. mic4 = get_unaligned_le32(k->kv_txmic + 4);
  2326. /* Write RX[31:0] and TX[31:16] */
  2327. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  2328. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), mic1);
  2329. /* Write RX[63:32] and TX[15:0] */
  2330. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  2331. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), mic3);
  2332. /* Write TX[63:32] and keyType(reserved) */
  2333. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), mic4);
  2334. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  2335. AR_KEYTABLE_TYPE_CLR);
  2336. } else {
  2337. /*
  2338. * TKIP uses four key cache entries (two for group
  2339. * keys):
  2340. * Michael MIC TX/RX keys are in different key cache
  2341. * entries (idx = main index + 64 for TX and
  2342. * main index + 32 + 96 for RX):
  2343. * key0 [31:0] = TX/RX MIC key [31:0]
  2344. * key1 [31:0] = reserved
  2345. * key2 [31:0] = TX/RX MIC key [63:32]
  2346. * key3 [31:0] = reserved
  2347. * key4 [31:0] = reserved
  2348. *
  2349. * Upper layer code will call this function separately
  2350. * for TX and RX keys when these registers offsets are
  2351. * used.
  2352. */
  2353. u32 mic0, mic2;
  2354. mic0 = get_unaligned_le32(k->kv_mic + 0);
  2355. mic2 = get_unaligned_le32(k->kv_mic + 4);
  2356. /* Write MIC key[31:0] */
  2357. REG_WRITE(ah, AR_KEYTABLE_KEY0(micentry), mic0);
  2358. REG_WRITE(ah, AR_KEYTABLE_KEY1(micentry), 0);
  2359. /* Write MIC key[63:32] */
  2360. REG_WRITE(ah, AR_KEYTABLE_KEY2(micentry), mic2);
  2361. REG_WRITE(ah, AR_KEYTABLE_KEY3(micentry), 0);
  2362. /* Write TX[63:32] and keyType(reserved) */
  2363. REG_WRITE(ah, AR_KEYTABLE_KEY4(micentry), 0);
  2364. REG_WRITE(ah, AR_KEYTABLE_TYPE(micentry),
  2365. AR_KEYTABLE_TYPE_CLR);
  2366. }
  2367. /* MAC address registers are reserved for the MIC entry */
  2368. REG_WRITE(ah, AR_KEYTABLE_MAC0(micentry), 0);
  2369. REG_WRITE(ah, AR_KEYTABLE_MAC1(micentry), 0);
  2370. /*
  2371. * Write the correct (un-inverted) key[47:0] last to enable
  2372. * TKIP now that all other registers are set with correct
  2373. * values.
  2374. */
  2375. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  2376. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  2377. } else {
  2378. /* Write key[47:0] */
  2379. REG_WRITE(ah, AR_KEYTABLE_KEY0(entry), key0);
  2380. REG_WRITE(ah, AR_KEYTABLE_KEY1(entry), key1);
  2381. /* Write key[95:48] */
  2382. REG_WRITE(ah, AR_KEYTABLE_KEY2(entry), key2);
  2383. REG_WRITE(ah, AR_KEYTABLE_KEY3(entry), key3);
  2384. /* Write key[127:96] and key type */
  2385. REG_WRITE(ah, AR_KEYTABLE_KEY4(entry), key4);
  2386. REG_WRITE(ah, AR_KEYTABLE_TYPE(entry), keyType);
  2387. /* Write MAC address for the entry */
  2388. (void) ath9k_hw_keysetmac(ah, entry, mac);
  2389. }
  2390. return true;
  2391. }
  2392. bool ath9k_hw_keyisvalid(struct ath_hw *ah, u16 entry)
  2393. {
  2394. if (entry < ah->caps.keycache_size) {
  2395. u32 val = REG_READ(ah, AR_KEYTABLE_MAC1(entry));
  2396. if (val & AR_KEYTABLE_VALID)
  2397. return true;
  2398. }
  2399. return false;
  2400. }
  2401. /******************************/
  2402. /* Power Management (Chipset) */
  2403. /******************************/
  2404. static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
  2405. {
  2406. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2407. if (setChip) {
  2408. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  2409. AR_RTC_FORCE_WAKE_EN);
  2410. if (!AR_SREV_9100(ah))
  2411. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  2412. REG_CLR_BIT(ah, (AR_RTC_RESET),
  2413. AR_RTC_RESET_EN);
  2414. }
  2415. }
  2416. static void ath9k_set_power_network_sleep(struct ath_hw *ah, int setChip)
  2417. {
  2418. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2419. if (setChip) {
  2420. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2421. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2422. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  2423. AR_RTC_FORCE_WAKE_ON_INT);
  2424. } else {
  2425. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  2426. AR_RTC_FORCE_WAKE_EN);
  2427. }
  2428. }
  2429. }
  2430. static bool ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
  2431. {
  2432. u32 val;
  2433. int i;
  2434. if (setChip) {
  2435. if ((REG_READ(ah, AR_RTC_STATUS) &
  2436. AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
  2437. if (ath9k_hw_set_reset_reg(ah,
  2438. ATH9K_RESET_POWER_ON) != true) {
  2439. return false;
  2440. }
  2441. }
  2442. if (AR_SREV_9100(ah))
  2443. REG_SET_BIT(ah, AR_RTC_RESET,
  2444. AR_RTC_RESET_EN);
  2445. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  2446. AR_RTC_FORCE_WAKE_EN);
  2447. udelay(50);
  2448. for (i = POWER_UP_TIME / 50; i > 0; i--) {
  2449. val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
  2450. if (val == AR_RTC_STATUS_ON)
  2451. break;
  2452. udelay(50);
  2453. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  2454. AR_RTC_FORCE_WAKE_EN);
  2455. }
  2456. if (i == 0) {
  2457. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2458. "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
  2459. return false;
  2460. }
  2461. }
  2462. REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  2463. return true;
  2464. }
  2465. static bool ath9k_hw_setpower_nolock(struct ath_hw *ah,
  2466. enum ath9k_power_mode mode)
  2467. {
  2468. int status = true, setChip = true;
  2469. static const char *modes[] = {
  2470. "AWAKE",
  2471. "FULL-SLEEP",
  2472. "NETWORK SLEEP",
  2473. "UNDEFINED"
  2474. };
  2475. if (ah->power_mode == mode)
  2476. return status;
  2477. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s -> %s\n",
  2478. modes[ah->power_mode], modes[mode]);
  2479. switch (mode) {
  2480. case ATH9K_PM_AWAKE:
  2481. status = ath9k_hw_set_power_awake(ah, setChip);
  2482. break;
  2483. case ATH9K_PM_FULL_SLEEP:
  2484. ath9k_set_power_sleep(ah, setChip);
  2485. ah->chip_fullsleep = true;
  2486. break;
  2487. case ATH9K_PM_NETWORK_SLEEP:
  2488. ath9k_set_power_network_sleep(ah, setChip);
  2489. break;
  2490. default:
  2491. DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
  2492. "Unknown power mode %u\n", mode);
  2493. return false;
  2494. }
  2495. ah->power_mode = mode;
  2496. return status;
  2497. }
  2498. bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
  2499. {
  2500. unsigned long flags;
  2501. bool ret;
  2502. spin_lock_irqsave(&ah->ah_sc->sc_pm_lock, flags);
  2503. ret = ath9k_hw_setpower_nolock(ah, mode);
  2504. spin_unlock_irqrestore(&ah->ah_sc->sc_pm_lock, flags);
  2505. return ret;
  2506. }
  2507. void ath9k_ps_wakeup(struct ath_softc *sc)
  2508. {
  2509. unsigned long flags;
  2510. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  2511. if (++sc->ps_usecount != 1)
  2512. goto unlock;
  2513. ath9k_hw_setpower_nolock(sc->sc_ah, ATH9K_PM_AWAKE);
  2514. unlock:
  2515. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  2516. }
  2517. void ath9k_ps_restore(struct ath_softc *sc)
  2518. {
  2519. unsigned long flags;
  2520. spin_lock_irqsave(&sc->sc_pm_lock, flags);
  2521. if (--sc->ps_usecount != 0)
  2522. goto unlock;
  2523. if (sc->ps_enabled &&
  2524. !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
  2525. SC_OP_WAIT_FOR_CAB |
  2526. SC_OP_WAIT_FOR_PSPOLL_DATA |
  2527. SC_OP_WAIT_FOR_TX_ACK)))
  2528. ath9k_hw_setpower_nolock(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
  2529. unlock:
  2530. spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
  2531. }
  2532. /*
  2533. * Helper for ASPM support.
  2534. *
  2535. * Disable PLL when in L0s as well as receiver clock when in L1.
  2536. * This power saving option must be enabled through the SerDes.
  2537. *
  2538. * Programming the SerDes must go through the same 288 bit serial shift
  2539. * register as the other analog registers. Hence the 9 writes.
  2540. */
  2541. void ath9k_hw_configpcipowersave(struct ath_hw *ah, int restore)
  2542. {
  2543. u8 i;
  2544. if (ah->is_pciexpress != true)
  2545. return;
  2546. /* Do not touch SerDes registers */
  2547. if (ah->config.pcie_powersave_enable == 2)
  2548. return;
  2549. /* Nothing to do on restore for 11N */
  2550. if (restore)
  2551. return;
  2552. if (AR_SREV_9280_20_OR_LATER(ah)) {
  2553. /*
  2554. * AR9280 2.0 or later chips use SerDes values from the
  2555. * initvals.h initialized depending on chipset during
  2556. * ath9k_hw_init()
  2557. */
  2558. for (i = 0; i < ah->iniPcieSerdes.ia_rows; i++) {
  2559. REG_WRITE(ah, INI_RA(&ah->iniPcieSerdes, i, 0),
  2560. INI_RA(&ah->iniPcieSerdes, i, 1));
  2561. }
  2562. } else if (AR_SREV_9280(ah) &&
  2563. (ah->hw_version.macRev == AR_SREV_REVISION_9280_10)) {
  2564. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fd00);
  2565. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  2566. /* RX shut off when elecidle is asserted */
  2567. REG_WRITE(ah, AR_PCIE_SERDES, 0xa8000019);
  2568. REG_WRITE(ah, AR_PCIE_SERDES, 0x13160820);
  2569. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980560);
  2570. /* Shut off CLKREQ active in L1 */
  2571. if (ah->config.pcie_clock_req)
  2572. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffc);
  2573. else
  2574. REG_WRITE(ah, AR_PCIE_SERDES, 0x401deffd);
  2575. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  2576. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  2577. REG_WRITE(ah, AR_PCIE_SERDES, 0x00043007);
  2578. /* Load the new settings */
  2579. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  2580. } else {
  2581. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  2582. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  2583. /* RX shut off when elecidle is asserted */
  2584. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000039);
  2585. REG_WRITE(ah, AR_PCIE_SERDES, 0x53160824);
  2586. REG_WRITE(ah, AR_PCIE_SERDES, 0xe5980579);
  2587. /*
  2588. * Ignore ah->ah_config.pcie_clock_req setting for
  2589. * pre-AR9280 11n
  2590. */
  2591. REG_WRITE(ah, AR_PCIE_SERDES, 0x001defff);
  2592. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  2593. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  2594. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e3007);
  2595. /* Load the new settings */
  2596. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  2597. }
  2598. udelay(1000);
  2599. /* set bit 19 to allow forcing of pcie core into L1 state */
  2600. REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
  2601. /* Several PCIe massages to ensure proper behaviour */
  2602. if (ah->config.pcie_waen) {
  2603. REG_WRITE(ah, AR_WA, ah->config.pcie_waen);
  2604. } else {
  2605. if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah))
  2606. REG_WRITE(ah, AR_WA, AR9285_WA_DEFAULT);
  2607. /*
  2608. * On AR9280 chips bit 22 of 0x4004 needs to be set to
  2609. * otherwise card may disappear.
  2610. */
  2611. else if (AR_SREV_9280(ah))
  2612. REG_WRITE(ah, AR_WA, AR9280_WA_DEFAULT);
  2613. else
  2614. REG_WRITE(ah, AR_WA, AR_WA_DEFAULT);
  2615. }
  2616. }
  2617. /**********************/
  2618. /* Interrupt Handling */
  2619. /**********************/
  2620. bool ath9k_hw_intrpend(struct ath_hw *ah)
  2621. {
  2622. u32 host_isr;
  2623. if (AR_SREV_9100(ah))
  2624. return true;
  2625. host_isr = REG_READ(ah, AR_INTR_ASYNC_CAUSE);
  2626. if ((host_isr & AR_INTR_MAC_IRQ) && (host_isr != AR_INTR_SPURIOUS))
  2627. return true;
  2628. host_isr = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  2629. if ((host_isr & AR_INTR_SYNC_DEFAULT)
  2630. && (host_isr != AR_INTR_SPURIOUS))
  2631. return true;
  2632. return false;
  2633. }
  2634. bool ath9k_hw_getisr(struct ath_hw *ah, enum ath9k_int *masked)
  2635. {
  2636. u32 isr = 0;
  2637. u32 mask2 = 0;
  2638. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2639. u32 sync_cause = 0;
  2640. bool fatal_int = false;
  2641. if (!AR_SREV_9100(ah)) {
  2642. if (REG_READ(ah, AR_INTR_ASYNC_CAUSE) & AR_INTR_MAC_IRQ) {
  2643. if ((REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M)
  2644. == AR_RTC_STATUS_ON) {
  2645. isr = REG_READ(ah, AR_ISR);
  2646. }
  2647. }
  2648. sync_cause = REG_READ(ah, AR_INTR_SYNC_CAUSE) &
  2649. AR_INTR_SYNC_DEFAULT;
  2650. *masked = 0;
  2651. if (!isr && !sync_cause)
  2652. return false;
  2653. } else {
  2654. *masked = 0;
  2655. isr = REG_READ(ah, AR_ISR);
  2656. }
  2657. if (isr) {
  2658. if (isr & AR_ISR_BCNMISC) {
  2659. u32 isr2;
  2660. isr2 = REG_READ(ah, AR_ISR_S2);
  2661. if (isr2 & AR_ISR_S2_TIM)
  2662. mask2 |= ATH9K_INT_TIM;
  2663. if (isr2 & AR_ISR_S2_DTIM)
  2664. mask2 |= ATH9K_INT_DTIM;
  2665. if (isr2 & AR_ISR_S2_DTIMSYNC)
  2666. mask2 |= ATH9K_INT_DTIMSYNC;
  2667. if (isr2 & (AR_ISR_S2_CABEND))
  2668. mask2 |= ATH9K_INT_CABEND;
  2669. if (isr2 & AR_ISR_S2_GTT)
  2670. mask2 |= ATH9K_INT_GTT;
  2671. if (isr2 & AR_ISR_S2_CST)
  2672. mask2 |= ATH9K_INT_CST;
  2673. if (isr2 & AR_ISR_S2_TSFOOR)
  2674. mask2 |= ATH9K_INT_TSFOOR;
  2675. }
  2676. isr = REG_READ(ah, AR_ISR_RAC);
  2677. if (isr == 0xffffffff) {
  2678. *masked = 0;
  2679. return false;
  2680. }
  2681. *masked = isr & ATH9K_INT_COMMON;
  2682. if (ah->config.intr_mitigation) {
  2683. if (isr & (AR_ISR_RXMINTR | AR_ISR_RXINTM))
  2684. *masked |= ATH9K_INT_RX;
  2685. }
  2686. if (isr & (AR_ISR_RXOK | AR_ISR_RXERR))
  2687. *masked |= ATH9K_INT_RX;
  2688. if (isr &
  2689. (AR_ISR_TXOK | AR_ISR_TXDESC | AR_ISR_TXERR |
  2690. AR_ISR_TXEOL)) {
  2691. u32 s0_s, s1_s;
  2692. *masked |= ATH9K_INT_TX;
  2693. s0_s = REG_READ(ah, AR_ISR_S0_S);
  2694. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXOK);
  2695. ah->intr_txqs |= MS(s0_s, AR_ISR_S0_QCU_TXDESC);
  2696. s1_s = REG_READ(ah, AR_ISR_S1_S);
  2697. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXERR);
  2698. ah->intr_txqs |= MS(s1_s, AR_ISR_S1_QCU_TXEOL);
  2699. }
  2700. if (isr & AR_ISR_RXORN) {
  2701. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
  2702. "receive FIFO overrun interrupt\n");
  2703. }
  2704. if (!AR_SREV_9100(ah)) {
  2705. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2706. u32 isr5 = REG_READ(ah, AR_ISR_S5_S);
  2707. if (isr5 & AR_ISR_S5_TIM_TIMER)
  2708. *masked |= ATH9K_INT_TIM_TIMER;
  2709. }
  2710. }
  2711. *masked |= mask2;
  2712. }
  2713. if (AR_SREV_9100(ah))
  2714. return true;
  2715. if (isr & AR_ISR_GENTMR) {
  2716. u32 s5_s;
  2717. s5_s = REG_READ(ah, AR_ISR_S5_S);
  2718. if (isr & AR_ISR_GENTMR) {
  2719. ah->intr_gen_timer_trigger =
  2720. MS(s5_s, AR_ISR_S5_GENTIMER_TRIG);
  2721. ah->intr_gen_timer_thresh =
  2722. MS(s5_s, AR_ISR_S5_GENTIMER_THRESH);
  2723. if (ah->intr_gen_timer_trigger)
  2724. *masked |= ATH9K_INT_GENTIMER;
  2725. }
  2726. }
  2727. if (sync_cause) {
  2728. fatal_int =
  2729. (sync_cause &
  2730. (AR_INTR_SYNC_HOST1_FATAL | AR_INTR_SYNC_HOST1_PERR))
  2731. ? true : false;
  2732. if (fatal_int) {
  2733. if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
  2734. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  2735. "received PCI FATAL interrupt\n");
  2736. }
  2737. if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
  2738. DPRINTF(ah->ah_sc, ATH_DBG_ANY,
  2739. "received PCI PERR interrupt\n");
  2740. }
  2741. *masked |= ATH9K_INT_FATAL;
  2742. }
  2743. if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
  2744. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
  2745. "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
  2746. REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
  2747. REG_WRITE(ah, AR_RC, 0);
  2748. *masked |= ATH9K_INT_FATAL;
  2749. }
  2750. if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
  2751. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
  2752. "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
  2753. }
  2754. REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
  2755. (void) REG_READ(ah, AR_INTR_SYNC_CAUSE_CLR);
  2756. }
  2757. return true;
  2758. }
  2759. enum ath9k_int ath9k_hw_set_interrupts(struct ath_hw *ah, enum ath9k_int ints)
  2760. {
  2761. u32 omask = ah->mask_reg;
  2762. u32 mask, mask2;
  2763. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2764. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
  2765. if (omask & ATH9K_INT_GLOBAL) {
  2766. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "disable IER\n");
  2767. REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
  2768. (void) REG_READ(ah, AR_IER);
  2769. if (!AR_SREV_9100(ah)) {
  2770. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE, 0);
  2771. (void) REG_READ(ah, AR_INTR_ASYNC_ENABLE);
  2772. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  2773. (void) REG_READ(ah, AR_INTR_SYNC_ENABLE);
  2774. }
  2775. }
  2776. mask = ints & ATH9K_INT_COMMON;
  2777. mask2 = 0;
  2778. if (ints & ATH9K_INT_TX) {
  2779. if (ah->txok_interrupt_mask)
  2780. mask |= AR_IMR_TXOK;
  2781. if (ah->txdesc_interrupt_mask)
  2782. mask |= AR_IMR_TXDESC;
  2783. if (ah->txerr_interrupt_mask)
  2784. mask |= AR_IMR_TXERR;
  2785. if (ah->txeol_interrupt_mask)
  2786. mask |= AR_IMR_TXEOL;
  2787. }
  2788. if (ints & ATH9K_INT_RX) {
  2789. mask |= AR_IMR_RXERR;
  2790. if (ah->config.intr_mitigation)
  2791. mask |= AR_IMR_RXMINTR | AR_IMR_RXINTM;
  2792. else
  2793. mask |= AR_IMR_RXOK | AR_IMR_RXDESC;
  2794. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP))
  2795. mask |= AR_IMR_GENTMR;
  2796. }
  2797. if (ints & (ATH9K_INT_BMISC)) {
  2798. mask |= AR_IMR_BCNMISC;
  2799. if (ints & ATH9K_INT_TIM)
  2800. mask2 |= AR_IMR_S2_TIM;
  2801. if (ints & ATH9K_INT_DTIM)
  2802. mask2 |= AR_IMR_S2_DTIM;
  2803. if (ints & ATH9K_INT_DTIMSYNC)
  2804. mask2 |= AR_IMR_S2_DTIMSYNC;
  2805. if (ints & ATH9K_INT_CABEND)
  2806. mask2 |= AR_IMR_S2_CABEND;
  2807. if (ints & ATH9K_INT_TSFOOR)
  2808. mask2 |= AR_IMR_S2_TSFOOR;
  2809. }
  2810. if (ints & (ATH9K_INT_GTT | ATH9K_INT_CST)) {
  2811. mask |= AR_IMR_BCNMISC;
  2812. if (ints & ATH9K_INT_GTT)
  2813. mask2 |= AR_IMR_S2_GTT;
  2814. if (ints & ATH9K_INT_CST)
  2815. mask2 |= AR_IMR_S2_CST;
  2816. }
  2817. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
  2818. REG_WRITE(ah, AR_IMR, mask);
  2819. mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
  2820. AR_IMR_S2_DTIM |
  2821. AR_IMR_S2_DTIMSYNC |
  2822. AR_IMR_S2_CABEND |
  2823. AR_IMR_S2_CABTO |
  2824. AR_IMR_S2_TSFOOR |
  2825. AR_IMR_S2_GTT | AR_IMR_S2_CST);
  2826. REG_WRITE(ah, AR_IMR_S2, mask | mask2);
  2827. ah->mask_reg = ints;
  2828. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  2829. if (ints & ATH9K_INT_TIM_TIMER)
  2830. REG_SET_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  2831. else
  2832. REG_CLR_BIT(ah, AR_IMR_S5, AR_IMR_S5_TIM_TIMER);
  2833. }
  2834. if (ints & ATH9K_INT_GLOBAL) {
  2835. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "enable IER\n");
  2836. REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
  2837. if (!AR_SREV_9100(ah)) {
  2838. REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
  2839. AR_INTR_MAC_IRQ);
  2840. REG_WRITE(ah, AR_INTR_ASYNC_MASK, AR_INTR_MAC_IRQ);
  2841. REG_WRITE(ah, AR_INTR_SYNC_ENABLE,
  2842. AR_INTR_SYNC_DEFAULT);
  2843. REG_WRITE(ah, AR_INTR_SYNC_MASK,
  2844. AR_INTR_SYNC_DEFAULT);
  2845. }
  2846. DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "AR_IMR 0x%x IER 0x%x\n",
  2847. REG_READ(ah, AR_IMR), REG_READ(ah, AR_IER));
  2848. }
  2849. return omask;
  2850. }
  2851. /*******************/
  2852. /* Beacon Handling */
  2853. /*******************/
  2854. void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
  2855. {
  2856. int flags = 0;
  2857. ah->beacon_interval = beacon_period;
  2858. switch (ah->opmode) {
  2859. case NL80211_IFTYPE_STATION:
  2860. case NL80211_IFTYPE_MONITOR:
  2861. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
  2862. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
  2863. REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
  2864. flags |= AR_TBTT_TIMER_EN;
  2865. break;
  2866. case NL80211_IFTYPE_ADHOC:
  2867. case NL80211_IFTYPE_MESH_POINT:
  2868. REG_SET_BIT(ah, AR_TXCFG,
  2869. AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
  2870. REG_WRITE(ah, AR_NEXT_NDP_TIMER,
  2871. TU_TO_USEC(next_beacon +
  2872. (ah->atim_window ? ah->
  2873. atim_window : 1)));
  2874. flags |= AR_NDP_TIMER_EN;
  2875. case NL80211_IFTYPE_AP:
  2876. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
  2877. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
  2878. TU_TO_USEC(next_beacon -
  2879. ah->config.
  2880. dma_beacon_response_time));
  2881. REG_WRITE(ah, AR_NEXT_SWBA,
  2882. TU_TO_USEC(next_beacon -
  2883. ah->config.
  2884. sw_beacon_response_time));
  2885. flags |=
  2886. AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
  2887. break;
  2888. default:
  2889. DPRINTF(ah->ah_sc, ATH_DBG_BEACON,
  2890. "%s: unsupported opmode: %d\n",
  2891. __func__, ah->opmode);
  2892. return;
  2893. break;
  2894. }
  2895. REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
  2896. REG_WRITE(ah, AR_DMA_BEACON_PERIOD, TU_TO_USEC(beacon_period));
  2897. REG_WRITE(ah, AR_SWBA_PERIOD, TU_TO_USEC(beacon_period));
  2898. REG_WRITE(ah, AR_NDP_PERIOD, TU_TO_USEC(beacon_period));
  2899. beacon_period &= ~ATH9K_BEACON_ENA;
  2900. if (beacon_period & ATH9K_BEACON_RESET_TSF) {
  2901. beacon_period &= ~ATH9K_BEACON_RESET_TSF;
  2902. ath9k_hw_reset_tsf(ah);
  2903. }
  2904. REG_SET_BIT(ah, AR_TIMER_MODE, flags);
  2905. }
  2906. void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
  2907. const struct ath9k_beacon_state *bs)
  2908. {
  2909. u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
  2910. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2911. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(bs->bs_nexttbtt));
  2912. REG_WRITE(ah, AR_BEACON_PERIOD,
  2913. TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
  2914. REG_WRITE(ah, AR_DMA_BEACON_PERIOD,
  2915. TU_TO_USEC(bs->bs_intval & ATH9K_BEACON_PERIOD));
  2916. REG_RMW_FIELD(ah, AR_RSSI_THR,
  2917. AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
  2918. beaconintval = bs->bs_intval & ATH9K_BEACON_PERIOD;
  2919. if (bs->bs_sleepduration > beaconintval)
  2920. beaconintval = bs->bs_sleepduration;
  2921. dtimperiod = bs->bs_dtimperiod;
  2922. if (bs->bs_sleepduration > dtimperiod)
  2923. dtimperiod = bs->bs_sleepduration;
  2924. if (beaconintval == dtimperiod)
  2925. nextTbtt = bs->bs_nextdtim;
  2926. else
  2927. nextTbtt = bs->bs_nexttbtt;
  2928. DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
  2929. DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
  2930. DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
  2931. DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
  2932. REG_WRITE(ah, AR_NEXT_DTIM,
  2933. TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
  2934. REG_WRITE(ah, AR_NEXT_TIM, TU_TO_USEC(nextTbtt - SLEEP_SLOP));
  2935. REG_WRITE(ah, AR_SLEEP1,
  2936. SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
  2937. | AR_SLEEP1_ASSUME_DTIM);
  2938. if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
  2939. beacontimeout = (BEACON_TIMEOUT_VAL << 3);
  2940. else
  2941. beacontimeout = MIN_BEACON_TIMEOUT_VAL;
  2942. REG_WRITE(ah, AR_SLEEP2,
  2943. SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
  2944. REG_WRITE(ah, AR_TIM_PERIOD, TU_TO_USEC(beaconintval));
  2945. REG_WRITE(ah, AR_DTIM_PERIOD, TU_TO_USEC(dtimperiod));
  2946. REG_SET_BIT(ah, AR_TIMER_MODE,
  2947. AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
  2948. AR_DTIM_TIMER_EN);
  2949. /* TSF Out of Range Threshold */
  2950. REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
  2951. }
  2952. /*******************/
  2953. /* HW Capabilities */
  2954. /*******************/
  2955. void ath9k_hw_fill_cap_info(struct ath_hw *ah)
  2956. {
  2957. struct ath9k_hw_capabilities *pCap = &ah->caps;
  2958. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  2959. struct ath_btcoex_info *btcoex_info = &ah->ah_sc->btcoex_info;
  2960. u16 capField = 0, eeval;
  2961. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
  2962. regulatory->current_rd = eeval;
  2963. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
  2964. if (AR_SREV_9285_10_OR_LATER(ah))
  2965. eeval |= AR9285_RDEXT_DEFAULT;
  2966. regulatory->current_rd_ext = eeval;
  2967. capField = ah->eep_ops->get_eeprom(ah, EEP_OP_CAP);
  2968. if (ah->opmode != NL80211_IFTYPE_AP &&
  2969. ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
  2970. if (regulatory->current_rd == 0x64 ||
  2971. regulatory->current_rd == 0x65)
  2972. regulatory->current_rd += 5;
  2973. else if (regulatory->current_rd == 0x41)
  2974. regulatory->current_rd = 0x43;
  2975. DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
  2976. "regdomain mapped to 0x%x\n", regulatory->current_rd);
  2977. }
  2978. eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
  2979. bitmap_zero(pCap->wireless_modes, ATH9K_MODE_MAX);
  2980. if (eeval & AR5416_OPFLAGS_11A) {
  2981. set_bit(ATH9K_MODE_11A, pCap->wireless_modes);
  2982. if (ah->config.ht_enable) {
  2983. if (!(eeval & AR5416_OPFLAGS_N_5G_HT20))
  2984. set_bit(ATH9K_MODE_11NA_HT20,
  2985. pCap->wireless_modes);
  2986. if (!(eeval & AR5416_OPFLAGS_N_5G_HT40)) {
  2987. set_bit(ATH9K_MODE_11NA_HT40PLUS,
  2988. pCap->wireless_modes);
  2989. set_bit(ATH9K_MODE_11NA_HT40MINUS,
  2990. pCap->wireless_modes);
  2991. }
  2992. }
  2993. }
  2994. if (eeval & AR5416_OPFLAGS_11G) {
  2995. set_bit(ATH9K_MODE_11G, pCap->wireless_modes);
  2996. if (ah->config.ht_enable) {
  2997. if (!(eeval & AR5416_OPFLAGS_N_2G_HT20))
  2998. set_bit(ATH9K_MODE_11NG_HT20,
  2999. pCap->wireless_modes);
  3000. if (!(eeval & AR5416_OPFLAGS_N_2G_HT40)) {
  3001. set_bit(ATH9K_MODE_11NG_HT40PLUS,
  3002. pCap->wireless_modes);
  3003. set_bit(ATH9K_MODE_11NG_HT40MINUS,
  3004. pCap->wireless_modes);
  3005. }
  3006. }
  3007. }
  3008. pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
  3009. /*
  3010. * For AR9271 we will temporarilly uses the rx chainmax as read from
  3011. * the EEPROM.
  3012. */
  3013. if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
  3014. !(eeval & AR5416_OPFLAGS_11A) &&
  3015. !(AR_SREV_9271(ah)))
  3016. /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
  3017. pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
  3018. else
  3019. /* Use rx_chainmask from EEPROM. */
  3020. pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
  3021. if (!(AR_SREV_9280(ah) && (ah->hw_version.macRev == 0)))
  3022. ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
  3023. pCap->low_2ghz_chan = 2312;
  3024. pCap->high_2ghz_chan = 2732;
  3025. pCap->low_5ghz_chan = 4920;
  3026. pCap->high_5ghz_chan = 6100;
  3027. pCap->hw_caps &= ~ATH9K_HW_CAP_CIPHER_CKIP;
  3028. pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_TKIP;
  3029. pCap->hw_caps |= ATH9K_HW_CAP_CIPHER_AESCCM;
  3030. pCap->hw_caps &= ~ATH9K_HW_CAP_MIC_CKIP;
  3031. pCap->hw_caps |= ATH9K_HW_CAP_MIC_TKIP;
  3032. pCap->hw_caps |= ATH9K_HW_CAP_MIC_AESCCM;
  3033. if (ah->config.ht_enable)
  3034. pCap->hw_caps |= ATH9K_HW_CAP_HT;
  3035. else
  3036. pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
  3037. pCap->hw_caps |= ATH9K_HW_CAP_GTT;
  3038. pCap->hw_caps |= ATH9K_HW_CAP_VEOL;
  3039. pCap->hw_caps |= ATH9K_HW_CAP_BSSIDMASK;
  3040. pCap->hw_caps &= ~ATH9K_HW_CAP_MCAST_KEYSEARCH;
  3041. if (capField & AR_EEPROM_EEPCAP_MAXQCU)
  3042. pCap->total_queues =
  3043. MS(capField, AR_EEPROM_EEPCAP_MAXQCU);
  3044. else
  3045. pCap->total_queues = ATH9K_NUM_TX_QUEUES;
  3046. if (capField & AR_EEPROM_EEPCAP_KC_ENTRIES)
  3047. pCap->keycache_size =
  3048. 1 << MS(capField, AR_EEPROM_EEPCAP_KC_ENTRIES);
  3049. else
  3050. pCap->keycache_size = AR_KEYTABLE_SIZE;
  3051. pCap->hw_caps |= ATH9K_HW_CAP_FASTCC;
  3052. pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
  3053. if (AR_SREV_9285_10_OR_LATER(ah))
  3054. pCap->num_gpio_pins = AR9285_NUM_GPIO;
  3055. else if (AR_SREV_9280_10_OR_LATER(ah))
  3056. pCap->num_gpio_pins = AR928X_NUM_GPIO;
  3057. else
  3058. pCap->num_gpio_pins = AR_NUM_GPIO;
  3059. if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
  3060. pCap->hw_caps |= ATH9K_HW_CAP_CST;
  3061. pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
  3062. } else {
  3063. pCap->rts_aggr_limit = (8 * 1024);
  3064. }
  3065. pCap->hw_caps |= ATH9K_HW_CAP_ENHANCEDPM;
  3066. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  3067. ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
  3068. if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
  3069. ah->rfkill_gpio =
  3070. MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
  3071. ah->rfkill_polarity =
  3072. MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
  3073. pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
  3074. }
  3075. #endif
  3076. if ((ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI) ||
  3077. (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE) ||
  3078. (ah->hw_version.macVersion == AR_SREV_VERSION_9160) ||
  3079. (ah->hw_version.macVersion == AR_SREV_VERSION_9100) ||
  3080. (ah->hw_version.macVersion == AR_SREV_VERSION_9280) ||
  3081. (ah->hw_version.macVersion == AR_SREV_VERSION_9285))
  3082. pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
  3083. else
  3084. pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
  3085. if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
  3086. pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
  3087. else
  3088. pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
  3089. if (regulatory->current_rd_ext & (1 << REG_EXT_JAPAN_MIDBAND)) {
  3090. pCap->reg_cap =
  3091. AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
  3092. AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN |
  3093. AR_EEPROM_EEREGCAP_EN_KK_U2 |
  3094. AR_EEPROM_EEREGCAP_EN_KK_MIDBAND;
  3095. } else {
  3096. pCap->reg_cap =
  3097. AR_EEPROM_EEREGCAP_EN_KK_NEW_11A |
  3098. AR_EEPROM_EEREGCAP_EN_KK_U1_EVEN;
  3099. }
  3100. pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
  3101. pCap->num_antcfg_5ghz =
  3102. ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
  3103. pCap->num_antcfg_2ghz =
  3104. ah->eep_ops->get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
  3105. if (AR_SREV_9280_10_OR_LATER(ah) &&
  3106. ath_btcoex_supported(ah->hw_version.subsysid)) {
  3107. btcoex_info->btactive_gpio = ATH_BTACTIVE_GPIO;
  3108. btcoex_info->wlanactive_gpio = ATH_WLANACTIVE_GPIO;
  3109. if (AR_SREV_9285(ah)) {
  3110. btcoex_info->btcoex_scheme = ATH_BTCOEX_CFG_3WIRE;
  3111. btcoex_info->btpriority_gpio = ATH_BTPRIORITY_GPIO;
  3112. } else {
  3113. btcoex_info->btcoex_scheme = ATH_BTCOEX_CFG_2WIRE;
  3114. }
  3115. } else {
  3116. btcoex_info->btcoex_scheme = ATH_BTCOEX_CFG_NONE;
  3117. }
  3118. }
  3119. bool ath9k_hw_getcapability(struct ath_hw *ah, enum ath9k_capability_type type,
  3120. u32 capability, u32 *result)
  3121. {
  3122. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  3123. switch (type) {
  3124. case ATH9K_CAP_CIPHER:
  3125. switch (capability) {
  3126. case ATH9K_CIPHER_AES_CCM:
  3127. case ATH9K_CIPHER_AES_OCB:
  3128. case ATH9K_CIPHER_TKIP:
  3129. case ATH9K_CIPHER_WEP:
  3130. case ATH9K_CIPHER_MIC:
  3131. case ATH9K_CIPHER_CLR:
  3132. return true;
  3133. default:
  3134. return false;
  3135. }
  3136. case ATH9K_CAP_TKIP_MIC:
  3137. switch (capability) {
  3138. case 0:
  3139. return true;
  3140. case 1:
  3141. return (ah->sta_id1_defaults &
  3142. AR_STA_ID1_CRPT_MIC_ENABLE) ? true :
  3143. false;
  3144. }
  3145. case ATH9K_CAP_TKIP_SPLIT:
  3146. return (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA) ?
  3147. false : true;
  3148. case ATH9K_CAP_DIVERSITY:
  3149. return (REG_READ(ah, AR_PHY_CCK_DETECT) &
  3150. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV) ?
  3151. true : false;
  3152. case ATH9K_CAP_MCAST_KEYSRCH:
  3153. switch (capability) {
  3154. case 0:
  3155. return true;
  3156. case 1:
  3157. if (REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_ADHOC) {
  3158. return false;
  3159. } else {
  3160. return (ah->sta_id1_defaults &
  3161. AR_STA_ID1_MCAST_KSRCH) ? true :
  3162. false;
  3163. }
  3164. }
  3165. return false;
  3166. case ATH9K_CAP_TXPOW:
  3167. switch (capability) {
  3168. case 0:
  3169. return 0;
  3170. case 1:
  3171. *result = regulatory->power_limit;
  3172. return 0;
  3173. case 2:
  3174. *result = regulatory->max_power_level;
  3175. return 0;
  3176. case 3:
  3177. *result = regulatory->tp_scale;
  3178. return 0;
  3179. }
  3180. return false;
  3181. case ATH9K_CAP_DS:
  3182. return (AR_SREV_9280_20_OR_LATER(ah) &&
  3183. (ah->eep_ops->get_eeprom(ah, EEP_RC_CHAIN_MASK) == 1))
  3184. ? false : true;
  3185. default:
  3186. return false;
  3187. }
  3188. }
  3189. bool ath9k_hw_setcapability(struct ath_hw *ah, enum ath9k_capability_type type,
  3190. u32 capability, u32 setting, int *status)
  3191. {
  3192. u32 v;
  3193. switch (type) {
  3194. case ATH9K_CAP_TKIP_MIC:
  3195. if (setting)
  3196. ah->sta_id1_defaults |=
  3197. AR_STA_ID1_CRPT_MIC_ENABLE;
  3198. else
  3199. ah->sta_id1_defaults &=
  3200. ~AR_STA_ID1_CRPT_MIC_ENABLE;
  3201. return true;
  3202. case ATH9K_CAP_DIVERSITY:
  3203. v = REG_READ(ah, AR_PHY_CCK_DETECT);
  3204. if (setting)
  3205. v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  3206. else
  3207. v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  3208. REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
  3209. return true;
  3210. case ATH9K_CAP_MCAST_KEYSRCH:
  3211. if (setting)
  3212. ah->sta_id1_defaults |= AR_STA_ID1_MCAST_KSRCH;
  3213. else
  3214. ah->sta_id1_defaults &= ~AR_STA_ID1_MCAST_KSRCH;
  3215. return true;
  3216. default:
  3217. return false;
  3218. }
  3219. }
  3220. /****************************/
  3221. /* GPIO / RFKILL / Antennae */
  3222. /****************************/
  3223. static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
  3224. u32 gpio, u32 type)
  3225. {
  3226. int addr;
  3227. u32 gpio_shift, tmp;
  3228. if (gpio > 11)
  3229. addr = AR_GPIO_OUTPUT_MUX3;
  3230. else if (gpio > 5)
  3231. addr = AR_GPIO_OUTPUT_MUX2;
  3232. else
  3233. addr = AR_GPIO_OUTPUT_MUX1;
  3234. gpio_shift = (gpio % 6) * 5;
  3235. if (AR_SREV_9280_20_OR_LATER(ah)
  3236. || (addr != AR_GPIO_OUTPUT_MUX1)) {
  3237. REG_RMW(ah, addr, (type << gpio_shift),
  3238. (0x1f << gpio_shift));
  3239. } else {
  3240. tmp = REG_READ(ah, addr);
  3241. tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
  3242. tmp &= ~(0x1f << gpio_shift);
  3243. tmp |= (type << gpio_shift);
  3244. REG_WRITE(ah, addr, tmp);
  3245. }
  3246. }
  3247. void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
  3248. {
  3249. u32 gpio_shift;
  3250. ASSERT(gpio < ah->caps.num_gpio_pins);
  3251. gpio_shift = gpio << 1;
  3252. REG_RMW(ah,
  3253. AR_GPIO_OE_OUT,
  3254. (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
  3255. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  3256. }
  3257. u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
  3258. {
  3259. #define MS_REG_READ(x, y) \
  3260. (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
  3261. if (gpio >= ah->caps.num_gpio_pins)
  3262. return 0xffffffff;
  3263. if (AR_SREV_9287_10_OR_LATER(ah))
  3264. return MS_REG_READ(AR9287, gpio) != 0;
  3265. else if (AR_SREV_9285_10_OR_LATER(ah))
  3266. return MS_REG_READ(AR9285, gpio) != 0;
  3267. else if (AR_SREV_9280_10_OR_LATER(ah))
  3268. return MS_REG_READ(AR928X, gpio) != 0;
  3269. else
  3270. return MS_REG_READ(AR, gpio) != 0;
  3271. }
  3272. void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
  3273. u32 ah_signal_type)
  3274. {
  3275. u32 gpio_shift;
  3276. ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
  3277. gpio_shift = 2 * gpio;
  3278. REG_RMW(ah,
  3279. AR_GPIO_OE_OUT,
  3280. (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
  3281. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  3282. }
  3283. void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
  3284. {
  3285. REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
  3286. AR_GPIO_BIT(gpio));
  3287. }
  3288. u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
  3289. {
  3290. return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
  3291. }
  3292. void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
  3293. {
  3294. REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
  3295. }
  3296. bool ath9k_hw_setantennaswitch(struct ath_hw *ah,
  3297. enum ath9k_ant_setting settings,
  3298. struct ath9k_channel *chan,
  3299. u8 *tx_chainmask,
  3300. u8 *rx_chainmask,
  3301. u8 *antenna_cfgd)
  3302. {
  3303. static u8 tx_chainmask_cfg, rx_chainmask_cfg;
  3304. if (AR_SREV_9280(ah)) {
  3305. if (!tx_chainmask_cfg) {
  3306. tx_chainmask_cfg = *tx_chainmask;
  3307. rx_chainmask_cfg = *rx_chainmask;
  3308. }
  3309. switch (settings) {
  3310. case ATH9K_ANT_FIXED_A:
  3311. *tx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
  3312. *rx_chainmask = ATH9K_ANTENNA0_CHAINMASK;
  3313. *antenna_cfgd = true;
  3314. break;
  3315. case ATH9K_ANT_FIXED_B:
  3316. if (ah->caps.tx_chainmask >
  3317. ATH9K_ANTENNA1_CHAINMASK) {
  3318. *tx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
  3319. }
  3320. *rx_chainmask = ATH9K_ANTENNA1_CHAINMASK;
  3321. *antenna_cfgd = true;
  3322. break;
  3323. case ATH9K_ANT_VARIABLE:
  3324. *tx_chainmask = tx_chainmask_cfg;
  3325. *rx_chainmask = rx_chainmask_cfg;
  3326. *antenna_cfgd = true;
  3327. break;
  3328. default:
  3329. break;
  3330. }
  3331. } else {
  3332. ah->config.diversity_control = settings;
  3333. }
  3334. return true;
  3335. }
  3336. /*********************/
  3337. /* General Operation */
  3338. /*********************/
  3339. u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
  3340. {
  3341. u32 bits = REG_READ(ah, AR_RX_FILTER);
  3342. u32 phybits = REG_READ(ah, AR_PHY_ERR);
  3343. if (phybits & AR_PHY_ERR_RADAR)
  3344. bits |= ATH9K_RX_FILTER_PHYRADAR;
  3345. if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
  3346. bits |= ATH9K_RX_FILTER_PHYERR;
  3347. return bits;
  3348. }
  3349. void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
  3350. {
  3351. u32 phybits;
  3352. REG_WRITE(ah, AR_RX_FILTER, bits);
  3353. phybits = 0;
  3354. if (bits & ATH9K_RX_FILTER_PHYRADAR)
  3355. phybits |= AR_PHY_ERR_RADAR;
  3356. if (bits & ATH9K_RX_FILTER_PHYERR)
  3357. phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
  3358. REG_WRITE(ah, AR_PHY_ERR, phybits);
  3359. if (phybits)
  3360. REG_WRITE(ah, AR_RXCFG,
  3361. REG_READ(ah, AR_RXCFG) | AR_RXCFG_ZLFDMA);
  3362. else
  3363. REG_WRITE(ah, AR_RXCFG,
  3364. REG_READ(ah, AR_RXCFG) & ~AR_RXCFG_ZLFDMA);
  3365. }
  3366. bool ath9k_hw_phy_disable(struct ath_hw *ah)
  3367. {
  3368. return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM);
  3369. }
  3370. bool ath9k_hw_disable(struct ath_hw *ah)
  3371. {
  3372. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  3373. return false;
  3374. return ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD);
  3375. }
  3376. void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit)
  3377. {
  3378. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  3379. struct ath9k_channel *chan = ah->curchan;
  3380. struct ieee80211_channel *channel = chan->chan;
  3381. regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
  3382. ah->eep_ops->set_txpower(ah, chan,
  3383. ath9k_regd_get_ctl(regulatory, chan),
  3384. channel->max_antenna_gain * 2,
  3385. channel->max_power * 2,
  3386. min((u32) MAX_RATE_POWER,
  3387. (u32) regulatory->power_limit));
  3388. }
  3389. void ath9k_hw_setmac(struct ath_hw *ah, const u8 *mac)
  3390. {
  3391. memcpy(ah->macaddr, mac, ETH_ALEN);
  3392. }
  3393. void ath9k_hw_setopmode(struct ath_hw *ah)
  3394. {
  3395. ath9k_hw_set_operating_mode(ah, ah->opmode);
  3396. }
  3397. void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
  3398. {
  3399. REG_WRITE(ah, AR_MCAST_FIL0, filter0);
  3400. REG_WRITE(ah, AR_MCAST_FIL1, filter1);
  3401. }
  3402. void ath9k_hw_setbssidmask(struct ath_softc *sc)
  3403. {
  3404. REG_WRITE(sc->sc_ah, AR_BSSMSKL, get_unaligned_le32(sc->bssidmask));
  3405. REG_WRITE(sc->sc_ah, AR_BSSMSKU, get_unaligned_le16(sc->bssidmask + 4));
  3406. }
  3407. void ath9k_hw_write_associd(struct ath_softc *sc)
  3408. {
  3409. REG_WRITE(sc->sc_ah, AR_BSS_ID0, get_unaligned_le32(sc->curbssid));
  3410. REG_WRITE(sc->sc_ah, AR_BSS_ID1, get_unaligned_le16(sc->curbssid + 4) |
  3411. ((sc->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
  3412. }
  3413. u64 ath9k_hw_gettsf64(struct ath_hw *ah)
  3414. {
  3415. u64 tsf;
  3416. tsf = REG_READ(ah, AR_TSF_U32);
  3417. tsf = (tsf << 32) | REG_READ(ah, AR_TSF_L32);
  3418. return tsf;
  3419. }
  3420. void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
  3421. {
  3422. REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
  3423. REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
  3424. }
  3425. void ath9k_hw_reset_tsf(struct ath_hw *ah)
  3426. {
  3427. ath9k_ps_wakeup(ah->ah_sc);
  3428. if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
  3429. AH_TSF_WRITE_TIMEOUT))
  3430. DPRINTF(ah->ah_sc, ATH_DBG_RESET,
  3431. "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
  3432. REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
  3433. ath9k_ps_restore(ah->ah_sc);
  3434. }
  3435. void ath9k_hw_set_tsfadjust(struct ath_hw *ah, u32 setting)
  3436. {
  3437. if (setting)
  3438. ah->misc_mode |= AR_PCU_TX_ADD_TSF;
  3439. else
  3440. ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
  3441. }
  3442. bool ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
  3443. {
  3444. if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
  3445. DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad slot time %u\n", us);
  3446. ah->slottime = (u32) -1;
  3447. return false;
  3448. } else {
  3449. REG_WRITE(ah, AR_D_GBL_IFS_SLOT, ath9k_hw_mac_to_clks(ah, us));
  3450. ah->slottime = us;
  3451. return true;
  3452. }
  3453. }
  3454. void ath9k_hw_set11nmac2040(struct ath_hw *ah, enum ath9k_ht_macmode mode)
  3455. {
  3456. u32 macmode;
  3457. if (mode == ATH9K_HT_MACMODE_2040 &&
  3458. !ah->config.cwm_ignore_extcca)
  3459. macmode = AR_2040_JOINED_RX_CLEAR;
  3460. else
  3461. macmode = 0;
  3462. REG_WRITE(ah, AR_2040_MODE, macmode);
  3463. }
  3464. /* HW Generic timers configuration */
  3465. static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
  3466. {
  3467. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3468. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3469. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3470. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3471. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3472. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3473. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3474. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  3475. {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
  3476. {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
  3477. AR_NDP2_TIMER_MODE, 0x0002},
  3478. {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
  3479. AR_NDP2_TIMER_MODE, 0x0004},
  3480. {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
  3481. AR_NDP2_TIMER_MODE, 0x0008},
  3482. {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
  3483. AR_NDP2_TIMER_MODE, 0x0010},
  3484. {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
  3485. AR_NDP2_TIMER_MODE, 0x0020},
  3486. {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
  3487. AR_NDP2_TIMER_MODE, 0x0040},
  3488. {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
  3489. AR_NDP2_TIMER_MODE, 0x0080}
  3490. };
  3491. /* HW generic timer primitives */
  3492. /* compute and clear index of rightmost 1 */
  3493. static u32 rightmost_index(struct ath_gen_timer_table *timer_table, u32 *mask)
  3494. {
  3495. u32 b;
  3496. b = *mask;
  3497. b &= (0-b);
  3498. *mask &= ~b;
  3499. b *= debruijn32;
  3500. b >>= 27;
  3501. return timer_table->gen_timer_index[b];
  3502. }
  3503. u32 ath9k_hw_gettsf32(struct ath_hw *ah)
  3504. {
  3505. return REG_READ(ah, AR_TSF_L32);
  3506. }
  3507. struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
  3508. void (*trigger)(void *),
  3509. void (*overflow)(void *),
  3510. void *arg,
  3511. u8 timer_index)
  3512. {
  3513. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3514. struct ath_gen_timer *timer;
  3515. timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
  3516. if (timer == NULL) {
  3517. printk(KERN_DEBUG "Failed to allocate memory"
  3518. "for hw timer[%d]\n", timer_index);
  3519. return NULL;
  3520. }
  3521. /* allocate a hardware generic timer slot */
  3522. timer_table->timers[timer_index] = timer;
  3523. timer->index = timer_index;
  3524. timer->trigger = trigger;
  3525. timer->overflow = overflow;
  3526. timer->arg = arg;
  3527. return timer;
  3528. }
  3529. void ath_gen_timer_start(struct ath_hw *ah,
  3530. struct ath_gen_timer *timer,
  3531. u32 timer_next, u32 timer_period)
  3532. {
  3533. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3534. u32 tsf;
  3535. BUG_ON(!timer_period);
  3536. set_bit(timer->index, &timer_table->timer_mask.timer_bits);
  3537. tsf = ath9k_hw_gettsf32(ah);
  3538. DPRINTF(ah->ah_sc, ATH_DBG_HWTIMER, "curent tsf %x period %x"
  3539. "timer_next %x\n", tsf, timer_period, timer_next);
  3540. /*
  3541. * Pull timer_next forward if the current TSF already passed it
  3542. * because of software latency
  3543. */
  3544. if (timer_next < tsf)
  3545. timer_next = tsf + timer_period;
  3546. /*
  3547. * Program generic timer registers
  3548. */
  3549. REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
  3550. timer_next);
  3551. REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
  3552. timer_period);
  3553. REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  3554. gen_tmr_configuration[timer->index].mode_mask);
  3555. /* Enable both trigger and thresh interrupt masks */
  3556. REG_SET_BIT(ah, AR_IMR_S5,
  3557. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  3558. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  3559. if ((ah->ah_sc->imask & ATH9K_INT_GENTIMER) == 0) {
  3560. ath9k_hw_set_interrupts(ah, 0);
  3561. ah->ah_sc->imask |= ATH9K_INT_GENTIMER;
  3562. ath9k_hw_set_interrupts(ah, ah->ah_sc->imask);
  3563. }
  3564. }
  3565. void ath_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
  3566. {
  3567. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3568. if ((timer->index < AR_FIRST_NDP_TIMER) ||
  3569. (timer->index >= ATH_MAX_GEN_TIMER)) {
  3570. return;
  3571. }
  3572. /* Clear generic timer enable bits. */
  3573. REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  3574. gen_tmr_configuration[timer->index].mode_mask);
  3575. /* Disable both trigger and thresh interrupt masks */
  3576. REG_CLR_BIT(ah, AR_IMR_S5,
  3577. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  3578. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  3579. clear_bit(timer->index, &timer_table->timer_mask.timer_bits);
  3580. /* if no timer is enabled, turn off interrupt mask */
  3581. if (timer_table->timer_mask.val == 0) {
  3582. ath9k_hw_set_interrupts(ah, 0);
  3583. ah->ah_sc->imask &= ~ATH9K_INT_GENTIMER;
  3584. ath9k_hw_set_interrupts(ah, ah->ah_sc->imask);
  3585. }
  3586. }
  3587. void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
  3588. {
  3589. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3590. /* free the hardware generic timer slot */
  3591. timer_table->timers[timer->index] = NULL;
  3592. kfree(timer);
  3593. }
  3594. /*
  3595. * Generic Timer Interrupts handling
  3596. */
  3597. void ath_gen_timer_isr(struct ath_hw *ah)
  3598. {
  3599. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  3600. struct ath_gen_timer *timer;
  3601. u32 trigger_mask, thresh_mask, index;
  3602. /* get hardware generic timer interrupt status */
  3603. trigger_mask = ah->intr_gen_timer_trigger;
  3604. thresh_mask = ah->intr_gen_timer_thresh;
  3605. trigger_mask &= timer_table->timer_mask.val;
  3606. thresh_mask &= timer_table->timer_mask.val;
  3607. trigger_mask &= ~thresh_mask;
  3608. while (thresh_mask) {
  3609. index = rightmost_index(timer_table, &thresh_mask);
  3610. timer = timer_table->timers[index];
  3611. BUG_ON(!timer);
  3612. DPRINTF(ah->ah_sc, ATH_DBG_HWTIMER,
  3613. "TSF overflow for Gen timer %d\n", index);
  3614. timer->overflow(timer->arg);
  3615. }
  3616. while (trigger_mask) {
  3617. index = rightmost_index(timer_table, &trigger_mask);
  3618. timer = timer_table->timers[index];
  3619. BUG_ON(!timer);
  3620. DPRINTF(ah->ah_sc, ATH_DBG_HWTIMER,
  3621. "Gen timer[%d] trigger\n", index);
  3622. timer->trigger(timer->arg);
  3623. }
  3624. }
  3625. /*
  3626. * Primitive to disable ASPM
  3627. */
  3628. void ath_pcie_aspm_disable(struct ath_softc *sc)
  3629. {
  3630. struct pci_dev *pdev = to_pci_dev(sc->dev);
  3631. u8 aspm;
  3632. pci_read_config_byte(pdev, ATH_PCIE_CAP_LINK_CTRL, &aspm);
  3633. aspm &= ~(ATH_PCIE_CAP_LINK_L0S | ATH_PCIE_CAP_LINK_L1);
  3634. pci_write_config_byte(pdev, ATH_PCIE_CAP_LINK_CTRL, aspm);
  3635. }