hw.c 100 KB

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