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