hw.c 79 KB

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