hw.c 95 KB

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