hw.c 106 KB

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