hw.c 105 KB

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