hw.c 102 KB

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