hw.c 106 KB

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