hw.c 104 KB

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