hw.c 103 KB

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