hw.c 100 KB

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