ar9003_phy.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  1. /*
  2. * Copyright (c) 2010-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/export.h>
  17. #include "hw.h"
  18. #include "ar9003_phy.h"
  19. static const int firstep_table[] =
  20. /* level: 0 1 2 3 4 5 6 7 8 */
  21. { -4, -2, 0, 2, 4, 6, 8, 10, 12 }; /* lvl 0-8, default 2 */
  22. static const int cycpwrThr1_table[] =
  23. /* level: 0 1 2 3 4 5 6 7 8 */
  24. { -6, -4, -2, 0, 2, 4, 6, 8 }; /* lvl 0-7, default 3 */
  25. /*
  26. * register values to turn OFDM weak signal detection OFF
  27. */
  28. static const int m1ThreshLow_off = 127;
  29. static const int m2ThreshLow_off = 127;
  30. static const int m1Thresh_off = 127;
  31. static const int m2Thresh_off = 127;
  32. static const int m2CountThr_off = 31;
  33. static const int m2CountThrLow_off = 63;
  34. static const int m1ThreshLowExt_off = 127;
  35. static const int m2ThreshLowExt_off = 127;
  36. static const int m1ThreshExt_off = 127;
  37. static const int m2ThreshExt_off = 127;
  38. /**
  39. * ar9003_hw_set_channel - set channel on single-chip device
  40. * @ah: atheros hardware structure
  41. * @chan:
  42. *
  43. * This is the function to change channel on single-chip devices, that is
  44. * for AR9300 family of chipsets.
  45. *
  46. * This function takes the channel value in MHz and sets
  47. * hardware channel value. Assumes writes have been enabled to analog bus.
  48. *
  49. * Actual Expression,
  50. *
  51. * For 2GHz channel,
  52. * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  53. * (freq_ref = 40MHz)
  54. *
  55. * For 5GHz channel,
  56. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
  57. * (freq_ref = 40MHz/(24>>amodeRefSel))
  58. *
  59. * For 5GHz channels which are 5MHz spaced,
  60. * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
  61. * (freq_ref = 40MHz)
  62. */
  63. static int ar9003_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
  64. {
  65. u16 bMode, fracMode = 0, aModeRefSel = 0;
  66. u32 freq, channelSel = 0, reg32 = 0;
  67. struct chan_centers centers;
  68. int loadSynthChannel;
  69. ath9k_hw_get_channel_centers(ah, chan, &centers);
  70. freq = centers.synth_center;
  71. if (freq < 4800) { /* 2 GHz, fractional mode */
  72. if (AR_SREV_9330(ah)) {
  73. u32 chan_frac;
  74. u32 div;
  75. if (ah->is_clk_25mhz)
  76. div = 75;
  77. else
  78. div = 120;
  79. channelSel = (freq * 4) / div;
  80. chan_frac = (((freq * 4) % div) * 0x20000) / div;
  81. channelSel = (channelSel << 17) | chan_frac;
  82. } else if (AR_SREV_9485(ah)) {
  83. u32 chan_frac;
  84. /*
  85. * freq_ref = 40 / (refdiva >> amoderefsel); where refdiva=1 and amoderefsel=0
  86. * ndiv = ((chan_mhz * 4) / 3) / freq_ref;
  87. * chansel = int(ndiv), chanfrac = (ndiv - chansel) * 0x20000
  88. */
  89. channelSel = (freq * 4) / 120;
  90. chan_frac = (((freq * 4) % 120) * 0x20000) / 120;
  91. channelSel = (channelSel << 17) | chan_frac;
  92. } else if (AR_SREV_9340(ah)) {
  93. if (ah->is_clk_25mhz) {
  94. u32 chan_frac;
  95. channelSel = (freq * 2) / 75;
  96. chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
  97. channelSel = (channelSel << 17) | chan_frac;
  98. } else
  99. channelSel = CHANSEL_2G(freq) >> 1;
  100. } else
  101. channelSel = CHANSEL_2G(freq);
  102. /* Set to 2G mode */
  103. bMode = 1;
  104. } else {
  105. if (AR_SREV_9340(ah) && ah->is_clk_25mhz) {
  106. u32 chan_frac;
  107. channelSel = (freq * 2) / 75;
  108. chan_frac = (((freq * 2) % 75) * 0x20000) / 75;
  109. channelSel = (channelSel << 17) | chan_frac;
  110. } else {
  111. channelSel = CHANSEL_5G(freq);
  112. /* Doubler is ON, so, divide channelSel by 2. */
  113. channelSel >>= 1;
  114. }
  115. /* Set to 5G mode */
  116. bMode = 0;
  117. }
  118. /* Enable fractional mode for all channels */
  119. fracMode = 1;
  120. aModeRefSel = 0;
  121. loadSynthChannel = 0;
  122. reg32 = (bMode << 29);
  123. REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
  124. /* Enable Long shift Select for Synthesizer */
  125. REG_RMW_FIELD(ah, AR_PHY_65NM_CH0_SYNTH4,
  126. AR_PHY_SYNTH4_LONG_SHIFT_SELECT, 1);
  127. /* Program Synth. setting */
  128. reg32 = (channelSel << 2) | (fracMode << 30) |
  129. (aModeRefSel << 28) | (loadSynthChannel << 31);
  130. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  131. /* Toggle Load Synth channel bit */
  132. loadSynthChannel = 1;
  133. reg32 = (channelSel << 2) | (fracMode << 30) |
  134. (aModeRefSel << 28) | (loadSynthChannel << 31);
  135. REG_WRITE(ah, AR_PHY_65NM_CH0_SYNTH7, reg32);
  136. ah->curchan = chan;
  137. return 0;
  138. }
  139. /**
  140. * ar9003_hw_spur_mitigate_mrc_cck - convert baseband spur frequency
  141. * @ah: atheros hardware structure
  142. * @chan:
  143. *
  144. * For single-chip solutions. Converts to baseband spur frequency given the
  145. * input channel frequency and compute register settings below.
  146. *
  147. * Spur mitigation for MRC CCK
  148. */
  149. static void ar9003_hw_spur_mitigate_mrc_cck(struct ath_hw *ah,
  150. struct ath9k_channel *chan)
  151. {
  152. static const u32 spur_freq[4] = { 2420, 2440, 2464, 2480 };
  153. int cur_bb_spur, negative = 0, cck_spur_freq;
  154. int i;
  155. int range, max_spur_cnts, synth_freq;
  156. u8 *spur_fbin_ptr = ar9003_get_spur_chan_ptr(ah, IS_CHAN_2GHZ(chan));
  157. /*
  158. * Need to verify range +/- 10 MHz in control channel, otherwise spur
  159. * is out-of-band and can be ignored.
  160. */
  161. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah)) {
  162. if (spur_fbin_ptr[0] == 0) /* No spur */
  163. return;
  164. max_spur_cnts = 5;
  165. if (IS_CHAN_HT40(chan)) {
  166. range = 19;
  167. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  168. AR_PHY_GC_DYN2040_PRI_CH) == 0)
  169. synth_freq = chan->channel + 10;
  170. else
  171. synth_freq = chan->channel - 10;
  172. } else {
  173. range = 10;
  174. synth_freq = chan->channel;
  175. }
  176. } else {
  177. range = AR_SREV_9462(ah) ? 5 : 10;
  178. max_spur_cnts = 4;
  179. synth_freq = chan->channel;
  180. }
  181. for (i = 0; i < max_spur_cnts; i++) {
  182. if (AR_SREV_9462(ah) && (i == 0 || i == 3))
  183. continue;
  184. negative = 0;
  185. if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah))
  186. cur_bb_spur = ath9k_hw_fbin2freq(spur_fbin_ptr[i],
  187. IS_CHAN_2GHZ(chan));
  188. else
  189. cur_bb_spur = spur_freq[i];
  190. cur_bb_spur -= synth_freq;
  191. if (cur_bb_spur < 0) {
  192. negative = 1;
  193. cur_bb_spur = -cur_bb_spur;
  194. }
  195. if (cur_bb_spur < range) {
  196. cck_spur_freq = (int)((cur_bb_spur << 19) / 11);
  197. if (negative == 1)
  198. cck_spur_freq = -cck_spur_freq;
  199. cck_spur_freq = cck_spur_freq & 0xfffff;
  200. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  201. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x7);
  202. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  203. AR_PHY_CCK_SPUR_MIT_SPUR_RSSI_THR, 0x7f);
  204. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  205. AR_PHY_CCK_SPUR_MIT_SPUR_FILTER_TYPE,
  206. 0x2);
  207. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  208. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT,
  209. 0x1);
  210. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  211. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ,
  212. cck_spur_freq);
  213. return;
  214. }
  215. }
  216. REG_RMW_FIELD(ah, AR_PHY_AGC_CONTROL,
  217. AR_PHY_AGC_CONTROL_YCOK_MAX, 0x5);
  218. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  219. AR_PHY_CCK_SPUR_MIT_USE_CCK_SPUR_MIT, 0x0);
  220. REG_RMW_FIELD(ah, AR_PHY_CCK_SPUR_MIT,
  221. AR_PHY_CCK_SPUR_MIT_CCK_SPUR_FREQ, 0x0);
  222. }
  223. /* Clean all spur register fields */
  224. static void ar9003_hw_spur_ofdm_clear(struct ath_hw *ah)
  225. {
  226. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  227. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0);
  228. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  229. AR_PHY_TIMING11_SPUR_FREQ_SD, 0);
  230. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  231. AR_PHY_TIMING11_SPUR_DELTA_PHASE, 0);
  232. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  233. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, 0);
  234. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  235. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0);
  236. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  237. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0);
  238. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  239. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0);
  240. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  241. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 0);
  242. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  243. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 0);
  244. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  245. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0);
  246. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  247. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0);
  248. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  249. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0);
  250. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  251. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, 0);
  252. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  253. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, 0);
  254. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  255. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, 0);
  256. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  257. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0);
  258. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  259. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0);
  260. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  261. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0);
  262. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  263. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0);
  264. }
  265. static void ar9003_hw_spur_ofdm(struct ath_hw *ah,
  266. int freq_offset,
  267. int spur_freq_sd,
  268. int spur_delta_phase,
  269. int spur_subchannel_sd)
  270. {
  271. int mask_index = 0;
  272. /* OFDM Spur mitigation */
  273. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  274. AR_PHY_TIMING4_ENABLE_SPUR_FILTER, 0x1);
  275. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  276. AR_PHY_TIMING11_SPUR_FREQ_SD, spur_freq_sd);
  277. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  278. AR_PHY_TIMING11_SPUR_DELTA_PHASE, spur_delta_phase);
  279. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  280. AR_PHY_SFCORR_EXT_SPUR_SUBCHANNEL_SD, spur_subchannel_sd);
  281. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  282. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_AGC, 0x1);
  283. REG_RMW_FIELD(ah, AR_PHY_TIMING11,
  284. AR_PHY_TIMING11_USE_SPUR_FILTER_IN_SELFCOR, 0x1);
  285. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  286. AR_PHY_TIMING4_ENABLE_SPUR_RSSI, 0x1);
  287. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  288. AR_PHY_SPUR_REG_SPUR_RSSI_THRESH, 34);
  289. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  290. AR_PHY_SPUR_REG_EN_VIT_SPUR_RSSI, 1);
  291. if (REG_READ_FIELD(ah, AR_PHY_MODE,
  292. AR_PHY_MODE_DYNAMIC) == 0x1)
  293. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  294. AR_PHY_SPUR_REG_ENABLE_NF_RSSI_SPUR_MIT, 1);
  295. mask_index = (freq_offset << 4) / 5;
  296. if (mask_index < 0)
  297. mask_index = mask_index - 1;
  298. mask_index = mask_index & 0x7f;
  299. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  300. AR_PHY_SPUR_REG_ENABLE_MASK_PPM, 0x1);
  301. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  302. AR_PHY_TIMING4_ENABLE_PILOT_MASK, 0x1);
  303. REG_RMW_FIELD(ah, AR_PHY_TIMING4,
  304. AR_PHY_TIMING4_ENABLE_CHAN_MASK, 0x1);
  305. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  306. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_IDX_A, mask_index);
  307. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  308. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_IDX_A, mask_index);
  309. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  310. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_IDX_A, mask_index);
  311. REG_RMW_FIELD(ah, AR_PHY_PILOT_SPUR_MASK,
  312. AR_PHY_PILOT_SPUR_MASK_CF_PILOT_MASK_A, 0xc);
  313. REG_RMW_FIELD(ah, AR_PHY_CHAN_SPUR_MASK,
  314. AR_PHY_CHAN_SPUR_MASK_CF_CHAN_MASK_A, 0xc);
  315. REG_RMW_FIELD(ah, AR_PHY_SPUR_MASK_A,
  316. AR_PHY_SPUR_MASK_A_CF_PUNC_MASK_A, 0xa0);
  317. REG_RMW_FIELD(ah, AR_PHY_SPUR_REG,
  318. AR_PHY_SPUR_REG_MASK_RATE_CNTL, 0xff);
  319. }
  320. static void ar9003_hw_spur_ofdm_work(struct ath_hw *ah,
  321. struct ath9k_channel *chan,
  322. int freq_offset)
  323. {
  324. int spur_freq_sd = 0;
  325. int spur_subchannel_sd = 0;
  326. int spur_delta_phase = 0;
  327. if (IS_CHAN_HT40(chan)) {
  328. if (freq_offset < 0) {
  329. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  330. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  331. spur_subchannel_sd = 1;
  332. else
  333. spur_subchannel_sd = 0;
  334. spur_freq_sd = ((freq_offset + 10) << 9) / 11;
  335. } else {
  336. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  337. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  338. spur_subchannel_sd = 0;
  339. else
  340. spur_subchannel_sd = 1;
  341. spur_freq_sd = ((freq_offset - 10) << 9) / 11;
  342. }
  343. spur_delta_phase = (freq_offset << 17) / 5;
  344. } else {
  345. spur_subchannel_sd = 0;
  346. spur_freq_sd = (freq_offset << 9) /11;
  347. spur_delta_phase = (freq_offset << 18) / 5;
  348. }
  349. spur_freq_sd = spur_freq_sd & 0x3ff;
  350. spur_delta_phase = spur_delta_phase & 0xfffff;
  351. ar9003_hw_spur_ofdm(ah,
  352. freq_offset,
  353. spur_freq_sd,
  354. spur_delta_phase,
  355. spur_subchannel_sd);
  356. }
  357. /* Spur mitigation for OFDM */
  358. static void ar9003_hw_spur_mitigate_ofdm(struct ath_hw *ah,
  359. struct ath9k_channel *chan)
  360. {
  361. int synth_freq;
  362. int range = 10;
  363. int freq_offset = 0;
  364. int mode;
  365. u8* spurChansPtr;
  366. unsigned int i;
  367. struct ar9300_eeprom *eep = &ah->eeprom.ar9300_eep;
  368. if (IS_CHAN_5GHZ(chan)) {
  369. spurChansPtr = &(eep->modalHeader5G.spurChans[0]);
  370. mode = 0;
  371. }
  372. else {
  373. spurChansPtr = &(eep->modalHeader2G.spurChans[0]);
  374. mode = 1;
  375. }
  376. if (spurChansPtr[0] == 0)
  377. return; /* No spur in the mode */
  378. if (IS_CHAN_HT40(chan)) {
  379. range = 19;
  380. if (REG_READ_FIELD(ah, AR_PHY_GEN_CTRL,
  381. AR_PHY_GC_DYN2040_PRI_CH) == 0x0)
  382. synth_freq = chan->channel - 10;
  383. else
  384. synth_freq = chan->channel + 10;
  385. } else {
  386. range = 10;
  387. synth_freq = chan->channel;
  388. }
  389. ar9003_hw_spur_ofdm_clear(ah);
  390. for (i = 0; i < AR_EEPROM_MODAL_SPURS && spurChansPtr[i]; i++) {
  391. freq_offset = ath9k_hw_fbin2freq(spurChansPtr[i], mode);
  392. freq_offset -= synth_freq;
  393. if (abs(freq_offset) < range) {
  394. ar9003_hw_spur_ofdm_work(ah, chan, freq_offset);
  395. break;
  396. }
  397. }
  398. }
  399. static void ar9003_hw_spur_mitigate(struct ath_hw *ah,
  400. struct ath9k_channel *chan)
  401. {
  402. ar9003_hw_spur_mitigate_mrc_cck(ah, chan);
  403. ar9003_hw_spur_mitigate_ofdm(ah, chan);
  404. }
  405. static u32 ar9003_hw_compute_pll_control(struct ath_hw *ah,
  406. struct ath9k_channel *chan)
  407. {
  408. u32 pll;
  409. pll = SM(0x5, AR_RTC_9300_PLL_REFDIV);
  410. if (chan && IS_CHAN_HALF_RATE(chan))
  411. pll |= SM(0x1, AR_RTC_9300_PLL_CLKSEL);
  412. else if (chan && IS_CHAN_QUARTER_RATE(chan))
  413. pll |= SM(0x2, AR_RTC_9300_PLL_CLKSEL);
  414. pll |= SM(0x2c, AR_RTC_9300_PLL_DIV);
  415. return pll;
  416. }
  417. static void ar9003_hw_set_channel_regs(struct ath_hw *ah,
  418. struct ath9k_channel *chan)
  419. {
  420. u32 phymode;
  421. u32 enableDacFifo = 0;
  422. enableDacFifo =
  423. (REG_READ(ah, AR_PHY_GEN_CTRL) & AR_PHY_GC_ENABLE_DAC_FIFO);
  424. /* Enable 11n HT, 20 MHz */
  425. phymode = AR_PHY_GC_HT_EN | AR_PHY_GC_SINGLE_HT_LTF1 |
  426. AR_PHY_GC_SHORT_GI_40 | enableDacFifo;
  427. /* Configure baseband for dynamic 20/40 operation */
  428. if (IS_CHAN_HT40(chan)) {
  429. phymode |= AR_PHY_GC_DYN2040_EN;
  430. /* Configure control (primary) channel at +-10MHz */
  431. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  432. (chan->chanmode == CHANNEL_G_HT40PLUS))
  433. phymode |= AR_PHY_GC_DYN2040_PRI_CH;
  434. }
  435. /* make sure we preserve INI settings */
  436. phymode |= REG_READ(ah, AR_PHY_GEN_CTRL);
  437. /* turn off Green Field detection for STA for now */
  438. phymode &= ~AR_PHY_GC_GF_DETECT_EN;
  439. REG_WRITE(ah, AR_PHY_GEN_CTRL, phymode);
  440. /* Configure MAC for 20/40 operation */
  441. ath9k_hw_set11nmac2040(ah);
  442. /* global transmit timeout (25 TUs default)*/
  443. REG_WRITE(ah, AR_GTXTO, 25 << AR_GTXTO_TIMEOUT_LIMIT_S);
  444. /* carrier sense timeout */
  445. REG_WRITE(ah, AR_CST, 0xF << AR_CST_TIMEOUT_LIMIT_S);
  446. }
  447. static void ar9003_hw_init_bb(struct ath_hw *ah,
  448. struct ath9k_channel *chan)
  449. {
  450. u32 synthDelay;
  451. /*
  452. * Wait for the frequency synth to settle (synth goes on
  453. * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
  454. * Value is in 100ns increments.
  455. */
  456. synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  457. /* Activate the PHY (includes baseband activate + synthesizer on) */
  458. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
  459. ath9k_hw_synth_delay(ah, chan, synthDelay);
  460. }
  461. static void ar9003_hw_set_chain_masks(struct ath_hw *ah, u8 rx, u8 tx)
  462. {
  463. switch (rx) {
  464. case 0x5:
  465. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  466. AR_PHY_SWAP_ALT_CHAIN);
  467. case 0x3:
  468. case 0x1:
  469. case 0x2:
  470. case 0x7:
  471. REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx);
  472. REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx);
  473. break;
  474. default:
  475. break;
  476. }
  477. if ((ah->caps.hw_caps & ATH9K_HW_CAP_APM) && (tx == 0x7))
  478. REG_WRITE(ah, AR_SELFGEN_MASK, 0x3);
  479. else if (AR_SREV_9462(ah))
  480. /* xxx only when MCI support is enabled */
  481. REG_WRITE(ah, AR_SELFGEN_MASK, 0x3);
  482. else
  483. REG_WRITE(ah, AR_SELFGEN_MASK, tx);
  484. if (tx == 0x5) {
  485. REG_SET_BIT(ah, AR_PHY_ANALOG_SWAP,
  486. AR_PHY_SWAP_ALT_CHAIN);
  487. }
  488. }
  489. /*
  490. * Override INI values with chip specific configuration.
  491. */
  492. static void ar9003_hw_override_ini(struct ath_hw *ah)
  493. {
  494. u32 val;
  495. /*
  496. * Set the RX_ABORT and RX_DIS and clear it only after
  497. * RXE is set for MAC. This prevents frames with
  498. * corrupted descriptor status.
  499. */
  500. REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
  501. /*
  502. * For AR9280 and above, there is a new feature that allows
  503. * Multicast search based on both MAC Address and Key ID. By default,
  504. * this feature is enabled. But since the driver is not using this
  505. * feature, we switch it off; otherwise multicast search based on
  506. * MAC addr only will fail.
  507. */
  508. val = REG_READ(ah, AR_PCU_MISC_MODE2) & (~AR_ADHOC_MCAST_KEYID_ENABLE);
  509. REG_WRITE(ah, AR_PCU_MISC_MODE2,
  510. val | AR_AGG_WEP_ENABLE_FIX | AR_AGG_WEP_ENABLE);
  511. REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
  512. AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
  513. }
  514. static void ar9003_hw_prog_ini(struct ath_hw *ah,
  515. struct ar5416IniArray *iniArr,
  516. int column)
  517. {
  518. unsigned int i, regWrites = 0;
  519. /* New INI format: Array may be undefined (pre, core, post arrays) */
  520. if (!iniArr->ia_array)
  521. return;
  522. /*
  523. * New INI format: Pre, core, and post arrays for a given subsystem
  524. * may be modal (> 2 columns) or non-modal (2 columns). Determine if
  525. * the array is non-modal and force the column to 1.
  526. */
  527. if (column >= iniArr->ia_columns)
  528. column = 1;
  529. for (i = 0; i < iniArr->ia_rows; i++) {
  530. u32 reg = INI_RA(iniArr, i, 0);
  531. u32 val = INI_RA(iniArr, i, column);
  532. REG_WRITE(ah, reg, val);
  533. DO_DELAY(regWrites);
  534. }
  535. }
  536. static int ar9003_hw_process_ini(struct ath_hw *ah,
  537. struct ath9k_channel *chan)
  538. {
  539. unsigned int regWrites = 0, i;
  540. u32 modesIndex;
  541. switch (chan->chanmode) {
  542. case CHANNEL_A:
  543. case CHANNEL_A_HT20:
  544. modesIndex = 1;
  545. break;
  546. case CHANNEL_A_HT40PLUS:
  547. case CHANNEL_A_HT40MINUS:
  548. modesIndex = 2;
  549. break;
  550. case CHANNEL_G:
  551. case CHANNEL_G_HT20:
  552. case CHANNEL_B:
  553. modesIndex = 4;
  554. break;
  555. case CHANNEL_G_HT40PLUS:
  556. case CHANNEL_G_HT40MINUS:
  557. modesIndex = 3;
  558. break;
  559. default:
  560. return -EINVAL;
  561. }
  562. for (i = 0; i < ATH_INI_NUM_SPLIT; i++) {
  563. ar9003_hw_prog_ini(ah, &ah->iniSOC[i], modesIndex);
  564. ar9003_hw_prog_ini(ah, &ah->iniMac[i], modesIndex);
  565. ar9003_hw_prog_ini(ah, &ah->iniBB[i], modesIndex);
  566. ar9003_hw_prog_ini(ah, &ah->iniRadio[i], modesIndex);
  567. if (i == ATH_INI_POST && AR_SREV_9462_20(ah))
  568. ar9003_hw_prog_ini(ah,
  569. &ah->ini_radio_post_sys2ant,
  570. modesIndex);
  571. }
  572. REG_WRITE_ARRAY(&ah->iniModesRxGain, 1, regWrites);
  573. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  574. /*
  575. * For 5GHz channels requiring Fast Clock, apply
  576. * different modal values.
  577. */
  578. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  579. REG_WRITE_ARRAY(&ah->iniModesFastClock,
  580. modesIndex, regWrites);
  581. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  582. if (chan->channel == 2484)
  583. ar9003_hw_prog_ini(ah, &ah->ini_japan2484, 1);
  584. if (AR_SREV_9462(ah))
  585. REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
  586. AR_GLB_SWREG_DISCONT_EN_BT_WLAN);
  587. ah->modes_index = modesIndex;
  588. ar9003_hw_override_ini(ah);
  589. ar9003_hw_set_channel_regs(ah, chan);
  590. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  591. ath9k_hw_apply_txpower(ah, chan, false);
  592. if (AR_SREV_9462(ah)) {
  593. if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
  594. AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
  595. ah->enabled_cals |= TX_IQ_CAL;
  596. else
  597. ah->enabled_cals &= ~TX_IQ_CAL;
  598. if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
  599. ah->enabled_cals |= TX_CL_CAL;
  600. else
  601. ah->enabled_cals &= ~TX_CL_CAL;
  602. }
  603. return 0;
  604. }
  605. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  606. struct ath9k_channel *chan)
  607. {
  608. u32 rfMode = 0;
  609. if (chan == NULL)
  610. return;
  611. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  612. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  613. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  614. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  615. if (IS_CHAN_QUARTER_RATE(chan))
  616. rfMode |= AR_PHY_MODE_QUARTER;
  617. if (IS_CHAN_HALF_RATE(chan))
  618. rfMode |= AR_PHY_MODE_HALF;
  619. if (rfMode & (AR_PHY_MODE_QUARTER | AR_PHY_MODE_HALF))
  620. REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL,
  621. AR_PHY_FRAME_CTL_CF_OVERLAP_WINDOW, 3);
  622. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  623. }
  624. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  625. {
  626. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  627. }
  628. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  629. struct ath9k_channel *chan)
  630. {
  631. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  632. u32 clockMhzScaled = 0x64000000;
  633. struct chan_centers centers;
  634. /*
  635. * half and quarter rate can divide the scaled clock by 2 or 4
  636. * scale for selected channel bandwidth
  637. */
  638. if (IS_CHAN_HALF_RATE(chan))
  639. clockMhzScaled = clockMhzScaled >> 1;
  640. else if (IS_CHAN_QUARTER_RATE(chan))
  641. clockMhzScaled = clockMhzScaled >> 2;
  642. /*
  643. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  644. * scaled coef to provide precision for this floating calculation
  645. */
  646. ath9k_hw_get_channel_centers(ah, chan, &centers);
  647. coef_scaled = clockMhzScaled / centers.synth_center;
  648. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  649. &ds_coef_exp);
  650. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  651. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  652. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  653. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  654. /*
  655. * For Short GI,
  656. * scaled coeff is 9/10 that of normal coeff
  657. */
  658. coef_scaled = (9 * coef_scaled) / 10;
  659. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  660. &ds_coef_exp);
  661. /* for short gi */
  662. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  663. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  664. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  665. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  666. }
  667. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  668. {
  669. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  670. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  671. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  672. }
  673. /*
  674. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  675. * Read the phy active delay register. Value is in 100ns increments.
  676. */
  677. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  678. {
  679. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  680. ath9k_hw_synth_delay(ah, ah->curchan, synthDelay);
  681. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  682. }
  683. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  684. enum ath9k_ani_cmd cmd, int param)
  685. {
  686. struct ath_common *common = ath9k_hw_common(ah);
  687. struct ath9k_channel *chan = ah->curchan;
  688. struct ar5416AniState *aniState = &chan->ani;
  689. s32 value, value2;
  690. switch (cmd & ah->ani_function) {
  691. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  692. /*
  693. * on == 1 means ofdm weak signal detection is ON
  694. * on == 1 is the default, for less noise immunity
  695. *
  696. * on == 0 means ofdm weak signal detection is OFF
  697. * on == 0 means more noise imm
  698. */
  699. u32 on = param ? 1 : 0;
  700. if (on)
  701. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  702. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  703. else
  704. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  705. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  706. if (on != aniState->ofdmWeakSigDetect) {
  707. ath_dbg(common, ANI,
  708. "** ch %d: ofdm weak signal: %s=>%s\n",
  709. chan->channel,
  710. aniState->ofdmWeakSigDetect ?
  711. "on" : "off",
  712. on ? "on" : "off");
  713. if (on)
  714. ah->stats.ast_ani_ofdmon++;
  715. else
  716. ah->stats.ast_ani_ofdmoff++;
  717. aniState->ofdmWeakSigDetect = on;
  718. }
  719. break;
  720. }
  721. case ATH9K_ANI_FIRSTEP_LEVEL:{
  722. u32 level = param;
  723. if (level >= ARRAY_SIZE(firstep_table)) {
  724. ath_dbg(common, ANI,
  725. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  726. level, ARRAY_SIZE(firstep_table));
  727. return false;
  728. }
  729. /*
  730. * make register setting relative to default
  731. * from INI file & cap value
  732. */
  733. value = firstep_table[level] -
  734. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  735. aniState->iniDef.firstep;
  736. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  737. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  738. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  739. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  740. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  741. AR_PHY_FIND_SIG_FIRSTEP,
  742. value);
  743. /*
  744. * we need to set first step low register too
  745. * make register setting relative to default
  746. * from INI file & cap value
  747. */
  748. value2 = firstep_table[level] -
  749. firstep_table[ATH9K_ANI_FIRSTEP_LVL] +
  750. aniState->iniDef.firstepLow;
  751. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  752. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  753. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  754. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  755. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  756. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  757. if (level != aniState->firstepLevel) {
  758. ath_dbg(common, ANI,
  759. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  760. chan->channel,
  761. aniState->firstepLevel,
  762. level,
  763. ATH9K_ANI_FIRSTEP_LVL,
  764. value,
  765. aniState->iniDef.firstep);
  766. ath_dbg(common, ANI,
  767. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  768. chan->channel,
  769. aniState->firstepLevel,
  770. level,
  771. ATH9K_ANI_FIRSTEP_LVL,
  772. value2,
  773. aniState->iniDef.firstepLow);
  774. if (level > aniState->firstepLevel)
  775. ah->stats.ast_ani_stepup++;
  776. else if (level < aniState->firstepLevel)
  777. ah->stats.ast_ani_stepdown++;
  778. aniState->firstepLevel = level;
  779. }
  780. break;
  781. }
  782. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  783. u32 level = param;
  784. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  785. ath_dbg(common, ANI,
  786. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  787. level, ARRAY_SIZE(cycpwrThr1_table));
  788. return false;
  789. }
  790. /*
  791. * make register setting relative to default
  792. * from INI file & cap value
  793. */
  794. value = cycpwrThr1_table[level] -
  795. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  796. aniState->iniDef.cycpwrThr1;
  797. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  798. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  799. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  800. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  801. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  802. AR_PHY_TIMING5_CYCPWR_THR1,
  803. value);
  804. /*
  805. * set AR_PHY_EXT_CCA for extension channel
  806. * make register setting relative to default
  807. * from INI file & cap value
  808. */
  809. value2 = cycpwrThr1_table[level] -
  810. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL] +
  811. aniState->iniDef.cycpwrThr1Ext;
  812. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  813. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  814. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  815. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  816. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  817. AR_PHY_EXT_CYCPWR_THR1, value2);
  818. if (level != aniState->spurImmunityLevel) {
  819. ath_dbg(common, ANI,
  820. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  821. chan->channel,
  822. aniState->spurImmunityLevel,
  823. level,
  824. ATH9K_ANI_SPUR_IMMUNE_LVL,
  825. value,
  826. aniState->iniDef.cycpwrThr1);
  827. ath_dbg(common, ANI,
  828. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  829. chan->channel,
  830. aniState->spurImmunityLevel,
  831. level,
  832. ATH9K_ANI_SPUR_IMMUNE_LVL,
  833. value2,
  834. aniState->iniDef.cycpwrThr1Ext);
  835. if (level > aniState->spurImmunityLevel)
  836. ah->stats.ast_ani_spurup++;
  837. else if (level < aniState->spurImmunityLevel)
  838. ah->stats.ast_ani_spurdown++;
  839. aniState->spurImmunityLevel = level;
  840. }
  841. break;
  842. }
  843. case ATH9K_ANI_MRC_CCK:{
  844. /*
  845. * is_on == 1 means MRC CCK ON (default, less noise imm)
  846. * is_on == 0 means MRC CCK is OFF (more noise imm)
  847. */
  848. bool is_on = param ? 1 : 0;
  849. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  850. AR_PHY_MRC_CCK_ENABLE, is_on);
  851. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  852. AR_PHY_MRC_CCK_MUX_REG, is_on);
  853. if (is_on != aniState->mrcCCK) {
  854. ath_dbg(common, ANI, "** ch %d: MRC CCK: %s=>%s\n",
  855. chan->channel,
  856. aniState->mrcCCK ? "on" : "off",
  857. is_on ? "on" : "off");
  858. if (is_on)
  859. ah->stats.ast_ani_ccklow++;
  860. else
  861. ah->stats.ast_ani_cckhigh++;
  862. aniState->mrcCCK = is_on;
  863. }
  864. break;
  865. }
  866. case ATH9K_ANI_PRESENT:
  867. break;
  868. default:
  869. ath_dbg(common, ANI, "invalid cmd %u\n", cmd);
  870. return false;
  871. }
  872. ath_dbg(common, ANI,
  873. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  874. aniState->spurImmunityLevel,
  875. aniState->ofdmWeakSigDetect ? "on" : "off",
  876. aniState->firstepLevel,
  877. aniState->mrcCCK ? "on" : "off",
  878. aniState->listenTime,
  879. aniState->ofdmPhyErrCount,
  880. aniState->cckPhyErrCount);
  881. return true;
  882. }
  883. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  884. int16_t nfarray[NUM_NF_READINGS])
  885. {
  886. #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
  887. #define AR_PHY_CH_MINCCA_PWR_S 20
  888. #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
  889. #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
  890. int16_t nf;
  891. int i;
  892. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  893. if (ah->rxchainmask & BIT(i)) {
  894. nf = MS(REG_READ(ah, ah->nf_regs[i]),
  895. AR_PHY_CH_MINCCA_PWR);
  896. nfarray[i] = sign_extend32(nf, 8);
  897. if (IS_CHAN_HT40(ah->curchan)) {
  898. u8 ext_idx = AR9300_MAX_CHAINS + i;
  899. nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
  900. AR_PHY_CH_EXT_MINCCA_PWR);
  901. nfarray[ext_idx] = sign_extend32(nf, 8);
  902. }
  903. }
  904. }
  905. }
  906. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  907. {
  908. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  909. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  910. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  911. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  912. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  913. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  914. if (AR_SREV_9330(ah))
  915. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9330_2GHZ;
  916. if (AR_SREV_9462(ah)) {
  917. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_2GHZ;
  918. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9462_2GHZ;
  919. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9462_5GHZ;
  920. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9462_5GHZ;
  921. }
  922. }
  923. /*
  924. * Initialize the ANI register values with default (ini) values.
  925. * This routine is called during a (full) hardware reset after
  926. * all the registers are initialised from the INI.
  927. */
  928. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  929. {
  930. struct ar5416AniState *aniState;
  931. struct ath_common *common = ath9k_hw_common(ah);
  932. struct ath9k_channel *chan = ah->curchan;
  933. struct ath9k_ani_default *iniDef;
  934. u32 val;
  935. aniState = &ah->curchan->ani;
  936. iniDef = &aniState->iniDef;
  937. ath_dbg(common, ANI, "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
  938. ah->hw_version.macVersion,
  939. ah->hw_version.macRev,
  940. ah->opmode,
  941. chan->channel,
  942. chan->channelFlags);
  943. val = REG_READ(ah, AR_PHY_SFCORR);
  944. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  945. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  946. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  947. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  948. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  949. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  950. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  951. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  952. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  953. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  954. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  955. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  956. iniDef->firstep = REG_READ_FIELD(ah,
  957. AR_PHY_FIND_SIG,
  958. AR_PHY_FIND_SIG_FIRSTEP);
  959. iniDef->firstepLow = REG_READ_FIELD(ah,
  960. AR_PHY_FIND_SIG_LOW,
  961. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  962. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  963. AR_PHY_TIMING5,
  964. AR_PHY_TIMING5_CYCPWR_THR1);
  965. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  966. AR_PHY_EXT_CCA,
  967. AR_PHY_EXT_CYCPWR_THR1);
  968. /* these levels just got reset to defaults by the INI */
  969. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL;
  970. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL;
  971. aniState->ofdmWeakSigDetect = ATH9K_ANI_USE_OFDM_WEAK_SIG;
  972. aniState->mrcCCK = true;
  973. }
  974. static void ar9003_hw_set_radar_params(struct ath_hw *ah,
  975. struct ath_hw_radar_conf *conf)
  976. {
  977. u32 radar_0 = 0, radar_1 = 0;
  978. if (!conf) {
  979. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  980. return;
  981. }
  982. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  983. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  984. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  985. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  986. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  987. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  988. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  989. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  990. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  991. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  992. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  993. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  994. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  995. if (conf->ext_channel)
  996. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  997. else
  998. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  999. }
  1000. static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
  1001. {
  1002. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1003. conf->fir_power = -28;
  1004. conf->radar_rssi = 0;
  1005. conf->pulse_height = 10;
  1006. conf->pulse_rssi = 24;
  1007. conf->pulse_inband = 8;
  1008. conf->pulse_maxlen = 255;
  1009. conf->pulse_inband_step = 12;
  1010. conf->radar_inband = 8;
  1011. }
  1012. static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  1013. struct ath_hw_antcomb_conf *antconf)
  1014. {
  1015. u32 regval;
  1016. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1017. antconf->main_lna_conf = (regval & AR_PHY_9485_ANT_DIV_MAIN_LNACONF) >>
  1018. AR_PHY_9485_ANT_DIV_MAIN_LNACONF_S;
  1019. antconf->alt_lna_conf = (regval & AR_PHY_9485_ANT_DIV_ALT_LNACONF) >>
  1020. AR_PHY_9485_ANT_DIV_ALT_LNACONF_S;
  1021. antconf->fast_div_bias = (regval & AR_PHY_9485_ANT_FAST_DIV_BIAS) >>
  1022. AR_PHY_9485_ANT_FAST_DIV_BIAS_S;
  1023. if (AR_SREV_9330_11(ah)) {
  1024. antconf->lna1_lna2_delta = -9;
  1025. antconf->div_group = 1;
  1026. } else if (AR_SREV_9485(ah)) {
  1027. antconf->lna1_lna2_delta = -9;
  1028. antconf->div_group = 2;
  1029. } else {
  1030. antconf->lna1_lna2_delta = -3;
  1031. antconf->div_group = 0;
  1032. }
  1033. }
  1034. static void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  1035. struct ath_hw_antcomb_conf *antconf)
  1036. {
  1037. u32 regval;
  1038. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1039. regval &= ~(AR_PHY_9485_ANT_DIV_MAIN_LNACONF |
  1040. AR_PHY_9485_ANT_DIV_ALT_LNACONF |
  1041. AR_PHY_9485_ANT_FAST_DIV_BIAS |
  1042. AR_PHY_9485_ANT_DIV_MAIN_GAINTB |
  1043. AR_PHY_9485_ANT_DIV_ALT_GAINTB);
  1044. regval |= ((antconf->main_lna_conf <<
  1045. AR_PHY_9485_ANT_DIV_MAIN_LNACONF_S)
  1046. & AR_PHY_9485_ANT_DIV_MAIN_LNACONF);
  1047. regval |= ((antconf->alt_lna_conf << AR_PHY_9485_ANT_DIV_ALT_LNACONF_S)
  1048. & AR_PHY_9485_ANT_DIV_ALT_LNACONF);
  1049. regval |= ((antconf->fast_div_bias << AR_PHY_9485_ANT_FAST_DIV_BIAS_S)
  1050. & AR_PHY_9485_ANT_FAST_DIV_BIAS);
  1051. regval |= ((antconf->main_gaintb << AR_PHY_9485_ANT_DIV_MAIN_GAINTB_S)
  1052. & AR_PHY_9485_ANT_DIV_MAIN_GAINTB);
  1053. regval |= ((antconf->alt_gaintb << AR_PHY_9485_ANT_DIV_ALT_GAINTB_S)
  1054. & AR_PHY_9485_ANT_DIV_ALT_GAINTB);
  1055. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1056. }
  1057. static int ar9003_hw_fast_chan_change(struct ath_hw *ah,
  1058. struct ath9k_channel *chan,
  1059. u8 *ini_reloaded)
  1060. {
  1061. unsigned int regWrites = 0;
  1062. u32 modesIndex;
  1063. switch (chan->chanmode) {
  1064. case CHANNEL_A:
  1065. case CHANNEL_A_HT20:
  1066. modesIndex = 1;
  1067. break;
  1068. case CHANNEL_A_HT40PLUS:
  1069. case CHANNEL_A_HT40MINUS:
  1070. modesIndex = 2;
  1071. break;
  1072. case CHANNEL_G:
  1073. case CHANNEL_G_HT20:
  1074. case CHANNEL_B:
  1075. modesIndex = 4;
  1076. break;
  1077. case CHANNEL_G_HT40PLUS:
  1078. case CHANNEL_G_HT40MINUS:
  1079. modesIndex = 3;
  1080. break;
  1081. default:
  1082. return -EINVAL;
  1083. }
  1084. if (modesIndex == ah->modes_index) {
  1085. *ini_reloaded = false;
  1086. goto set_rfmode;
  1087. }
  1088. ar9003_hw_prog_ini(ah, &ah->iniSOC[ATH_INI_POST], modesIndex);
  1089. ar9003_hw_prog_ini(ah, &ah->iniMac[ATH_INI_POST], modesIndex);
  1090. ar9003_hw_prog_ini(ah, &ah->iniBB[ATH_INI_POST], modesIndex);
  1091. ar9003_hw_prog_ini(ah, &ah->iniRadio[ATH_INI_POST], modesIndex);
  1092. if (AR_SREV_9462_20(ah))
  1093. ar9003_hw_prog_ini(ah,
  1094. &ah->ini_radio_post_sys2ant,
  1095. modesIndex);
  1096. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  1097. /*
  1098. * For 5GHz channels requiring Fast Clock, apply
  1099. * different modal values.
  1100. */
  1101. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  1102. REG_WRITE_ARRAY(&ah->iniModesFastClock, modesIndex, regWrites);
  1103. REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
  1104. ah->modes_index = modesIndex;
  1105. *ini_reloaded = true;
  1106. set_rfmode:
  1107. ar9003_hw_set_rfmode(ah, chan);
  1108. return 0;
  1109. }
  1110. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  1111. {
  1112. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1113. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  1114. static const u32 ar9300_cca_regs[6] = {
  1115. AR_PHY_CCA_0,
  1116. AR_PHY_CCA_1,
  1117. AR_PHY_CCA_2,
  1118. AR_PHY_EXT_CCA,
  1119. AR_PHY_EXT_CCA_1,
  1120. AR_PHY_EXT_CCA_2,
  1121. };
  1122. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  1123. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  1124. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  1125. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  1126. priv_ops->init_bb = ar9003_hw_init_bb;
  1127. priv_ops->process_ini = ar9003_hw_process_ini;
  1128. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1129. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1130. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1131. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1132. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1133. priv_ops->ani_control = ar9003_hw_ani_control;
  1134. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1135. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1136. priv_ops->set_radar_params = ar9003_hw_set_radar_params;
  1137. priv_ops->fast_chan_change = ar9003_hw_fast_chan_change;
  1138. ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
  1139. ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
  1140. ar9003_hw_set_nf_limits(ah);
  1141. ar9003_hw_set_radar_conf(ah);
  1142. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1143. }
  1144. void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
  1145. {
  1146. struct ath_common *common = ath9k_hw_common(ah);
  1147. u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
  1148. u32 val, idle_count;
  1149. if (!idle_tmo_ms) {
  1150. /* disable IRQ, disable chip-reset for BB panic */
  1151. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1152. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
  1153. ~(AR_PHY_WATCHDOG_RST_ENABLE |
  1154. AR_PHY_WATCHDOG_IRQ_ENABLE));
  1155. /* disable watchdog in non-IDLE mode, disable in IDLE mode */
  1156. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1157. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
  1158. ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1159. AR_PHY_WATCHDOG_IDLE_ENABLE));
  1160. ath_dbg(common, RESET, "Disabled BB Watchdog\n");
  1161. return;
  1162. }
  1163. /* enable IRQ, disable chip-reset for BB watchdog */
  1164. val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
  1165. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1166. (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
  1167. ~AR_PHY_WATCHDOG_RST_ENABLE);
  1168. /* bound limit to 10 secs */
  1169. if (idle_tmo_ms > 10000)
  1170. idle_tmo_ms = 10000;
  1171. /*
  1172. * The time unit for watchdog event is 2^15 44/88MHz cycles.
  1173. *
  1174. * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
  1175. * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
  1176. *
  1177. * Given we use fast clock now in 5 GHz, these time units should
  1178. * be common for both 2 GHz and 5 GHz.
  1179. */
  1180. idle_count = (100 * idle_tmo_ms) / 74;
  1181. if (ah->curchan && IS_CHAN_HT40(ah->curchan))
  1182. idle_count = (100 * idle_tmo_ms) / 37;
  1183. /*
  1184. * enable watchdog in non-IDLE mode, disable in IDLE mode,
  1185. * set idle time-out.
  1186. */
  1187. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1188. AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1189. AR_PHY_WATCHDOG_IDLE_MASK |
  1190. (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
  1191. ath_dbg(common, RESET, "Enabled BB Watchdog timeout (%u ms)\n",
  1192. idle_tmo_ms);
  1193. }
  1194. void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
  1195. {
  1196. /*
  1197. * we want to avoid printing in ISR context so we save the
  1198. * watchdog status to be printed later in bottom half context.
  1199. */
  1200. ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
  1201. /*
  1202. * the watchdog timer should reset on status read but to be sure
  1203. * sure we write 0 to the watchdog status bit.
  1204. */
  1205. REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
  1206. ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
  1207. }
  1208. void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
  1209. {
  1210. struct ath_common *common = ath9k_hw_common(ah);
  1211. u32 status;
  1212. if (likely(!(common->debug_mask & ATH_DBG_RESET)))
  1213. return;
  1214. status = ah->bb_watchdog_last_status;
  1215. ath_dbg(common, RESET,
  1216. "\n==== BB update: BB status=0x%08x ====\n", status);
  1217. ath_dbg(common, RESET,
  1218. "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
  1219. MS(status, AR_PHY_WATCHDOG_INFO),
  1220. MS(status, AR_PHY_WATCHDOG_DET_HANG),
  1221. MS(status, AR_PHY_WATCHDOG_RADAR_SM),
  1222. MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
  1223. MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
  1224. MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
  1225. MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
  1226. MS(status, AR_PHY_WATCHDOG_AGC_SM),
  1227. MS(status, AR_PHY_WATCHDOG_SRCH_SM));
  1228. ath_dbg(common, RESET, "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
  1229. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
  1230. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
  1231. ath_dbg(common, RESET, "** BB mode: BB_gen_controls=0x%08x **\n",
  1232. REG_READ(ah, AR_PHY_GEN_CTRL));
  1233. #define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
  1234. if (common->cc_survey.cycles)
  1235. ath_dbg(common, RESET,
  1236. "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
  1237. PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
  1238. ath_dbg(common, RESET, "==== BB update: done ====\n\n");
  1239. }
  1240. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);
  1241. void ar9003_hw_disable_phy_restart(struct ath_hw *ah)
  1242. {
  1243. u32 val;
  1244. /* While receiving unsupported rate frame rx state machine
  1245. * gets into a state 0xb and if phy_restart happens in that
  1246. * state, BB would go hang. If RXSM is in 0xb state after
  1247. * first bb panic, ensure to disable the phy_restart.
  1248. */
  1249. if (!((MS(ah->bb_watchdog_last_status,
  1250. AR_PHY_WATCHDOG_RX_OFDM_SM) == 0xb) ||
  1251. ah->bb_hang_rx_ofdm))
  1252. return;
  1253. ah->bb_hang_rx_ofdm = true;
  1254. val = REG_READ(ah, AR_PHY_RESTART);
  1255. val &= ~AR_PHY_RESTART_ENA;
  1256. REG_WRITE(ah, AR_PHY_RESTART, val);
  1257. }
  1258. EXPORT_SYMBOL(ar9003_hw_disable_phy_restart);