hw.c 102 KB

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