hw.c 104 KB

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