ar9003_phy.c 43 KB

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