hw.c 95 KB

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