hw.c 104 KB

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