hw.c 102 KB

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