hw.c 100 KB

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