hw.c 79 KB

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