hw.c 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192
  1. /*
  2. * Copyright (c) 2008-2011 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 <linux/slab.h>
  18. #include <linux/module.h>
  19. #include <linux/time.h>
  20. #include <linux/bitops.h>
  21. #include <linux/etherdevice.h>
  22. #include <asm/unaligned.h>
  23. #include "hw.h"
  24. #include "hw-ops.h"
  25. #include "ar9003_mac.h"
  26. #include "ar9003_mci.h"
  27. #include "ar9003_phy.h"
  28. #include "ath9k.h"
  29. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
  30. MODULE_AUTHOR("Atheros Communications");
  31. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  32. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  33. MODULE_LICENSE("Dual BSD/GPL");
  34. static void ath9k_hw_set_clockrate(struct ath_hw *ah)
  35. {
  36. struct ath_common *common = ath9k_hw_common(ah);
  37. struct ath9k_channel *chan = ah->curchan;
  38. unsigned int clockrate;
  39. /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
  40. if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
  41. clockrate = 117;
  42. else if (!chan) /* should really check for CCK instead */
  43. clockrate = ATH9K_CLOCK_RATE_CCK;
  44. else if (IS_CHAN_2GHZ(chan))
  45. clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
  46. else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
  47. clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
  48. else
  49. clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
  50. if (chan) {
  51. if (IS_CHAN_HT40(chan))
  52. clockrate *= 2;
  53. if (IS_CHAN_HALF_RATE(chan))
  54. clockrate /= 2;
  55. if (IS_CHAN_QUARTER_RATE(chan))
  56. clockrate /= 4;
  57. }
  58. common->clockrate = clockrate;
  59. }
  60. static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
  61. {
  62. struct ath_common *common = ath9k_hw_common(ah);
  63. return usecs * common->clockrate;
  64. }
  65. bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
  66. {
  67. int i;
  68. BUG_ON(timeout < AH_TIME_QUANTUM);
  69. for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
  70. if ((REG_READ(ah, reg) & mask) == val)
  71. return true;
  72. udelay(AH_TIME_QUANTUM);
  73. }
  74. ath_dbg(ath9k_hw_common(ah), ANY,
  75. "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
  76. timeout, reg, REG_READ(ah, reg), mask, val);
  77. return false;
  78. }
  79. EXPORT_SYMBOL(ath9k_hw_wait);
  80. void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
  81. int hw_delay)
  82. {
  83. hw_delay /= 10;
  84. if (IS_CHAN_HALF_RATE(chan))
  85. hw_delay *= 2;
  86. else if (IS_CHAN_QUARTER_RATE(chan))
  87. hw_delay *= 4;
  88. udelay(hw_delay + BASE_ACTIVATE_DELAY);
  89. }
  90. void ath9k_hw_write_array(struct ath_hw *ah, const struct ar5416IniArray *array,
  91. int column, unsigned int *writecnt)
  92. {
  93. int r;
  94. ENABLE_REGWRITE_BUFFER(ah);
  95. for (r = 0; r < array->ia_rows; r++) {
  96. REG_WRITE(ah, INI_RA(array, r, 0),
  97. INI_RA(array, r, column));
  98. DO_DELAY(*writecnt);
  99. }
  100. REGWRITE_BUFFER_FLUSH(ah);
  101. }
  102. u32 ath9k_hw_reverse_bits(u32 val, u32 n)
  103. {
  104. u32 retval;
  105. int i;
  106. for (i = 0, retval = 0; i < n; i++) {
  107. retval = (retval << 1) | (val & 1);
  108. val >>= 1;
  109. }
  110. return retval;
  111. }
  112. u16 ath9k_hw_computetxtime(struct ath_hw *ah,
  113. u8 phy, int kbps,
  114. u32 frameLen, u16 rateix,
  115. bool shortPreamble)
  116. {
  117. u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
  118. if (kbps == 0)
  119. return 0;
  120. switch (phy) {
  121. case WLAN_RC_PHY_CCK:
  122. phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
  123. if (shortPreamble)
  124. phyTime >>= 1;
  125. numBits = frameLen << 3;
  126. txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
  127. break;
  128. case WLAN_RC_PHY_OFDM:
  129. if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
  130. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
  131. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  132. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  133. txTime = OFDM_SIFS_TIME_QUARTER
  134. + OFDM_PREAMBLE_TIME_QUARTER
  135. + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
  136. } else if (ah->curchan &&
  137. IS_CHAN_HALF_RATE(ah->curchan)) {
  138. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
  139. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  140. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  141. txTime = OFDM_SIFS_TIME_HALF +
  142. OFDM_PREAMBLE_TIME_HALF
  143. + (numSymbols * OFDM_SYMBOL_TIME_HALF);
  144. } else {
  145. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
  146. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  147. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  148. txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
  149. + (numSymbols * OFDM_SYMBOL_TIME);
  150. }
  151. break;
  152. default:
  153. ath_err(ath9k_hw_common(ah),
  154. "Unknown phy %u (rate ix %u)\n", phy, rateix);
  155. txTime = 0;
  156. break;
  157. }
  158. return txTime;
  159. }
  160. EXPORT_SYMBOL(ath9k_hw_computetxtime);
  161. void ath9k_hw_get_channel_centers(struct ath_hw *ah,
  162. struct ath9k_channel *chan,
  163. struct chan_centers *centers)
  164. {
  165. int8_t extoff;
  166. if (!IS_CHAN_HT40(chan)) {
  167. centers->ctl_center = centers->ext_center =
  168. centers->synth_center = chan->channel;
  169. return;
  170. }
  171. if (IS_CHAN_HT40PLUS(chan)) {
  172. centers->synth_center =
  173. chan->channel + HT40_CHANNEL_CENTER_SHIFT;
  174. extoff = 1;
  175. } else {
  176. centers->synth_center =
  177. chan->channel - HT40_CHANNEL_CENTER_SHIFT;
  178. extoff = -1;
  179. }
  180. centers->ctl_center =
  181. centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
  182. /* 25 MHz spacing is supported by hw but not on upper layers */
  183. centers->ext_center =
  184. centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
  185. }
  186. /******************/
  187. /* Chip Revisions */
  188. /******************/
  189. static void ath9k_hw_read_revisions(struct ath_hw *ah)
  190. {
  191. u32 val;
  192. if (ah->get_mac_revision)
  193. ah->hw_version.macRev = ah->get_mac_revision();
  194. switch (ah->hw_version.devid) {
  195. case AR5416_AR9100_DEVID:
  196. ah->hw_version.macVersion = AR_SREV_VERSION_9100;
  197. break;
  198. case AR9300_DEVID_AR9330:
  199. ah->hw_version.macVersion = AR_SREV_VERSION_9330;
  200. if (!ah->get_mac_revision) {
  201. val = REG_READ(ah, AR_SREV);
  202. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  203. }
  204. return;
  205. case AR9300_DEVID_AR9340:
  206. ah->hw_version.macVersion = AR_SREV_VERSION_9340;
  207. return;
  208. case AR9300_DEVID_QCA955X:
  209. ah->hw_version.macVersion = AR_SREV_VERSION_9550;
  210. return;
  211. case AR9300_DEVID_AR953X:
  212. ah->hw_version.macVersion = AR_SREV_VERSION_9531;
  213. return;
  214. }
  215. val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
  216. if (val == 0xFF) {
  217. val = REG_READ(ah, AR_SREV);
  218. ah->hw_version.macVersion =
  219. (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
  220. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  221. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  222. ah->is_pciexpress = true;
  223. else
  224. ah->is_pciexpress = (val &
  225. AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
  226. } else {
  227. if (!AR_SREV_9100(ah))
  228. ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
  229. ah->hw_version.macRev = val & AR_SREV_REVISION;
  230. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
  231. ah->is_pciexpress = true;
  232. }
  233. }
  234. /************************************/
  235. /* HW Attach, Detach, Init Routines */
  236. /************************************/
  237. static void ath9k_hw_disablepcie(struct ath_hw *ah)
  238. {
  239. if (!AR_SREV_5416(ah))
  240. return;
  241. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  242. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  243. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
  244. REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
  245. REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
  246. REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
  247. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  248. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  249. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
  250. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  251. }
  252. /* This should work for all families including legacy */
  253. static bool ath9k_hw_chip_test(struct ath_hw *ah)
  254. {
  255. struct ath_common *common = ath9k_hw_common(ah);
  256. u32 regAddr[2] = { AR_STA_ID0 };
  257. u32 regHold[2];
  258. static const u32 patternData[4] = {
  259. 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
  260. };
  261. int i, j, loop_max;
  262. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  263. loop_max = 2;
  264. regAddr[1] = AR_PHY_BASE + (8 << 2);
  265. } else
  266. loop_max = 1;
  267. for (i = 0; i < loop_max; i++) {
  268. u32 addr = regAddr[i];
  269. u32 wrData, rdData;
  270. regHold[i] = REG_READ(ah, addr);
  271. for (j = 0; j < 0x100; j++) {
  272. wrData = (j << 16) | j;
  273. REG_WRITE(ah, addr, wrData);
  274. rdData = REG_READ(ah, addr);
  275. if (rdData != wrData) {
  276. ath_err(common,
  277. "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  278. addr, wrData, rdData);
  279. return false;
  280. }
  281. }
  282. for (j = 0; j < 4; j++) {
  283. wrData = patternData[j];
  284. REG_WRITE(ah, addr, wrData);
  285. rdData = REG_READ(ah, addr);
  286. if (wrData != rdData) {
  287. ath_err(common,
  288. "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  289. addr, wrData, rdData);
  290. return false;
  291. }
  292. }
  293. REG_WRITE(ah, regAddr[i], regHold[i]);
  294. }
  295. udelay(100);
  296. return true;
  297. }
  298. static void ath9k_hw_init_config(struct ath_hw *ah)
  299. {
  300. struct ath_common *common = ath9k_hw_common(ah);
  301. ah->config.dma_beacon_response_time = 1;
  302. ah->config.sw_beacon_response_time = 6;
  303. ah->config.cwm_ignore_extcca = 0;
  304. ah->config.analog_shiftreg = 1;
  305. ah->config.rx_intr_mitigation = true;
  306. if (AR_SREV_9300_20_OR_LATER(ah)) {
  307. ah->config.rimt_last = 500;
  308. ah->config.rimt_first = 2000;
  309. } else {
  310. ah->config.rimt_last = 250;
  311. ah->config.rimt_first = 700;
  312. }
  313. /*
  314. * We need this for PCI devices only (Cardbus, PCI, miniPCI)
  315. * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
  316. * This means we use it for all AR5416 devices, and the few
  317. * minor PCI AR9280 devices out there.
  318. *
  319. * Serialization is required because these devices do not handle
  320. * well the case of two concurrent reads/writes due to the latency
  321. * involved. During one read/write another read/write can be issued
  322. * on another CPU while the previous read/write may still be working
  323. * on our hardware, if we hit this case the hardware poops in a loop.
  324. * We prevent this by serializing reads and writes.
  325. *
  326. * This issue is not present on PCI-Express devices or pre-AR5416
  327. * devices (legacy, 802.11abg).
  328. */
  329. if (num_possible_cpus() > 1)
  330. ah->config.serialize_regmode = SER_REG_MODE_AUTO;
  331. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
  332. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
  333. ((AR_SREV_9160(ah) || AR_SREV_9280(ah) || AR_SREV_9287(ah)) &&
  334. !ah->is_pciexpress)) {
  335. ah->config.serialize_regmode = SER_REG_MODE_ON;
  336. } else {
  337. ah->config.serialize_regmode = SER_REG_MODE_OFF;
  338. }
  339. }
  340. ath_dbg(common, RESET, "serialize_regmode is %d\n",
  341. ah->config.serialize_regmode);
  342. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  343. ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
  344. else
  345. ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
  346. }
  347. static void ath9k_hw_init_defaults(struct ath_hw *ah)
  348. {
  349. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  350. regulatory->country_code = CTRY_DEFAULT;
  351. regulatory->power_limit = MAX_RATE_POWER;
  352. ah->hw_version.magic = AR5416_MAGIC;
  353. ah->hw_version.subvendorid = 0;
  354. ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE |
  355. AR_STA_ID1_MCAST_KSRCH;
  356. if (AR_SREV_9100(ah))
  357. ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
  358. ah->slottime = ATH9K_SLOT_TIME_9;
  359. ah->globaltxtimeout = (u32) -1;
  360. ah->power_mode = ATH9K_PM_UNDEFINED;
  361. ah->htc_reset_init = true;
  362. /* ar9002 does not support TPC for the moment */
  363. ah->tpc_enabled = !!AR_SREV_9300_20_OR_LATER(ah);
  364. ah->ani_function = ATH9K_ANI_ALL;
  365. if (!AR_SREV_9300_20_OR_LATER(ah))
  366. ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
  367. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  368. ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
  369. else
  370. ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
  371. }
  372. static int ath9k_hw_init_macaddr(struct ath_hw *ah)
  373. {
  374. struct ath_common *common = ath9k_hw_common(ah);
  375. u32 sum;
  376. int i;
  377. u16 eeval;
  378. static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
  379. sum = 0;
  380. for (i = 0; i < 3; i++) {
  381. eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
  382. sum += eeval;
  383. common->macaddr[2 * i] = eeval >> 8;
  384. common->macaddr[2 * i + 1] = eeval & 0xff;
  385. }
  386. if (!is_valid_ether_addr(common->macaddr)) {
  387. ath_err(common,
  388. "eeprom contains invalid mac address: %pM\n",
  389. common->macaddr);
  390. random_ether_addr(common->macaddr);
  391. ath_err(common,
  392. "random mac address will be used: %pM\n",
  393. common->macaddr);
  394. }
  395. return 0;
  396. }
  397. static int ath9k_hw_post_init(struct ath_hw *ah)
  398. {
  399. struct ath_common *common = ath9k_hw_common(ah);
  400. int ecode;
  401. if (common->bus_ops->ath_bus_type != ATH_USB) {
  402. if (!ath9k_hw_chip_test(ah))
  403. return -ENODEV;
  404. }
  405. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  406. ecode = ar9002_hw_rf_claim(ah);
  407. if (ecode != 0)
  408. return ecode;
  409. }
  410. ecode = ath9k_hw_eeprom_init(ah);
  411. if (ecode != 0)
  412. return ecode;
  413. ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
  414. ah->eep_ops->get_eeprom_ver(ah),
  415. ah->eep_ops->get_eeprom_rev(ah));
  416. ath9k_hw_ani_init(ah);
  417. /*
  418. * EEPROM needs to be initialized before we do this.
  419. * This is required for regulatory compliance.
  420. */
  421. if (AR_SREV_9300_20_OR_LATER(ah)) {
  422. u16 regdmn = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
  423. if ((regdmn & 0xF0) == CTL_FCC) {
  424. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_2GHZ;
  425. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_5GHZ;
  426. }
  427. }
  428. return 0;
  429. }
  430. static int ath9k_hw_attach_ops(struct ath_hw *ah)
  431. {
  432. if (!AR_SREV_9300_20_OR_LATER(ah))
  433. return ar9002_hw_attach_ops(ah);
  434. ar9003_hw_attach_ops(ah);
  435. return 0;
  436. }
  437. /* Called for all hardware families */
  438. static int __ath9k_hw_init(struct ath_hw *ah)
  439. {
  440. struct ath_common *common = ath9k_hw_common(ah);
  441. int r = 0;
  442. ath9k_hw_read_revisions(ah);
  443. switch (ah->hw_version.macVersion) {
  444. case AR_SREV_VERSION_5416_PCI:
  445. case AR_SREV_VERSION_5416_PCIE:
  446. case AR_SREV_VERSION_9160:
  447. case AR_SREV_VERSION_9100:
  448. case AR_SREV_VERSION_9280:
  449. case AR_SREV_VERSION_9285:
  450. case AR_SREV_VERSION_9287:
  451. case AR_SREV_VERSION_9271:
  452. case AR_SREV_VERSION_9300:
  453. case AR_SREV_VERSION_9330:
  454. case AR_SREV_VERSION_9485:
  455. case AR_SREV_VERSION_9340:
  456. case AR_SREV_VERSION_9462:
  457. case AR_SREV_VERSION_9550:
  458. case AR_SREV_VERSION_9565:
  459. case AR_SREV_VERSION_9531:
  460. break;
  461. default:
  462. ath_err(common,
  463. "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
  464. ah->hw_version.macVersion, ah->hw_version.macRev);
  465. return -EOPNOTSUPP;
  466. }
  467. /*
  468. * Read back AR_WA into a permanent copy and set bits 14 and 17.
  469. * We need to do this to avoid RMW of this register. We cannot
  470. * read the reg when chip is asleep.
  471. */
  472. if (AR_SREV_9300_20_OR_LATER(ah)) {
  473. ah->WARegVal = REG_READ(ah, AR_WA);
  474. ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
  475. AR_WA_ASPM_TIMER_BASED_DISABLE);
  476. }
  477. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  478. ath_err(common, "Couldn't reset chip\n");
  479. return -EIO;
  480. }
  481. if (AR_SREV_9565(ah)) {
  482. ah->WARegVal |= AR_WA_BIT22;
  483. REG_WRITE(ah, AR_WA, ah->WARegVal);
  484. }
  485. ath9k_hw_init_defaults(ah);
  486. ath9k_hw_init_config(ah);
  487. r = ath9k_hw_attach_ops(ah);
  488. if (r)
  489. return r;
  490. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
  491. ath_err(common, "Couldn't wakeup chip\n");
  492. return -EIO;
  493. }
  494. if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
  495. AR_SREV_9330(ah) || AR_SREV_9550(ah))
  496. ah->is_pciexpress = false;
  497. ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
  498. ath9k_hw_init_cal_settings(ah);
  499. if (!ah->is_pciexpress)
  500. ath9k_hw_disablepcie(ah);
  501. r = ath9k_hw_post_init(ah);
  502. if (r)
  503. return r;
  504. ath9k_hw_init_mode_gain_regs(ah);
  505. r = ath9k_hw_fill_cap_info(ah);
  506. if (r)
  507. return r;
  508. r = ath9k_hw_init_macaddr(ah);
  509. if (r) {
  510. ath_err(common, "Failed to initialize MAC address\n");
  511. return r;
  512. }
  513. ath9k_hw_init_hang_checks(ah);
  514. common->state = ATH_HW_INITIALIZED;
  515. return 0;
  516. }
  517. int ath9k_hw_init(struct ath_hw *ah)
  518. {
  519. int ret;
  520. struct ath_common *common = ath9k_hw_common(ah);
  521. /* These are all the AR5008/AR9001/AR9002/AR9003 hardware family of chipsets */
  522. switch (ah->hw_version.devid) {
  523. case AR5416_DEVID_PCI:
  524. case AR5416_DEVID_PCIE:
  525. case AR5416_AR9100_DEVID:
  526. case AR9160_DEVID_PCI:
  527. case AR9280_DEVID_PCI:
  528. case AR9280_DEVID_PCIE:
  529. case AR9285_DEVID_PCIE:
  530. case AR9287_DEVID_PCI:
  531. case AR9287_DEVID_PCIE:
  532. case AR2427_DEVID_PCIE:
  533. case AR9300_DEVID_PCIE:
  534. case AR9300_DEVID_AR9485_PCIE:
  535. case AR9300_DEVID_AR9330:
  536. case AR9300_DEVID_AR9340:
  537. case AR9300_DEVID_QCA955X:
  538. case AR9300_DEVID_AR9580:
  539. case AR9300_DEVID_AR9462:
  540. case AR9485_DEVID_AR1111:
  541. case AR9300_DEVID_AR9565:
  542. case AR9300_DEVID_AR953X:
  543. break;
  544. default:
  545. if (common->bus_ops->ath_bus_type == ATH_USB)
  546. break;
  547. ath_err(common, "Hardware device ID 0x%04x not supported\n",
  548. ah->hw_version.devid);
  549. return -EOPNOTSUPP;
  550. }
  551. ret = __ath9k_hw_init(ah);
  552. if (ret) {
  553. ath_err(common,
  554. "Unable to initialize hardware; initialization status: %d\n",
  555. ret);
  556. return ret;
  557. }
  558. ath_dynack_init(ah);
  559. return 0;
  560. }
  561. EXPORT_SYMBOL(ath9k_hw_init);
  562. static void ath9k_hw_init_qos(struct ath_hw *ah)
  563. {
  564. ENABLE_REGWRITE_BUFFER(ah);
  565. REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
  566. REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
  567. REG_WRITE(ah, AR_QOS_NO_ACK,
  568. SM(2, AR_QOS_NO_ACK_TWO_BIT) |
  569. SM(5, AR_QOS_NO_ACK_BIT_OFF) |
  570. SM(0, AR_QOS_NO_ACK_BYTE_OFF));
  571. REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
  572. REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
  573. REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
  574. REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
  575. REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
  576. REGWRITE_BUFFER_FLUSH(ah);
  577. }
  578. u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
  579. {
  580. struct ath_common *common = ath9k_hw_common(ah);
  581. int i = 0;
  582. REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
  583. udelay(100);
  584. REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
  585. while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) {
  586. udelay(100);
  587. if (WARN_ON_ONCE(i >= 100)) {
  588. ath_err(common, "PLL4 meaurement not done\n");
  589. break;
  590. }
  591. i++;
  592. }
  593. return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
  594. }
  595. EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
  596. static void ath9k_hw_init_pll(struct ath_hw *ah,
  597. struct ath9k_channel *chan)
  598. {
  599. u32 pll;
  600. pll = ath9k_hw_compute_pll_control(ah, chan);
  601. if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
  602. /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
  603. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  604. AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
  605. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  606. AR_CH0_DPLL2_KD, 0x40);
  607. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  608. AR_CH0_DPLL2_KI, 0x4);
  609. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  610. AR_CH0_BB_DPLL1_REFDIV, 0x5);
  611. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  612. AR_CH0_BB_DPLL1_NINI, 0x58);
  613. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  614. AR_CH0_BB_DPLL1_NFRAC, 0x0);
  615. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  616. AR_CH0_BB_DPLL2_OUTDIV, 0x1);
  617. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  618. AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
  619. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  620. AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
  621. /* program BB PLL phase_shift to 0x6 */
  622. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
  623. AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
  624. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  625. AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
  626. udelay(1000);
  627. } else if (AR_SREV_9330(ah)) {
  628. u32 ddr_dpll2, pll_control2, kd;
  629. if (ah->is_clk_25mhz) {
  630. ddr_dpll2 = 0x18e82f01;
  631. pll_control2 = 0xe04a3d;
  632. kd = 0x1d;
  633. } else {
  634. ddr_dpll2 = 0x19e82f01;
  635. pll_control2 = 0x886666;
  636. kd = 0x3d;
  637. }
  638. /* program DDR PLL ki and kd value */
  639. REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
  640. /* program DDR PLL phase_shift */
  641. REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
  642. AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
  643. REG_WRITE(ah, AR_RTC_PLL_CONTROL,
  644. pll | AR_RTC_9300_PLL_BYPASS);
  645. udelay(1000);
  646. /* program refdiv, nint, frac to RTC register */
  647. REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
  648. /* program BB PLL kd and ki value */
  649. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
  650. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
  651. /* program BB PLL phase_shift */
  652. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
  653. AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
  654. } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah)) {
  655. u32 regval, pll2_divint, pll2_divfrac, refdiv;
  656. REG_WRITE(ah, AR_RTC_PLL_CONTROL,
  657. pll | AR_RTC_9300_SOC_PLL_BYPASS);
  658. udelay(1000);
  659. REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
  660. udelay(100);
  661. if (ah->is_clk_25mhz) {
  662. if (AR_SREV_9531(ah)) {
  663. pll2_divint = 0x1c;
  664. pll2_divfrac = 0xa3d2;
  665. refdiv = 1;
  666. } else {
  667. pll2_divint = 0x54;
  668. pll2_divfrac = 0x1eb85;
  669. refdiv = 3;
  670. }
  671. } else {
  672. if (AR_SREV_9340(ah)) {
  673. pll2_divint = 88;
  674. pll2_divfrac = 0;
  675. refdiv = 5;
  676. } else {
  677. pll2_divint = 0x11;
  678. pll2_divfrac =
  679. AR_SREV_9531(ah) ? 0x26665 : 0x26666;
  680. refdiv = 1;
  681. }
  682. }
  683. regval = REG_READ(ah, AR_PHY_PLL_MODE);
  684. if (AR_SREV_9531(ah))
  685. regval |= (0x1 << 22);
  686. else
  687. regval |= (0x1 << 16);
  688. REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
  689. udelay(100);
  690. REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
  691. (pll2_divint << 18) | pll2_divfrac);
  692. udelay(100);
  693. regval = REG_READ(ah, AR_PHY_PLL_MODE);
  694. if (AR_SREV_9340(ah))
  695. regval = (regval & 0x80071fff) |
  696. (0x1 << 30) |
  697. (0x1 << 13) |
  698. (0x4 << 26) |
  699. (0x18 << 19);
  700. else if (AR_SREV_9531(ah))
  701. regval = (regval & 0x01c00fff) |
  702. (0x1 << 31) |
  703. (0x2 << 29) |
  704. (0xa << 25) |
  705. (0x1 << 19) |
  706. (0x6 << 12);
  707. else
  708. regval = (regval & 0x80071fff) |
  709. (0x3 << 30) |
  710. (0x1 << 13) |
  711. (0x4 << 26) |
  712. (0x60 << 19);
  713. REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
  714. if (AR_SREV_9531(ah))
  715. REG_WRITE(ah, AR_PHY_PLL_MODE,
  716. REG_READ(ah, AR_PHY_PLL_MODE) & 0xffbfffff);
  717. else
  718. REG_WRITE(ah, AR_PHY_PLL_MODE,
  719. REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
  720. udelay(1000);
  721. }
  722. if (AR_SREV_9565(ah))
  723. pll |= 0x40000;
  724. REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
  725. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
  726. AR_SREV_9550(ah))
  727. udelay(1000);
  728. /* Switch the core clock for ar9271 to 117Mhz */
  729. if (AR_SREV_9271(ah)) {
  730. udelay(500);
  731. REG_WRITE(ah, 0x50040, 0x304);
  732. }
  733. udelay(RTC_PLL_SETTLE_DELAY);
  734. REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
  735. }
  736. static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
  737. enum nl80211_iftype opmode)
  738. {
  739. u32 sync_default = AR_INTR_SYNC_DEFAULT;
  740. u32 imr_reg = AR_IMR_TXERR |
  741. AR_IMR_TXURN |
  742. AR_IMR_RXERR |
  743. AR_IMR_RXORN |
  744. AR_IMR_BCNMISC;
  745. if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah))
  746. sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
  747. if (AR_SREV_9300_20_OR_LATER(ah)) {
  748. imr_reg |= AR_IMR_RXOK_HP;
  749. if (ah->config.rx_intr_mitigation)
  750. imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  751. else
  752. imr_reg |= AR_IMR_RXOK_LP;
  753. } else {
  754. if (ah->config.rx_intr_mitigation)
  755. imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  756. else
  757. imr_reg |= AR_IMR_RXOK;
  758. }
  759. if (ah->config.tx_intr_mitigation)
  760. imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
  761. else
  762. imr_reg |= AR_IMR_TXOK;
  763. ENABLE_REGWRITE_BUFFER(ah);
  764. REG_WRITE(ah, AR_IMR, imr_reg);
  765. ah->imrs2_reg |= AR_IMR_S2_GTT;
  766. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  767. if (!AR_SREV_9100(ah)) {
  768. REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
  769. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
  770. REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
  771. }
  772. REGWRITE_BUFFER_FLUSH(ah);
  773. if (AR_SREV_9300_20_OR_LATER(ah)) {
  774. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
  775. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
  776. REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
  777. REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
  778. }
  779. }
  780. static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
  781. {
  782. u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
  783. val = min(val, (u32) 0xFFFF);
  784. REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
  785. }
  786. void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
  787. {
  788. u32 val = ath9k_hw_mac_to_clks(ah, us);
  789. val = min(val, (u32) 0xFFFF);
  790. REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
  791. }
  792. void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
  793. {
  794. u32 val = ath9k_hw_mac_to_clks(ah, us);
  795. val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
  796. REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
  797. }
  798. void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
  799. {
  800. u32 val = ath9k_hw_mac_to_clks(ah, us);
  801. val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
  802. REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
  803. }
  804. static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
  805. {
  806. if (tu > 0xFFFF) {
  807. ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
  808. tu);
  809. ah->globaltxtimeout = (u32) -1;
  810. return false;
  811. } else {
  812. REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
  813. ah->globaltxtimeout = tu;
  814. return true;
  815. }
  816. }
  817. void ath9k_hw_init_global_settings(struct ath_hw *ah)
  818. {
  819. struct ath_common *common = ath9k_hw_common(ah);
  820. const struct ath9k_channel *chan = ah->curchan;
  821. int acktimeout, ctstimeout, ack_offset = 0;
  822. int slottime;
  823. int sifstime;
  824. int rx_lat = 0, tx_lat = 0, eifs = 0;
  825. u32 reg;
  826. ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
  827. ah->misc_mode);
  828. if (!chan)
  829. return;
  830. if (ah->misc_mode != 0)
  831. REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
  832. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  833. rx_lat = 41;
  834. else
  835. rx_lat = 37;
  836. tx_lat = 54;
  837. if (IS_CHAN_5GHZ(chan))
  838. sifstime = 16;
  839. else
  840. sifstime = 10;
  841. if (IS_CHAN_HALF_RATE(chan)) {
  842. eifs = 175;
  843. rx_lat *= 2;
  844. tx_lat *= 2;
  845. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  846. tx_lat += 11;
  847. sifstime = 32;
  848. ack_offset = 16;
  849. slottime = 13;
  850. } else if (IS_CHAN_QUARTER_RATE(chan)) {
  851. eifs = 340;
  852. rx_lat = (rx_lat * 4) - 1;
  853. tx_lat *= 4;
  854. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  855. tx_lat += 22;
  856. sifstime = 64;
  857. ack_offset = 32;
  858. slottime = 21;
  859. } else {
  860. if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
  861. eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
  862. reg = AR_USEC_ASYNC_FIFO;
  863. } else {
  864. eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
  865. common->clockrate;
  866. reg = REG_READ(ah, AR_USEC);
  867. }
  868. rx_lat = MS(reg, AR_USEC_RX_LAT);
  869. tx_lat = MS(reg, AR_USEC_TX_LAT);
  870. slottime = ah->slottime;
  871. }
  872. /* As defined by IEEE 802.11-2007 17.3.8.6 */
  873. slottime += 3 * ah->coverage_class;
  874. acktimeout = slottime + sifstime + ack_offset;
  875. ctstimeout = acktimeout;
  876. /*
  877. * Workaround for early ACK timeouts, add an offset to match the
  878. * initval's 64us ack timeout value. Use 48us for the CTS timeout.
  879. * This was initially only meant to work around an issue with delayed
  880. * BA frames in some implementations, but it has been found to fix ACK
  881. * timeout issues in other cases as well.
  882. */
  883. if (IS_CHAN_2GHZ(chan) &&
  884. !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
  885. acktimeout += 64 - sifstime - ah->slottime;
  886. ctstimeout += 48 - sifstime - ah->slottime;
  887. }
  888. if (ah->dynack.enabled) {
  889. acktimeout = ah->dynack.ackto;
  890. ctstimeout = acktimeout;
  891. slottime = (acktimeout - 3) / 2;
  892. } else {
  893. ah->dynack.ackto = acktimeout;
  894. }
  895. ath9k_hw_set_sifs_time(ah, sifstime);
  896. ath9k_hw_setslottime(ah, slottime);
  897. ath9k_hw_set_ack_timeout(ah, acktimeout);
  898. ath9k_hw_set_cts_timeout(ah, ctstimeout);
  899. if (ah->globaltxtimeout != (u32) -1)
  900. ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
  901. REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
  902. REG_RMW(ah, AR_USEC,
  903. (common->clockrate - 1) |
  904. SM(rx_lat, AR_USEC_RX_LAT) |
  905. SM(tx_lat, AR_USEC_TX_LAT),
  906. AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
  907. }
  908. EXPORT_SYMBOL(ath9k_hw_init_global_settings);
  909. void ath9k_hw_deinit(struct ath_hw *ah)
  910. {
  911. struct ath_common *common = ath9k_hw_common(ah);
  912. if (common->state < ATH_HW_INITIALIZED)
  913. return;
  914. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  915. }
  916. EXPORT_SYMBOL(ath9k_hw_deinit);
  917. /*******/
  918. /* INI */
  919. /*******/
  920. u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
  921. {
  922. u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
  923. if (IS_CHAN_2GHZ(chan))
  924. ctl |= CTL_11G;
  925. else
  926. ctl |= CTL_11A;
  927. return ctl;
  928. }
  929. /****************************************/
  930. /* Reset and Channel Switching Routines */
  931. /****************************************/
  932. static inline void ath9k_hw_set_dma(struct ath_hw *ah)
  933. {
  934. struct ath_common *common = ath9k_hw_common(ah);
  935. int txbuf_size;
  936. ENABLE_REGWRITE_BUFFER(ah);
  937. /*
  938. * set AHB_MODE not to do cacheline prefetches
  939. */
  940. if (!AR_SREV_9300_20_OR_LATER(ah))
  941. REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
  942. /*
  943. * let mac dma reads be in 128 byte chunks
  944. */
  945. REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
  946. REGWRITE_BUFFER_FLUSH(ah);
  947. /*
  948. * Restore TX Trigger Level to its pre-reset value.
  949. * The initial value depends on whether aggregation is enabled, and is
  950. * adjusted whenever underruns are detected.
  951. */
  952. if (!AR_SREV_9300_20_OR_LATER(ah))
  953. REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
  954. ENABLE_REGWRITE_BUFFER(ah);
  955. /*
  956. * let mac dma writes be in 128 byte chunks
  957. */
  958. REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
  959. /*
  960. * Setup receive FIFO threshold to hold off TX activities
  961. */
  962. REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
  963. if (AR_SREV_9300_20_OR_LATER(ah)) {
  964. REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
  965. REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
  966. ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
  967. ah->caps.rx_status_len);
  968. }
  969. /*
  970. * reduce the number of usable entries in PCU TXBUF to avoid
  971. * wrap around issues.
  972. */
  973. if (AR_SREV_9285(ah)) {
  974. /* For AR9285 the number of Fifos are reduced to half.
  975. * So set the usable tx buf size also to half to
  976. * avoid data/delimiter underruns
  977. */
  978. txbuf_size = AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE;
  979. } else if (AR_SREV_9340_13_OR_LATER(ah)) {
  980. /* Uses fewer entries for AR934x v1.3+ to prevent rx overruns */
  981. txbuf_size = AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE;
  982. } else {
  983. txbuf_size = AR_PCU_TXBUF_CTRL_USABLE_SIZE;
  984. }
  985. if (!AR_SREV_9271(ah))
  986. REG_WRITE(ah, AR_PCU_TXBUF_CTRL, txbuf_size);
  987. REGWRITE_BUFFER_FLUSH(ah);
  988. if (AR_SREV_9300_20_OR_LATER(ah))
  989. ath9k_hw_reset_txstatus_ring(ah);
  990. }
  991. static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
  992. {
  993. u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
  994. u32 set = AR_STA_ID1_KSRCH_MODE;
  995. switch (opmode) {
  996. case NL80211_IFTYPE_ADHOC:
  997. if (!AR_SREV_9340_13(ah)) {
  998. set |= AR_STA_ID1_ADHOC;
  999. REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1000. break;
  1001. }
  1002. /* fall through */
  1003. case NL80211_IFTYPE_MESH_POINT:
  1004. case NL80211_IFTYPE_AP:
  1005. set |= AR_STA_ID1_STA_AP;
  1006. /* fall through */
  1007. case NL80211_IFTYPE_STATION:
  1008. REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  1009. break;
  1010. default:
  1011. if (!ah->is_monitoring)
  1012. set = 0;
  1013. break;
  1014. }
  1015. REG_RMW(ah, AR_STA_ID1, set, mask);
  1016. }
  1017. void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
  1018. u32 *coef_mantissa, u32 *coef_exponent)
  1019. {
  1020. u32 coef_exp, coef_man;
  1021. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  1022. if ((coef_scaled >> coef_exp) & 0x1)
  1023. break;
  1024. coef_exp = 14 - (coef_exp - COEF_SCALE_S);
  1025. coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
  1026. *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
  1027. *coef_exponent = coef_exp - 16;
  1028. }
  1029. /* AR9330 WAR:
  1030. * call external reset function to reset WMAC if:
  1031. * - doing a cold reset
  1032. * - we have pending frames in the TX queues.
  1033. */
  1034. static bool ath9k_hw_ar9330_reset_war(struct ath_hw *ah, int type)
  1035. {
  1036. int i, npend = 0;
  1037. for (i = 0; i < AR_NUM_QCU; i++) {
  1038. npend = ath9k_hw_numtxpending(ah, i);
  1039. if (npend)
  1040. break;
  1041. }
  1042. if (ah->external_reset &&
  1043. (npend || type == ATH9K_RESET_COLD)) {
  1044. int reset_err = 0;
  1045. ath_dbg(ath9k_hw_common(ah), RESET,
  1046. "reset MAC via external reset\n");
  1047. reset_err = ah->external_reset();
  1048. if (reset_err) {
  1049. ath_err(ath9k_hw_common(ah),
  1050. "External reset failed, err=%d\n",
  1051. reset_err);
  1052. return false;
  1053. }
  1054. REG_WRITE(ah, AR_RTC_RESET, 1);
  1055. }
  1056. return true;
  1057. }
  1058. static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
  1059. {
  1060. u32 rst_flags;
  1061. u32 tmpReg;
  1062. if (AR_SREV_9100(ah)) {
  1063. REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
  1064. AR_RTC_DERIVED_CLK_PERIOD, 1);
  1065. (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
  1066. }
  1067. ENABLE_REGWRITE_BUFFER(ah);
  1068. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1069. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1070. udelay(10);
  1071. }
  1072. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1073. AR_RTC_FORCE_WAKE_ON_INT);
  1074. if (AR_SREV_9100(ah)) {
  1075. rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
  1076. AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
  1077. } else {
  1078. tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  1079. if (AR_SREV_9340(ah))
  1080. tmpReg &= AR9340_INTR_SYNC_LOCAL_TIMEOUT;
  1081. else
  1082. tmpReg &= AR_INTR_SYNC_LOCAL_TIMEOUT |
  1083. AR_INTR_SYNC_RADM_CPL_TIMEOUT;
  1084. if (tmpReg) {
  1085. u32 val;
  1086. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  1087. val = AR_RC_HOSTIF;
  1088. if (!AR_SREV_9300_20_OR_LATER(ah))
  1089. val |= AR_RC_AHB;
  1090. REG_WRITE(ah, AR_RC, val);
  1091. } else if (!AR_SREV_9300_20_OR_LATER(ah))
  1092. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1093. rst_flags = AR_RTC_RC_MAC_WARM;
  1094. if (type == ATH9K_RESET_COLD)
  1095. rst_flags |= AR_RTC_RC_MAC_COLD;
  1096. }
  1097. if (AR_SREV_9330(ah)) {
  1098. if (!ath9k_hw_ar9330_reset_war(ah, type))
  1099. return false;
  1100. }
  1101. if (ath9k_hw_mci_is_enabled(ah))
  1102. ar9003_mci_check_gpm_offset(ah);
  1103. REG_WRITE(ah, AR_RTC_RC, rst_flags);
  1104. REGWRITE_BUFFER_FLUSH(ah);
  1105. if (AR_SREV_9300_20_OR_LATER(ah))
  1106. udelay(50);
  1107. else if (AR_SREV_9100(ah))
  1108. mdelay(10);
  1109. else
  1110. udelay(100);
  1111. REG_WRITE(ah, AR_RTC_RC, 0);
  1112. if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
  1113. ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
  1114. return false;
  1115. }
  1116. if (!AR_SREV_9100(ah))
  1117. REG_WRITE(ah, AR_RC, 0);
  1118. if (AR_SREV_9100(ah))
  1119. udelay(50);
  1120. return true;
  1121. }
  1122. static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
  1123. {
  1124. ENABLE_REGWRITE_BUFFER(ah);
  1125. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1126. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1127. udelay(10);
  1128. }
  1129. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  1130. AR_RTC_FORCE_WAKE_ON_INT);
  1131. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1132. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  1133. REG_WRITE(ah, AR_RTC_RESET, 0);
  1134. REGWRITE_BUFFER_FLUSH(ah);
  1135. udelay(2);
  1136. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1137. REG_WRITE(ah, AR_RC, 0);
  1138. REG_WRITE(ah, AR_RTC_RESET, 1);
  1139. if (!ath9k_hw_wait(ah,
  1140. AR_RTC_STATUS,
  1141. AR_RTC_STATUS_M,
  1142. AR_RTC_STATUS_ON,
  1143. AH_WAIT_TIMEOUT)) {
  1144. ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
  1145. return false;
  1146. }
  1147. return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
  1148. }
  1149. static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
  1150. {
  1151. bool ret = false;
  1152. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1153. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1154. udelay(10);
  1155. }
  1156. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1157. AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
  1158. if (!ah->reset_power_on)
  1159. type = ATH9K_RESET_POWER_ON;
  1160. switch (type) {
  1161. case ATH9K_RESET_POWER_ON:
  1162. ret = ath9k_hw_set_reset_power_on(ah);
  1163. if (ret)
  1164. ah->reset_power_on = true;
  1165. break;
  1166. case ATH9K_RESET_WARM:
  1167. case ATH9K_RESET_COLD:
  1168. ret = ath9k_hw_set_reset(ah, type);
  1169. break;
  1170. default:
  1171. break;
  1172. }
  1173. return ret;
  1174. }
  1175. static bool ath9k_hw_chip_reset(struct ath_hw *ah,
  1176. struct ath9k_channel *chan)
  1177. {
  1178. int reset_type = ATH9K_RESET_WARM;
  1179. if (AR_SREV_9280(ah)) {
  1180. if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
  1181. reset_type = ATH9K_RESET_POWER_ON;
  1182. else
  1183. reset_type = ATH9K_RESET_COLD;
  1184. } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
  1185. (REG_READ(ah, AR_CR) & AR_CR_RXE))
  1186. reset_type = ATH9K_RESET_COLD;
  1187. if (!ath9k_hw_set_reset_reg(ah, reset_type))
  1188. return false;
  1189. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1190. return false;
  1191. ah->chip_fullsleep = false;
  1192. if (AR_SREV_9330(ah))
  1193. ar9003_hw_internal_regulator_apply(ah);
  1194. ath9k_hw_init_pll(ah, chan);
  1195. return true;
  1196. }
  1197. static bool ath9k_hw_channel_change(struct ath_hw *ah,
  1198. struct ath9k_channel *chan)
  1199. {
  1200. struct ath_common *common = ath9k_hw_common(ah);
  1201. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1202. bool band_switch = false, mode_diff = false;
  1203. u8 ini_reloaded = 0;
  1204. u32 qnum;
  1205. int r;
  1206. if (pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) {
  1207. u32 flags_diff = chan->channelFlags ^ ah->curchan->channelFlags;
  1208. band_switch = !!(flags_diff & CHANNEL_5GHZ);
  1209. mode_diff = !!(flags_diff & ~CHANNEL_HT);
  1210. }
  1211. for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
  1212. if (ath9k_hw_numtxpending(ah, qnum)) {
  1213. ath_dbg(common, QUEUE,
  1214. "Transmit frames pending on queue %d\n", qnum);
  1215. return false;
  1216. }
  1217. }
  1218. if (!ath9k_hw_rfbus_req(ah)) {
  1219. ath_err(common, "Could not kill baseband RX\n");
  1220. return false;
  1221. }
  1222. if (band_switch || mode_diff) {
  1223. ath9k_hw_mark_phy_inactive(ah);
  1224. udelay(5);
  1225. if (band_switch)
  1226. ath9k_hw_init_pll(ah, chan);
  1227. if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
  1228. ath_err(common, "Failed to do fast channel change\n");
  1229. return false;
  1230. }
  1231. }
  1232. ath9k_hw_set_channel_regs(ah, chan);
  1233. r = ath9k_hw_rf_set_freq(ah, chan);
  1234. if (r) {
  1235. ath_err(common, "Failed to set channel\n");
  1236. return false;
  1237. }
  1238. ath9k_hw_set_clockrate(ah);
  1239. ath9k_hw_apply_txpower(ah, chan, false);
  1240. ath9k_hw_set_delta_slope(ah, chan);
  1241. ath9k_hw_spur_mitigate_freq(ah, chan);
  1242. if (band_switch || ini_reloaded)
  1243. ah->eep_ops->set_board_values(ah, chan);
  1244. ath9k_hw_init_bb(ah, chan);
  1245. ath9k_hw_rfbus_done(ah);
  1246. if (band_switch || ini_reloaded) {
  1247. ah->ah_flags |= AH_FASTCC;
  1248. ath9k_hw_init_cal(ah, chan);
  1249. ah->ah_flags &= ~AH_FASTCC;
  1250. }
  1251. return true;
  1252. }
  1253. static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
  1254. {
  1255. u32 gpio_mask = ah->gpio_mask;
  1256. int i;
  1257. for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
  1258. if (!(gpio_mask & 1))
  1259. continue;
  1260. ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  1261. ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
  1262. }
  1263. }
  1264. void ath9k_hw_check_nav(struct ath_hw *ah)
  1265. {
  1266. struct ath_common *common = ath9k_hw_common(ah);
  1267. u32 val;
  1268. val = REG_READ(ah, AR_NAV);
  1269. if (val != 0xdeadbeef && val > 0x7fff) {
  1270. ath_dbg(common, BSTUCK, "Abnormal NAV: 0x%x\n", val);
  1271. REG_WRITE(ah, AR_NAV, 0);
  1272. }
  1273. }
  1274. EXPORT_SYMBOL(ath9k_hw_check_nav);
  1275. bool ath9k_hw_check_alive(struct ath_hw *ah)
  1276. {
  1277. int count = 50;
  1278. u32 reg, last_val;
  1279. if (AR_SREV_9300(ah))
  1280. return !ath9k_hw_detect_mac_hang(ah);
  1281. if (AR_SREV_9285_12_OR_LATER(ah))
  1282. return true;
  1283. last_val = REG_READ(ah, AR_OBS_BUS_1);
  1284. do {
  1285. reg = REG_READ(ah, AR_OBS_BUS_1);
  1286. if (reg != last_val)
  1287. return true;
  1288. udelay(1);
  1289. last_val = reg;
  1290. if ((reg & 0x7E7FFFEF) == 0x00702400)
  1291. continue;
  1292. switch (reg & 0x7E000B00) {
  1293. case 0x1E000000:
  1294. case 0x52000B00:
  1295. case 0x18000B00:
  1296. continue;
  1297. default:
  1298. return true;
  1299. }
  1300. } while (count-- > 0);
  1301. return false;
  1302. }
  1303. EXPORT_SYMBOL(ath9k_hw_check_alive);
  1304. static void ath9k_hw_init_mfp(struct ath_hw *ah)
  1305. {
  1306. /* Setup MFP options for CCMP */
  1307. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1308. /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
  1309. * frames when constructing CCMP AAD. */
  1310. REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
  1311. 0xc7ff);
  1312. if (AR_SREV_9271(ah) || AR_DEVID_7010(ah))
  1313. ah->sw_mgmt_crypto_tx = true;
  1314. else
  1315. ah->sw_mgmt_crypto_tx = false;
  1316. ah->sw_mgmt_crypto_rx = false;
  1317. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  1318. /* Disable hardware crypto for management frames */
  1319. REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
  1320. AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
  1321. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  1322. AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
  1323. ah->sw_mgmt_crypto_tx = true;
  1324. ah->sw_mgmt_crypto_rx = true;
  1325. } else {
  1326. ah->sw_mgmt_crypto_tx = true;
  1327. ah->sw_mgmt_crypto_rx = true;
  1328. }
  1329. }
  1330. static void ath9k_hw_reset_opmode(struct ath_hw *ah,
  1331. u32 macStaId1, u32 saveDefAntenna)
  1332. {
  1333. struct ath_common *common = ath9k_hw_common(ah);
  1334. ENABLE_REGWRITE_BUFFER(ah);
  1335. REG_RMW(ah, AR_STA_ID1, macStaId1
  1336. | AR_STA_ID1_RTS_USE_DEF
  1337. | ah->sta_id1_defaults,
  1338. ~AR_STA_ID1_SADH_MASK);
  1339. ath_hw_setbssidmask(common);
  1340. REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
  1341. ath9k_hw_write_associd(ah);
  1342. REG_WRITE(ah, AR_ISR, ~0);
  1343. REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
  1344. REGWRITE_BUFFER_FLUSH(ah);
  1345. ath9k_hw_set_operating_mode(ah, ah->opmode);
  1346. }
  1347. static void ath9k_hw_init_queues(struct ath_hw *ah)
  1348. {
  1349. int i;
  1350. ENABLE_REGWRITE_BUFFER(ah);
  1351. for (i = 0; i < AR_NUM_DCU; i++)
  1352. REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
  1353. REGWRITE_BUFFER_FLUSH(ah);
  1354. ah->intr_txqs = 0;
  1355. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1356. ath9k_hw_resettxqueue(ah, i);
  1357. }
  1358. /*
  1359. * For big endian systems turn on swapping for descriptors
  1360. */
  1361. static void ath9k_hw_init_desc(struct ath_hw *ah)
  1362. {
  1363. struct ath_common *common = ath9k_hw_common(ah);
  1364. if (AR_SREV_9100(ah)) {
  1365. u32 mask;
  1366. mask = REG_READ(ah, AR_CFG);
  1367. if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
  1368. ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
  1369. mask);
  1370. } else {
  1371. mask = INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
  1372. REG_WRITE(ah, AR_CFG, mask);
  1373. ath_dbg(common, RESET, "Setting CFG 0x%x\n",
  1374. REG_READ(ah, AR_CFG));
  1375. }
  1376. } else {
  1377. if (common->bus_ops->ath_bus_type == ATH_USB) {
  1378. /* Configure AR9271 target WLAN */
  1379. if (AR_SREV_9271(ah))
  1380. REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
  1381. else
  1382. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  1383. }
  1384. #ifdef __BIG_ENDIAN
  1385. else if (AR_SREV_9330(ah) || AR_SREV_9340(ah) ||
  1386. AR_SREV_9550(ah) || AR_SREV_9531(ah))
  1387. REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
  1388. else
  1389. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  1390. #endif
  1391. }
  1392. }
  1393. /*
  1394. * Fast channel change:
  1395. * (Change synthesizer based on channel freq without resetting chip)
  1396. */
  1397. static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
  1398. {
  1399. struct ath_common *common = ath9k_hw_common(ah);
  1400. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1401. int ret;
  1402. if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
  1403. goto fail;
  1404. if (ah->chip_fullsleep)
  1405. goto fail;
  1406. if (!ah->curchan)
  1407. goto fail;
  1408. if (chan->channel == ah->curchan->channel)
  1409. goto fail;
  1410. if ((ah->curchan->channelFlags | chan->channelFlags) &
  1411. (CHANNEL_HALF | CHANNEL_QUARTER))
  1412. goto fail;
  1413. /*
  1414. * If cross-band fcc is not supoprted, bail out if channelFlags differ.
  1415. */
  1416. if (!(pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) &&
  1417. ((chan->channelFlags ^ ah->curchan->channelFlags) & ~CHANNEL_HT))
  1418. goto fail;
  1419. if (!ath9k_hw_check_alive(ah))
  1420. goto fail;
  1421. /*
  1422. * For AR9462, make sure that calibration data for
  1423. * re-using are present.
  1424. */
  1425. if (AR_SREV_9462(ah) && (ah->caldata &&
  1426. (!test_bit(TXIQCAL_DONE, &ah->caldata->cal_flags) ||
  1427. !test_bit(TXCLCAL_DONE, &ah->caldata->cal_flags) ||
  1428. !test_bit(RTT_DONE, &ah->caldata->cal_flags))))
  1429. goto fail;
  1430. ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
  1431. ah->curchan->channel, chan->channel);
  1432. ret = ath9k_hw_channel_change(ah, chan);
  1433. if (!ret)
  1434. goto fail;
  1435. if (ath9k_hw_mci_is_enabled(ah))
  1436. ar9003_mci_2g5g_switch(ah, false);
  1437. ath9k_hw_loadnf(ah, ah->curchan);
  1438. ath9k_hw_start_nfcal(ah, true);
  1439. if (AR_SREV_9271(ah))
  1440. ar9002_hw_load_ani_reg(ah, chan);
  1441. return 0;
  1442. fail:
  1443. return -EINVAL;
  1444. }
  1445. u32 ath9k_hw_get_tsf_offset(struct timespec *last, struct timespec *cur)
  1446. {
  1447. struct timespec ts;
  1448. s64 usec;
  1449. if (!cur) {
  1450. getrawmonotonic(&ts);
  1451. cur = &ts;
  1452. }
  1453. usec = cur->tv_sec * 1000000ULL + cur->tv_nsec / 1000;
  1454. usec -= last->tv_sec * 1000000ULL + last->tv_nsec / 1000;
  1455. return (u32) usec;
  1456. }
  1457. EXPORT_SYMBOL(ath9k_hw_get_tsf_offset);
  1458. int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
  1459. struct ath9k_hw_cal_data *caldata, bool fastcc)
  1460. {
  1461. struct ath_common *common = ath9k_hw_common(ah);
  1462. u32 saveLedState;
  1463. u32 saveDefAntenna;
  1464. u32 macStaId1;
  1465. u64 tsf = 0;
  1466. s64 usec = 0;
  1467. int r;
  1468. bool start_mci_reset = false;
  1469. bool save_fullsleep = ah->chip_fullsleep;
  1470. if (ath9k_hw_mci_is_enabled(ah)) {
  1471. start_mci_reset = ar9003_mci_start_reset(ah, chan);
  1472. if (start_mci_reset)
  1473. return 0;
  1474. }
  1475. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1476. return -EIO;
  1477. if (ah->curchan && !ah->chip_fullsleep)
  1478. ath9k_hw_getnf(ah, ah->curchan);
  1479. ah->caldata = caldata;
  1480. if (caldata && (chan->channel != caldata->channel ||
  1481. chan->channelFlags != caldata->channelFlags)) {
  1482. /* Operating channel changed, reset channel calibration data */
  1483. memset(caldata, 0, sizeof(*caldata));
  1484. ath9k_init_nfcal_hist_buffer(ah, chan);
  1485. } else if (caldata) {
  1486. clear_bit(PAPRD_PACKET_SENT, &caldata->cal_flags);
  1487. }
  1488. ah->noise = ath9k_hw_getchan_noise(ah, chan, chan->noisefloor);
  1489. if (fastcc) {
  1490. r = ath9k_hw_do_fastcc(ah, chan);
  1491. if (!r)
  1492. return r;
  1493. }
  1494. if (ath9k_hw_mci_is_enabled(ah))
  1495. ar9003_mci_stop_bt(ah, save_fullsleep);
  1496. saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
  1497. if (saveDefAntenna == 0)
  1498. saveDefAntenna = 1;
  1499. macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
  1500. /* Save TSF before chip reset, a cold reset clears it */
  1501. tsf = ath9k_hw_gettsf64(ah);
  1502. usec = ktime_to_us(ktime_get_raw());
  1503. saveLedState = REG_READ(ah, AR_CFG_LED) &
  1504. (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
  1505. AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
  1506. ath9k_hw_mark_phy_inactive(ah);
  1507. ah->paprd_table_write_done = false;
  1508. /* Only required on the first reset */
  1509. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  1510. REG_WRITE(ah,
  1511. AR9271_RESET_POWER_DOWN_CONTROL,
  1512. AR9271_RADIO_RF_RST);
  1513. udelay(50);
  1514. }
  1515. if (!ath9k_hw_chip_reset(ah, chan)) {
  1516. ath_err(common, "Chip reset failed\n");
  1517. return -EINVAL;
  1518. }
  1519. /* Only required on the first reset */
  1520. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  1521. ah->htc_reset_init = false;
  1522. REG_WRITE(ah,
  1523. AR9271_RESET_POWER_DOWN_CONTROL,
  1524. AR9271_GATE_MAC_CTL);
  1525. udelay(50);
  1526. }
  1527. /* Restore TSF */
  1528. usec = ktime_to_us(ktime_get_raw()) - usec;
  1529. ath9k_hw_settsf64(ah, tsf + usec);
  1530. if (AR_SREV_9280_20_OR_LATER(ah))
  1531. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  1532. if (!AR_SREV_9300_20_OR_LATER(ah))
  1533. ar9002_hw_enable_async_fifo(ah);
  1534. r = ath9k_hw_process_ini(ah, chan);
  1535. if (r)
  1536. return r;
  1537. ath9k_hw_set_rfmode(ah, chan);
  1538. if (ath9k_hw_mci_is_enabled(ah))
  1539. ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
  1540. /*
  1541. * Some AR91xx SoC devices frequently fail to accept TSF writes
  1542. * right after the chip reset. When that happens, write a new
  1543. * value after the initvals have been applied, with an offset
  1544. * based on measured time difference
  1545. */
  1546. if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
  1547. tsf += 1500;
  1548. ath9k_hw_settsf64(ah, tsf);
  1549. }
  1550. ath9k_hw_init_mfp(ah);
  1551. ath9k_hw_set_delta_slope(ah, chan);
  1552. ath9k_hw_spur_mitigate_freq(ah, chan);
  1553. ah->eep_ops->set_board_values(ah, chan);
  1554. ath9k_hw_reset_opmode(ah, macStaId1, saveDefAntenna);
  1555. r = ath9k_hw_rf_set_freq(ah, chan);
  1556. if (r)
  1557. return r;
  1558. ath9k_hw_set_clockrate(ah);
  1559. ath9k_hw_init_queues(ah);
  1560. ath9k_hw_init_interrupt_masks(ah, ah->opmode);
  1561. ath9k_hw_ani_cache_ini_regs(ah);
  1562. ath9k_hw_init_qos(ah);
  1563. if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1564. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  1565. ath9k_hw_init_global_settings(ah);
  1566. if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
  1567. REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
  1568. AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
  1569. REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
  1570. AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
  1571. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  1572. AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
  1573. }
  1574. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
  1575. ath9k_hw_set_dma(ah);
  1576. if (!ath9k_hw_mci_is_enabled(ah))
  1577. REG_WRITE(ah, AR_OBS, 8);
  1578. if (ah->config.rx_intr_mitigation) {
  1579. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, ah->config.rimt_last);
  1580. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, ah->config.rimt_first);
  1581. }
  1582. if (ah->config.tx_intr_mitigation) {
  1583. REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
  1584. REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
  1585. }
  1586. ath9k_hw_init_bb(ah, chan);
  1587. if (caldata) {
  1588. clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
  1589. clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
  1590. }
  1591. if (!ath9k_hw_init_cal(ah, chan))
  1592. return -EIO;
  1593. if (ath9k_hw_mci_is_enabled(ah) && ar9003_mci_end_reset(ah, chan, caldata))
  1594. return -EIO;
  1595. ENABLE_REGWRITE_BUFFER(ah);
  1596. ath9k_hw_restore_chainmask(ah);
  1597. REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
  1598. REGWRITE_BUFFER_FLUSH(ah);
  1599. ath9k_hw_gen_timer_start_tsf2(ah);
  1600. ath9k_hw_init_desc(ah);
  1601. if (ath9k_hw_btcoex_is_enabled(ah))
  1602. ath9k_hw_btcoex_enable(ah);
  1603. if (ath9k_hw_mci_is_enabled(ah))
  1604. ar9003_mci_check_bt(ah);
  1605. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1606. ath9k_hw_loadnf(ah, chan);
  1607. ath9k_hw_start_nfcal(ah, true);
  1608. }
  1609. if (AR_SREV_9300_20_OR_LATER(ah))
  1610. ar9003_hw_bb_watchdog_config(ah);
  1611. if (ah->config.hw_hang_checks & HW_PHYRESTART_CLC_WAR)
  1612. ar9003_hw_disable_phy_restart(ah);
  1613. ath9k_hw_apply_gpio_override(ah);
  1614. if (AR_SREV_9565(ah) && common->bt_ant_diversity)
  1615. REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON);
  1616. if (ah->hw->conf.radar_enabled) {
  1617. /* set HW specific DFS configuration */
  1618. ah->radar_conf.ext_channel = IS_CHAN_HT40(chan);
  1619. ath9k_hw_set_radar_params(ah);
  1620. }
  1621. return 0;
  1622. }
  1623. EXPORT_SYMBOL(ath9k_hw_reset);
  1624. /******************************/
  1625. /* Power Management (Chipset) */
  1626. /******************************/
  1627. /*
  1628. * Notify Power Mgt is disabled in self-generated frames.
  1629. * If requested, force chip to sleep.
  1630. */
  1631. static void ath9k_set_power_sleep(struct ath_hw *ah)
  1632. {
  1633. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1634. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  1635. REG_CLR_BIT(ah, AR_TIMER_MODE, 0xff);
  1636. REG_CLR_BIT(ah, AR_NDP2_TIMER_MODE, 0xff);
  1637. REG_CLR_BIT(ah, AR_SLP32_INC, 0xfffff);
  1638. /* xxx Required for WLAN only case ? */
  1639. REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
  1640. udelay(100);
  1641. }
  1642. /*
  1643. * Clear the RTC force wake bit to allow the
  1644. * mac to go to sleep.
  1645. */
  1646. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
  1647. if (ath9k_hw_mci_is_enabled(ah))
  1648. udelay(100);
  1649. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1650. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  1651. /* Shutdown chip. Active low */
  1652. if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
  1653. REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
  1654. udelay(2);
  1655. }
  1656. /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
  1657. if (AR_SREV_9300_20_OR_LATER(ah))
  1658. REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
  1659. }
  1660. /*
  1661. * Notify Power Management is enabled in self-generating
  1662. * frames. If request, set power mode of chip to
  1663. * auto/normal. Duration in units of 128us (1/8 TU).
  1664. */
  1665. static void ath9k_set_power_network_sleep(struct ath_hw *ah)
  1666. {
  1667. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1668. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1669. if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
  1670. /* Set WakeOnInterrupt bit; clear ForceWake bit */
  1671. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  1672. AR_RTC_FORCE_WAKE_ON_INT);
  1673. } else {
  1674. /* When chip goes into network sleep, it could be waken
  1675. * up by MCI_INT interrupt caused by BT's HW messages
  1676. * (LNA_xxx, CONT_xxx) which chould be in a very fast
  1677. * rate (~100us). This will cause chip to leave and
  1678. * re-enter network sleep mode frequently, which in
  1679. * consequence will have WLAN MCI HW to generate lots of
  1680. * SYS_WAKING and SYS_SLEEPING messages which will make
  1681. * BT CPU to busy to process.
  1682. */
  1683. if (ath9k_hw_mci_is_enabled(ah))
  1684. REG_CLR_BIT(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
  1685. AR_MCI_INTERRUPT_RX_HW_MSG_MASK);
  1686. /*
  1687. * Clear the RTC force wake bit to allow the
  1688. * mac to go to sleep.
  1689. */
  1690. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
  1691. if (ath9k_hw_mci_is_enabled(ah))
  1692. udelay(30);
  1693. }
  1694. /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
  1695. if (AR_SREV_9300_20_OR_LATER(ah))
  1696. REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
  1697. }
  1698. static bool ath9k_hw_set_power_awake(struct ath_hw *ah)
  1699. {
  1700. u32 val;
  1701. int i;
  1702. /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
  1703. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1704. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1705. udelay(10);
  1706. }
  1707. if ((REG_READ(ah, AR_RTC_STATUS) &
  1708. AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
  1709. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  1710. return false;
  1711. }
  1712. if (!AR_SREV_9300_20_OR_LATER(ah))
  1713. ath9k_hw_init_pll(ah, NULL);
  1714. }
  1715. if (AR_SREV_9100(ah))
  1716. REG_SET_BIT(ah, AR_RTC_RESET,
  1717. AR_RTC_RESET_EN);
  1718. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  1719. AR_RTC_FORCE_WAKE_EN);
  1720. if (AR_SREV_9100(ah))
  1721. mdelay(10);
  1722. else
  1723. udelay(50);
  1724. for (i = POWER_UP_TIME / 50; i > 0; i--) {
  1725. val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
  1726. if (val == AR_RTC_STATUS_ON)
  1727. break;
  1728. udelay(50);
  1729. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  1730. AR_RTC_FORCE_WAKE_EN);
  1731. }
  1732. if (i == 0) {
  1733. ath_err(ath9k_hw_common(ah),
  1734. "Failed to wakeup in %uus\n",
  1735. POWER_UP_TIME / 20);
  1736. return false;
  1737. }
  1738. if (ath9k_hw_mci_is_enabled(ah))
  1739. ar9003_mci_set_power_awake(ah);
  1740. REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1741. return true;
  1742. }
  1743. bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
  1744. {
  1745. struct ath_common *common = ath9k_hw_common(ah);
  1746. int status = true;
  1747. static const char *modes[] = {
  1748. "AWAKE",
  1749. "FULL-SLEEP",
  1750. "NETWORK SLEEP",
  1751. "UNDEFINED"
  1752. };
  1753. if (ah->power_mode == mode)
  1754. return status;
  1755. ath_dbg(common, RESET, "%s -> %s\n",
  1756. modes[ah->power_mode], modes[mode]);
  1757. switch (mode) {
  1758. case ATH9K_PM_AWAKE:
  1759. status = ath9k_hw_set_power_awake(ah);
  1760. break;
  1761. case ATH9K_PM_FULL_SLEEP:
  1762. if (ath9k_hw_mci_is_enabled(ah))
  1763. ar9003_mci_set_full_sleep(ah);
  1764. ath9k_set_power_sleep(ah);
  1765. ah->chip_fullsleep = true;
  1766. break;
  1767. case ATH9K_PM_NETWORK_SLEEP:
  1768. ath9k_set_power_network_sleep(ah);
  1769. break;
  1770. default:
  1771. ath_err(common, "Unknown power mode %u\n", mode);
  1772. return false;
  1773. }
  1774. ah->power_mode = mode;
  1775. /*
  1776. * XXX: If this warning never comes up after a while then
  1777. * simply keep the ATH_DBG_WARN_ON_ONCE() but make
  1778. * ath9k_hw_setpower() return type void.
  1779. */
  1780. if (!(ah->ah_flags & AH_UNPLUGGED))
  1781. ATH_DBG_WARN_ON_ONCE(!status);
  1782. return status;
  1783. }
  1784. EXPORT_SYMBOL(ath9k_hw_setpower);
  1785. /*******************/
  1786. /* Beacon Handling */
  1787. /*******************/
  1788. void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
  1789. {
  1790. int flags = 0;
  1791. ENABLE_REGWRITE_BUFFER(ah);
  1792. switch (ah->opmode) {
  1793. case NL80211_IFTYPE_ADHOC:
  1794. REG_SET_BIT(ah, AR_TXCFG,
  1795. AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
  1796. case NL80211_IFTYPE_MESH_POINT:
  1797. case NL80211_IFTYPE_AP:
  1798. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
  1799. REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
  1800. TU_TO_USEC(ah->config.dma_beacon_response_time));
  1801. REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
  1802. TU_TO_USEC(ah->config.sw_beacon_response_time));
  1803. flags |=
  1804. AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
  1805. break;
  1806. default:
  1807. ath_dbg(ath9k_hw_common(ah), BEACON,
  1808. "%s: unsupported opmode: %d\n", __func__, ah->opmode);
  1809. return;
  1810. break;
  1811. }
  1812. REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
  1813. REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
  1814. REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
  1815. REGWRITE_BUFFER_FLUSH(ah);
  1816. REG_SET_BIT(ah, AR_TIMER_MODE, flags);
  1817. }
  1818. EXPORT_SYMBOL(ath9k_hw_beaconinit);
  1819. void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
  1820. const struct ath9k_beacon_state *bs)
  1821. {
  1822. u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
  1823. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1824. struct ath_common *common = ath9k_hw_common(ah);
  1825. ENABLE_REGWRITE_BUFFER(ah);
  1826. REG_WRITE(ah, AR_NEXT_TBTT_TIMER, bs->bs_nexttbtt);
  1827. REG_WRITE(ah, AR_BEACON_PERIOD, bs->bs_intval);
  1828. REG_WRITE(ah, AR_DMA_BEACON_PERIOD, bs->bs_intval);
  1829. REGWRITE_BUFFER_FLUSH(ah);
  1830. REG_RMW_FIELD(ah, AR_RSSI_THR,
  1831. AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
  1832. beaconintval = bs->bs_intval;
  1833. if (bs->bs_sleepduration > beaconintval)
  1834. beaconintval = bs->bs_sleepduration;
  1835. dtimperiod = bs->bs_dtimperiod;
  1836. if (bs->bs_sleepduration > dtimperiod)
  1837. dtimperiod = bs->bs_sleepduration;
  1838. if (beaconintval == dtimperiod)
  1839. nextTbtt = bs->bs_nextdtim;
  1840. else
  1841. nextTbtt = bs->bs_nexttbtt;
  1842. ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
  1843. ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
  1844. ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
  1845. ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
  1846. ENABLE_REGWRITE_BUFFER(ah);
  1847. REG_WRITE(ah, AR_NEXT_DTIM, bs->bs_nextdtim - SLEEP_SLOP);
  1848. REG_WRITE(ah, AR_NEXT_TIM, nextTbtt - SLEEP_SLOP);
  1849. REG_WRITE(ah, AR_SLEEP1,
  1850. SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
  1851. | AR_SLEEP1_ASSUME_DTIM);
  1852. if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
  1853. beacontimeout = (BEACON_TIMEOUT_VAL << 3);
  1854. else
  1855. beacontimeout = MIN_BEACON_TIMEOUT_VAL;
  1856. REG_WRITE(ah, AR_SLEEP2,
  1857. SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
  1858. REG_WRITE(ah, AR_TIM_PERIOD, beaconintval);
  1859. REG_WRITE(ah, AR_DTIM_PERIOD, dtimperiod);
  1860. REGWRITE_BUFFER_FLUSH(ah);
  1861. REG_SET_BIT(ah, AR_TIMER_MODE,
  1862. AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
  1863. AR_DTIM_TIMER_EN);
  1864. /* TSF Out of Range Threshold */
  1865. REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
  1866. }
  1867. EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
  1868. /*******************/
  1869. /* HW Capabilities */
  1870. /*******************/
  1871. static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
  1872. {
  1873. eeprom_chainmask &= chip_chainmask;
  1874. if (eeprom_chainmask)
  1875. return eeprom_chainmask;
  1876. else
  1877. return chip_chainmask;
  1878. }
  1879. /**
  1880. * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
  1881. * @ah: the atheros hardware data structure
  1882. *
  1883. * We enable DFS support upstream on chipsets which have passed a series
  1884. * of tests. The testing requirements are going to be documented. Desired
  1885. * test requirements are documented at:
  1886. *
  1887. * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
  1888. *
  1889. * Once a new chipset gets properly tested an individual commit can be used
  1890. * to document the testing for DFS for that chipset.
  1891. */
  1892. static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
  1893. {
  1894. switch (ah->hw_version.macVersion) {
  1895. /* for temporary testing DFS with 9280 */
  1896. case AR_SREV_VERSION_9280:
  1897. /* AR9580 will likely be our first target to get testing on */
  1898. case AR_SREV_VERSION_9580:
  1899. return true;
  1900. default:
  1901. return false;
  1902. }
  1903. }
  1904. int ath9k_hw_fill_cap_info(struct ath_hw *ah)
  1905. {
  1906. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1907. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1908. struct ath_common *common = ath9k_hw_common(ah);
  1909. u16 eeval;
  1910. u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
  1911. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
  1912. regulatory->current_rd = eeval;
  1913. if (ah->opmode != NL80211_IFTYPE_AP &&
  1914. ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
  1915. if (regulatory->current_rd == 0x64 ||
  1916. regulatory->current_rd == 0x65)
  1917. regulatory->current_rd += 5;
  1918. else if (regulatory->current_rd == 0x41)
  1919. regulatory->current_rd = 0x43;
  1920. ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
  1921. regulatory->current_rd);
  1922. }
  1923. eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
  1924. if (eeval & AR5416_OPFLAGS_11A) {
  1925. if (ah->disable_5ghz)
  1926. ath_warn(common, "disabling 5GHz band\n");
  1927. else
  1928. pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
  1929. }
  1930. if (eeval & AR5416_OPFLAGS_11G) {
  1931. if (ah->disable_2ghz)
  1932. ath_warn(common, "disabling 2GHz band\n");
  1933. else
  1934. pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
  1935. }
  1936. if ((pCap->hw_caps & (ATH9K_HW_CAP_2GHZ | ATH9K_HW_CAP_5GHZ)) == 0) {
  1937. ath_err(common, "both bands are disabled\n");
  1938. return -EINVAL;
  1939. }
  1940. if (AR_SREV_9485(ah) ||
  1941. AR_SREV_9285(ah) ||
  1942. AR_SREV_9330(ah) ||
  1943. AR_SREV_9565(ah))
  1944. pCap->chip_chainmask = 1;
  1945. else if (!AR_SREV_9280_20_OR_LATER(ah))
  1946. pCap->chip_chainmask = 7;
  1947. else if (!AR_SREV_9300_20_OR_LATER(ah) ||
  1948. AR_SREV_9340(ah) ||
  1949. AR_SREV_9462(ah) ||
  1950. AR_SREV_9531(ah))
  1951. pCap->chip_chainmask = 3;
  1952. else
  1953. pCap->chip_chainmask = 7;
  1954. pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
  1955. /*
  1956. * For AR9271 we will temporarilly uses the rx chainmax as read from
  1957. * the EEPROM.
  1958. */
  1959. if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
  1960. !(eeval & AR5416_OPFLAGS_11A) &&
  1961. !(AR_SREV_9271(ah)))
  1962. /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
  1963. pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
  1964. else if (AR_SREV_9100(ah))
  1965. pCap->rx_chainmask = 0x7;
  1966. else
  1967. /* Use rx_chainmask from EEPROM. */
  1968. pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
  1969. pCap->tx_chainmask = fixup_chainmask(pCap->chip_chainmask, pCap->tx_chainmask);
  1970. pCap->rx_chainmask = fixup_chainmask(pCap->chip_chainmask, pCap->rx_chainmask);
  1971. ah->txchainmask = pCap->tx_chainmask;
  1972. ah->rxchainmask = pCap->rx_chainmask;
  1973. ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
  1974. /* enable key search for every frame in an aggregate */
  1975. if (AR_SREV_9300_20_OR_LATER(ah))
  1976. ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
  1977. common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
  1978. if (ah->hw_version.devid != AR2427_DEVID_PCIE)
  1979. pCap->hw_caps |= ATH9K_HW_CAP_HT;
  1980. else
  1981. pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
  1982. if (AR_SREV_9271(ah))
  1983. pCap->num_gpio_pins = AR9271_NUM_GPIO;
  1984. else if (AR_DEVID_7010(ah))
  1985. pCap->num_gpio_pins = AR7010_NUM_GPIO;
  1986. else if (AR_SREV_9300_20_OR_LATER(ah))
  1987. pCap->num_gpio_pins = AR9300_NUM_GPIO;
  1988. else if (AR_SREV_9287_11_OR_LATER(ah))
  1989. pCap->num_gpio_pins = AR9287_NUM_GPIO;
  1990. else if (AR_SREV_9285_12_OR_LATER(ah))
  1991. pCap->num_gpio_pins = AR9285_NUM_GPIO;
  1992. else if (AR_SREV_9280_20_OR_LATER(ah))
  1993. pCap->num_gpio_pins = AR928X_NUM_GPIO;
  1994. else
  1995. pCap->num_gpio_pins = AR_NUM_GPIO;
  1996. if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
  1997. pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
  1998. else
  1999. pCap->rts_aggr_limit = (8 * 1024);
  2000. #ifdef CONFIG_ATH9K_RFKILL
  2001. ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
  2002. if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
  2003. ah->rfkill_gpio =
  2004. MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
  2005. ah->rfkill_polarity =
  2006. MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
  2007. pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
  2008. }
  2009. #endif
  2010. if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
  2011. pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
  2012. else
  2013. pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
  2014. if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
  2015. pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
  2016. else
  2017. pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
  2018. if (AR_SREV_9300_20_OR_LATER(ah)) {
  2019. pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
  2020. if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah) && !AR_SREV_9565(ah))
  2021. pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
  2022. pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
  2023. pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
  2024. pCap->rx_status_len = sizeof(struct ar9003_rxs);
  2025. pCap->tx_desc_len = sizeof(struct ar9003_txc);
  2026. pCap->txs_len = sizeof(struct ar9003_txs);
  2027. } else {
  2028. pCap->tx_desc_len = sizeof(struct ath_desc);
  2029. if (AR_SREV_9280_20(ah))
  2030. pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
  2031. }
  2032. if (AR_SREV_9300_20_OR_LATER(ah))
  2033. pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
  2034. if (AR_SREV_9300_20_OR_LATER(ah))
  2035. ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
  2036. if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
  2037. pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
  2038. if (AR_SREV_9285(ah)) {
  2039. if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
  2040. ant_div_ctl1 =
  2041. ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  2042. if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1)) {
  2043. pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
  2044. ath_info(common, "Enable LNA combining\n");
  2045. }
  2046. }
  2047. }
  2048. if (AR_SREV_9300_20_OR_LATER(ah)) {
  2049. if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
  2050. pCap->hw_caps |= ATH9K_HW_CAP_APM;
  2051. }
  2052. if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
  2053. ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  2054. if ((ant_div_ctl1 >> 0x6) == 0x3) {
  2055. pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
  2056. ath_info(common, "Enable LNA combining\n");
  2057. }
  2058. }
  2059. if (ath9k_hw_dfs_tested(ah))
  2060. pCap->hw_caps |= ATH9K_HW_CAP_DFS;
  2061. tx_chainmask = pCap->tx_chainmask;
  2062. rx_chainmask = pCap->rx_chainmask;
  2063. while (tx_chainmask || rx_chainmask) {
  2064. if (tx_chainmask & BIT(0))
  2065. pCap->max_txchains++;
  2066. if (rx_chainmask & BIT(0))
  2067. pCap->max_rxchains++;
  2068. tx_chainmask >>= 1;
  2069. rx_chainmask >>= 1;
  2070. }
  2071. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  2072. if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE))
  2073. pCap->hw_caps |= ATH9K_HW_CAP_MCI;
  2074. if (AR_SREV_9462_20_OR_LATER(ah))
  2075. pCap->hw_caps |= ATH9K_HW_CAP_RTT;
  2076. }
  2077. if (AR_SREV_9462(ah))
  2078. pCap->hw_caps |= ATH9K_HW_WOW_DEVICE_CAPABLE;
  2079. if (AR_SREV_9300_20_OR_LATER(ah) &&
  2080. ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
  2081. pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
  2082. return 0;
  2083. }
  2084. /****************************/
  2085. /* GPIO / RFKILL / Antennae */
  2086. /****************************/
  2087. static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
  2088. u32 gpio, u32 type)
  2089. {
  2090. int addr;
  2091. u32 gpio_shift, tmp;
  2092. if (gpio > 11)
  2093. addr = AR_GPIO_OUTPUT_MUX3;
  2094. else if (gpio > 5)
  2095. addr = AR_GPIO_OUTPUT_MUX2;
  2096. else
  2097. addr = AR_GPIO_OUTPUT_MUX1;
  2098. gpio_shift = (gpio % 6) * 5;
  2099. if (AR_SREV_9280_20_OR_LATER(ah)
  2100. || (addr != AR_GPIO_OUTPUT_MUX1)) {
  2101. REG_RMW(ah, addr, (type << gpio_shift),
  2102. (0x1f << gpio_shift));
  2103. } else {
  2104. tmp = REG_READ(ah, addr);
  2105. tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
  2106. tmp &= ~(0x1f << gpio_shift);
  2107. tmp |= (type << gpio_shift);
  2108. REG_WRITE(ah, addr, tmp);
  2109. }
  2110. }
  2111. void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
  2112. {
  2113. u32 gpio_shift;
  2114. BUG_ON(gpio >= ah->caps.num_gpio_pins);
  2115. if (AR_DEVID_7010(ah)) {
  2116. gpio_shift = gpio;
  2117. REG_RMW(ah, AR7010_GPIO_OE,
  2118. (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
  2119. (AR7010_GPIO_OE_MASK << gpio_shift));
  2120. return;
  2121. }
  2122. gpio_shift = gpio << 1;
  2123. REG_RMW(ah,
  2124. AR_GPIO_OE_OUT,
  2125. (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
  2126. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  2127. }
  2128. EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
  2129. u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
  2130. {
  2131. #define MS_REG_READ(x, y) \
  2132. (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
  2133. if (gpio >= ah->caps.num_gpio_pins)
  2134. return 0xffffffff;
  2135. if (AR_DEVID_7010(ah)) {
  2136. u32 val;
  2137. val = REG_READ(ah, AR7010_GPIO_IN);
  2138. return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
  2139. } else if (AR_SREV_9300_20_OR_LATER(ah))
  2140. return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
  2141. AR_GPIO_BIT(gpio)) != 0;
  2142. else if (AR_SREV_9271(ah))
  2143. return MS_REG_READ(AR9271, gpio) != 0;
  2144. else if (AR_SREV_9287_11_OR_LATER(ah))
  2145. return MS_REG_READ(AR9287, gpio) != 0;
  2146. else if (AR_SREV_9285_12_OR_LATER(ah))
  2147. return MS_REG_READ(AR9285, gpio) != 0;
  2148. else if (AR_SREV_9280_20_OR_LATER(ah))
  2149. return MS_REG_READ(AR928X, gpio) != 0;
  2150. else
  2151. return MS_REG_READ(AR, gpio) != 0;
  2152. }
  2153. EXPORT_SYMBOL(ath9k_hw_gpio_get);
  2154. void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
  2155. u32 ah_signal_type)
  2156. {
  2157. u32 gpio_shift;
  2158. if (AR_DEVID_7010(ah)) {
  2159. gpio_shift = gpio;
  2160. REG_RMW(ah, AR7010_GPIO_OE,
  2161. (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
  2162. (AR7010_GPIO_OE_MASK << gpio_shift));
  2163. return;
  2164. }
  2165. ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
  2166. gpio_shift = 2 * gpio;
  2167. REG_RMW(ah,
  2168. AR_GPIO_OE_OUT,
  2169. (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
  2170. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  2171. }
  2172. EXPORT_SYMBOL(ath9k_hw_cfg_output);
  2173. void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
  2174. {
  2175. if (AR_DEVID_7010(ah)) {
  2176. val = val ? 0 : 1;
  2177. REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
  2178. AR_GPIO_BIT(gpio));
  2179. return;
  2180. }
  2181. if (AR_SREV_9271(ah))
  2182. val = ~val;
  2183. REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
  2184. AR_GPIO_BIT(gpio));
  2185. }
  2186. EXPORT_SYMBOL(ath9k_hw_set_gpio);
  2187. void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
  2188. {
  2189. REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
  2190. }
  2191. EXPORT_SYMBOL(ath9k_hw_setantenna);
  2192. /*********************/
  2193. /* General Operation */
  2194. /*********************/
  2195. u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
  2196. {
  2197. u32 bits = REG_READ(ah, AR_RX_FILTER);
  2198. u32 phybits = REG_READ(ah, AR_PHY_ERR);
  2199. if (phybits & AR_PHY_ERR_RADAR)
  2200. bits |= ATH9K_RX_FILTER_PHYRADAR;
  2201. if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
  2202. bits |= ATH9K_RX_FILTER_PHYERR;
  2203. return bits;
  2204. }
  2205. EXPORT_SYMBOL(ath9k_hw_getrxfilter);
  2206. void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
  2207. {
  2208. u32 phybits;
  2209. ENABLE_REGWRITE_BUFFER(ah);
  2210. if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
  2211. bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
  2212. REG_WRITE(ah, AR_RX_FILTER, bits);
  2213. phybits = 0;
  2214. if (bits & ATH9K_RX_FILTER_PHYRADAR)
  2215. phybits |= AR_PHY_ERR_RADAR;
  2216. if (bits & ATH9K_RX_FILTER_PHYERR)
  2217. phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
  2218. REG_WRITE(ah, AR_PHY_ERR, phybits);
  2219. if (phybits)
  2220. REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
  2221. else
  2222. REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
  2223. REGWRITE_BUFFER_FLUSH(ah);
  2224. }
  2225. EXPORT_SYMBOL(ath9k_hw_setrxfilter);
  2226. bool ath9k_hw_phy_disable(struct ath_hw *ah)
  2227. {
  2228. if (ath9k_hw_mci_is_enabled(ah))
  2229. ar9003_mci_bt_gain_ctrl(ah);
  2230. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  2231. return false;
  2232. ath9k_hw_init_pll(ah, NULL);
  2233. ah->htc_reset_init = true;
  2234. return true;
  2235. }
  2236. EXPORT_SYMBOL(ath9k_hw_phy_disable);
  2237. bool ath9k_hw_disable(struct ath_hw *ah)
  2238. {
  2239. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  2240. return false;
  2241. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
  2242. return false;
  2243. ath9k_hw_init_pll(ah, NULL);
  2244. return true;
  2245. }
  2246. EXPORT_SYMBOL(ath9k_hw_disable);
  2247. static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
  2248. {
  2249. enum eeprom_param gain_param;
  2250. if (IS_CHAN_2GHZ(chan))
  2251. gain_param = EEP_ANTENNA_GAIN_2G;
  2252. else
  2253. gain_param = EEP_ANTENNA_GAIN_5G;
  2254. return ah->eep_ops->get_eeprom(ah, gain_param);
  2255. }
  2256. void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
  2257. bool test)
  2258. {
  2259. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  2260. struct ieee80211_channel *channel;
  2261. int chan_pwr, new_pwr, max_gain;
  2262. int ant_gain, ant_reduction = 0;
  2263. if (!chan)
  2264. return;
  2265. channel = chan->chan;
  2266. chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
  2267. new_pwr = min_t(int, chan_pwr, reg->power_limit);
  2268. max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
  2269. ant_gain = get_antenna_gain(ah, chan);
  2270. if (ant_gain > max_gain)
  2271. ant_reduction = ant_gain - max_gain;
  2272. ah->eep_ops->set_txpower(ah, chan,
  2273. ath9k_regd_get_ctl(reg, chan),
  2274. ant_reduction, new_pwr, test);
  2275. }
  2276. void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
  2277. {
  2278. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  2279. struct ath9k_channel *chan = ah->curchan;
  2280. struct ieee80211_channel *channel = chan->chan;
  2281. reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
  2282. if (test)
  2283. channel->max_power = MAX_RATE_POWER / 2;
  2284. ath9k_hw_apply_txpower(ah, chan, test);
  2285. if (test)
  2286. channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
  2287. }
  2288. EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
  2289. void ath9k_hw_setopmode(struct ath_hw *ah)
  2290. {
  2291. ath9k_hw_set_operating_mode(ah, ah->opmode);
  2292. }
  2293. EXPORT_SYMBOL(ath9k_hw_setopmode);
  2294. void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
  2295. {
  2296. REG_WRITE(ah, AR_MCAST_FIL0, filter0);
  2297. REG_WRITE(ah, AR_MCAST_FIL1, filter1);
  2298. }
  2299. EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
  2300. void ath9k_hw_write_associd(struct ath_hw *ah)
  2301. {
  2302. struct ath_common *common = ath9k_hw_common(ah);
  2303. REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
  2304. REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
  2305. ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
  2306. }
  2307. EXPORT_SYMBOL(ath9k_hw_write_associd);
  2308. #define ATH9K_MAX_TSF_READ 10
  2309. u64 ath9k_hw_gettsf64(struct ath_hw *ah)
  2310. {
  2311. u32 tsf_lower, tsf_upper1, tsf_upper2;
  2312. int i;
  2313. tsf_upper1 = REG_READ(ah, AR_TSF_U32);
  2314. for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
  2315. tsf_lower = REG_READ(ah, AR_TSF_L32);
  2316. tsf_upper2 = REG_READ(ah, AR_TSF_U32);
  2317. if (tsf_upper2 == tsf_upper1)
  2318. break;
  2319. tsf_upper1 = tsf_upper2;
  2320. }
  2321. WARN_ON( i == ATH9K_MAX_TSF_READ );
  2322. return (((u64)tsf_upper1 << 32) | tsf_lower);
  2323. }
  2324. EXPORT_SYMBOL(ath9k_hw_gettsf64);
  2325. void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
  2326. {
  2327. REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
  2328. REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
  2329. }
  2330. EXPORT_SYMBOL(ath9k_hw_settsf64);
  2331. void ath9k_hw_reset_tsf(struct ath_hw *ah)
  2332. {
  2333. if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
  2334. AH_TSF_WRITE_TIMEOUT))
  2335. ath_dbg(ath9k_hw_common(ah), RESET,
  2336. "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
  2337. REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
  2338. }
  2339. EXPORT_SYMBOL(ath9k_hw_reset_tsf);
  2340. void ath9k_hw_set_tsfadjust(struct ath_hw *ah, bool set)
  2341. {
  2342. if (set)
  2343. ah->misc_mode |= AR_PCU_TX_ADD_TSF;
  2344. else
  2345. ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
  2346. }
  2347. EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
  2348. void ath9k_hw_set11nmac2040(struct ath_hw *ah, struct ath9k_channel *chan)
  2349. {
  2350. u32 macmode;
  2351. if (IS_CHAN_HT40(chan) && !ah->config.cwm_ignore_extcca)
  2352. macmode = AR_2040_JOINED_RX_CLEAR;
  2353. else
  2354. macmode = 0;
  2355. REG_WRITE(ah, AR_2040_MODE, macmode);
  2356. }
  2357. /* HW Generic timers configuration */
  2358. static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
  2359. {
  2360. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2361. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2362. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2363. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2364. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2365. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2366. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2367. {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
  2368. {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
  2369. {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
  2370. AR_NDP2_TIMER_MODE, 0x0002},
  2371. {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
  2372. AR_NDP2_TIMER_MODE, 0x0004},
  2373. {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
  2374. AR_NDP2_TIMER_MODE, 0x0008},
  2375. {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
  2376. AR_NDP2_TIMER_MODE, 0x0010},
  2377. {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
  2378. AR_NDP2_TIMER_MODE, 0x0020},
  2379. {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
  2380. AR_NDP2_TIMER_MODE, 0x0040},
  2381. {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
  2382. AR_NDP2_TIMER_MODE, 0x0080}
  2383. };
  2384. /* HW generic timer primitives */
  2385. u32 ath9k_hw_gettsf32(struct ath_hw *ah)
  2386. {
  2387. return REG_READ(ah, AR_TSF_L32);
  2388. }
  2389. EXPORT_SYMBOL(ath9k_hw_gettsf32);
  2390. void ath9k_hw_gen_timer_start_tsf2(struct ath_hw *ah)
  2391. {
  2392. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2393. if (timer_table->tsf2_enabled) {
  2394. REG_SET_BIT(ah, AR_DIRECT_CONNECT, AR_DC_AP_STA_EN);
  2395. REG_SET_BIT(ah, AR_RESET_TSF, AR_RESET_TSF2_ONCE);
  2396. }
  2397. }
  2398. struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
  2399. void (*trigger)(void *),
  2400. void (*overflow)(void *),
  2401. void *arg,
  2402. u8 timer_index)
  2403. {
  2404. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2405. struct ath_gen_timer *timer;
  2406. if ((timer_index < AR_FIRST_NDP_TIMER) ||
  2407. (timer_index >= ATH_MAX_GEN_TIMER))
  2408. return NULL;
  2409. if ((timer_index > AR_FIRST_NDP_TIMER) &&
  2410. !AR_SREV_9300_20_OR_LATER(ah))
  2411. return NULL;
  2412. timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
  2413. if (timer == NULL)
  2414. return NULL;
  2415. /* allocate a hardware generic timer slot */
  2416. timer_table->timers[timer_index] = timer;
  2417. timer->index = timer_index;
  2418. timer->trigger = trigger;
  2419. timer->overflow = overflow;
  2420. timer->arg = arg;
  2421. if ((timer_index > AR_FIRST_NDP_TIMER) && !timer_table->tsf2_enabled) {
  2422. timer_table->tsf2_enabled = true;
  2423. ath9k_hw_gen_timer_start_tsf2(ah);
  2424. }
  2425. return timer;
  2426. }
  2427. EXPORT_SYMBOL(ath_gen_timer_alloc);
  2428. void ath9k_hw_gen_timer_start(struct ath_hw *ah,
  2429. struct ath_gen_timer *timer,
  2430. u32 timer_next,
  2431. u32 timer_period)
  2432. {
  2433. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2434. u32 mask = 0;
  2435. timer_table->timer_mask |= BIT(timer->index);
  2436. /*
  2437. * Program generic timer registers
  2438. */
  2439. REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
  2440. timer_next);
  2441. REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
  2442. timer_period);
  2443. REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  2444. gen_tmr_configuration[timer->index].mode_mask);
  2445. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  2446. /*
  2447. * Starting from AR9462, each generic timer can select which tsf
  2448. * to use. But we still follow the old rule, 0 - 7 use tsf and
  2449. * 8 - 15 use tsf2.
  2450. */
  2451. if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
  2452. REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
  2453. (1 << timer->index));
  2454. else
  2455. REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
  2456. (1 << timer->index));
  2457. }
  2458. if (timer->trigger)
  2459. mask |= SM(AR_GENTMR_BIT(timer->index),
  2460. AR_IMR_S5_GENTIMER_TRIG);
  2461. if (timer->overflow)
  2462. mask |= SM(AR_GENTMR_BIT(timer->index),
  2463. AR_IMR_S5_GENTIMER_THRESH);
  2464. REG_SET_BIT(ah, AR_IMR_S5, mask);
  2465. if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
  2466. ah->imask |= ATH9K_INT_GENTIMER;
  2467. ath9k_hw_set_interrupts(ah);
  2468. }
  2469. }
  2470. EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
  2471. void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
  2472. {
  2473. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2474. /* Clear generic timer enable bits. */
  2475. REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
  2476. gen_tmr_configuration[timer->index].mode_mask);
  2477. if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
  2478. /*
  2479. * Need to switch back to TSF if it was using TSF2.
  2480. */
  2481. if ((timer->index >= AR_GEN_TIMER_BANK_1_LEN)) {
  2482. REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
  2483. (1 << timer->index));
  2484. }
  2485. }
  2486. /* Disable both trigger and thresh interrupt masks */
  2487. REG_CLR_BIT(ah, AR_IMR_S5,
  2488. (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
  2489. SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
  2490. timer_table->timer_mask &= ~BIT(timer->index);
  2491. if (timer_table->timer_mask == 0) {
  2492. ah->imask &= ~ATH9K_INT_GENTIMER;
  2493. ath9k_hw_set_interrupts(ah);
  2494. }
  2495. }
  2496. EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
  2497. void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
  2498. {
  2499. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2500. /* free the hardware generic timer slot */
  2501. timer_table->timers[timer->index] = NULL;
  2502. kfree(timer);
  2503. }
  2504. EXPORT_SYMBOL(ath_gen_timer_free);
  2505. /*
  2506. * Generic Timer Interrupts handling
  2507. */
  2508. void ath_gen_timer_isr(struct ath_hw *ah)
  2509. {
  2510. struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
  2511. struct ath_gen_timer *timer;
  2512. unsigned long trigger_mask, thresh_mask;
  2513. unsigned int index;
  2514. /* get hardware generic timer interrupt status */
  2515. trigger_mask = ah->intr_gen_timer_trigger;
  2516. thresh_mask = ah->intr_gen_timer_thresh;
  2517. trigger_mask &= timer_table->timer_mask;
  2518. thresh_mask &= timer_table->timer_mask;
  2519. for_each_set_bit(index, &thresh_mask, ARRAY_SIZE(timer_table->timers)) {
  2520. timer = timer_table->timers[index];
  2521. if (!timer)
  2522. continue;
  2523. if (!timer->overflow)
  2524. continue;
  2525. trigger_mask &= ~BIT(index);
  2526. timer->overflow(timer->arg);
  2527. }
  2528. for_each_set_bit(index, &trigger_mask, ARRAY_SIZE(timer_table->timers)) {
  2529. timer = timer_table->timers[index];
  2530. if (!timer)
  2531. continue;
  2532. if (!timer->trigger)
  2533. continue;
  2534. timer->trigger(timer->arg);
  2535. }
  2536. }
  2537. EXPORT_SYMBOL(ath_gen_timer_isr);
  2538. /********/
  2539. /* HTC */
  2540. /********/
  2541. static struct {
  2542. u32 version;
  2543. const char * name;
  2544. } ath_mac_bb_names[] = {
  2545. /* Devices with external radios */
  2546. { AR_SREV_VERSION_5416_PCI, "5416" },
  2547. { AR_SREV_VERSION_5416_PCIE, "5418" },
  2548. { AR_SREV_VERSION_9100, "9100" },
  2549. { AR_SREV_VERSION_9160, "9160" },
  2550. /* Single-chip solutions */
  2551. { AR_SREV_VERSION_9280, "9280" },
  2552. { AR_SREV_VERSION_9285, "9285" },
  2553. { AR_SREV_VERSION_9287, "9287" },
  2554. { AR_SREV_VERSION_9271, "9271" },
  2555. { AR_SREV_VERSION_9300, "9300" },
  2556. { AR_SREV_VERSION_9330, "9330" },
  2557. { AR_SREV_VERSION_9340, "9340" },
  2558. { AR_SREV_VERSION_9485, "9485" },
  2559. { AR_SREV_VERSION_9462, "9462" },
  2560. { AR_SREV_VERSION_9550, "9550" },
  2561. { AR_SREV_VERSION_9565, "9565" },
  2562. { AR_SREV_VERSION_9531, "9531" },
  2563. };
  2564. /* For devices with external radios */
  2565. static struct {
  2566. u16 version;
  2567. const char * name;
  2568. } ath_rf_names[] = {
  2569. { 0, "5133" },
  2570. { AR_RAD5133_SREV_MAJOR, "5133" },
  2571. { AR_RAD5122_SREV_MAJOR, "5122" },
  2572. { AR_RAD2133_SREV_MAJOR, "2133" },
  2573. { AR_RAD2122_SREV_MAJOR, "2122" }
  2574. };
  2575. /*
  2576. * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
  2577. */
  2578. static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
  2579. {
  2580. int i;
  2581. for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
  2582. if (ath_mac_bb_names[i].version == mac_bb_version) {
  2583. return ath_mac_bb_names[i].name;
  2584. }
  2585. }
  2586. return "????";
  2587. }
  2588. /*
  2589. * Return the RF name. "????" is returned if the RF is unknown.
  2590. * Used for devices with external radios.
  2591. */
  2592. static const char *ath9k_hw_rf_name(u16 rf_version)
  2593. {
  2594. int i;
  2595. for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
  2596. if (ath_rf_names[i].version == rf_version) {
  2597. return ath_rf_names[i].name;
  2598. }
  2599. }
  2600. return "????";
  2601. }
  2602. void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
  2603. {
  2604. int used;
  2605. /* chipsets >= AR9280 are single-chip */
  2606. if (AR_SREV_9280_20_OR_LATER(ah)) {
  2607. used = scnprintf(hw_name, len,
  2608. "Atheros AR%s Rev:%x",
  2609. ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
  2610. ah->hw_version.macRev);
  2611. }
  2612. else {
  2613. used = scnprintf(hw_name, len,
  2614. "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
  2615. ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
  2616. ah->hw_version.macRev,
  2617. ath9k_hw_rf_name((ah->hw_version.analog5GhzRev
  2618. & AR_RADIO_SREV_MAJOR)),
  2619. ah->hw_version.phyRev);
  2620. }
  2621. hw_name[used] = '\0';
  2622. }
  2623. EXPORT_SYMBOL(ath9k_hw_name);