ar9003_phy.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  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_9462(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_9462_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_9462(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. if (AR_SREV_9462(ah)) {
  602. if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
  603. AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
  604. ah->enabled_cals |= TX_IQ_CAL;
  605. else
  606. ah->enabled_cals &= ~TX_IQ_CAL;
  607. if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
  608. ah->enabled_cals |= TX_CL_CAL;
  609. else
  610. ah->enabled_cals &= ~TX_CL_CAL;
  611. }
  612. return 0;
  613. }
  614. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  615. struct ath9k_channel *chan)
  616. {
  617. u32 rfMode = 0;
  618. if (chan == NULL)
  619. return;
  620. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  621. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  622. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  623. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  624. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  625. }
  626. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  627. {
  628. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  629. }
  630. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  631. struct ath9k_channel *chan)
  632. {
  633. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  634. u32 clockMhzScaled = 0x64000000;
  635. struct chan_centers centers;
  636. /*
  637. * half and quarter rate can divide the scaled clock by 2 or 4
  638. * scale for selected channel bandwidth
  639. */
  640. if (IS_CHAN_HALF_RATE(chan))
  641. clockMhzScaled = clockMhzScaled >> 1;
  642. else if (IS_CHAN_QUARTER_RATE(chan))
  643. clockMhzScaled = clockMhzScaled >> 2;
  644. /*
  645. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  646. * scaled coef to provide precision for this floating calculation
  647. */
  648. ath9k_hw_get_channel_centers(ah, chan, &centers);
  649. coef_scaled = clockMhzScaled / centers.synth_center;
  650. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  651. &ds_coef_exp);
  652. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  653. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  654. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  655. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  656. /*
  657. * For Short GI,
  658. * scaled coeff is 9/10 that of normal coeff
  659. */
  660. coef_scaled = (9 * coef_scaled) / 10;
  661. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  662. &ds_coef_exp);
  663. /* for short gi */
  664. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  665. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  666. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  667. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  668. }
  669. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  670. {
  671. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  672. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  673. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  674. }
  675. /*
  676. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  677. * Read the phy active delay register. Value is in 100ns increments.
  678. */
  679. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  680. {
  681. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  682. if (IS_CHAN_B(ah->curchan))
  683. synthDelay = (4 * synthDelay) / 22;
  684. else
  685. synthDelay /= 10;
  686. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  687. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  688. }
  689. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  690. enum ath9k_ani_cmd cmd, int param)
  691. {
  692. struct ath_common *common = ath9k_hw_common(ah);
  693. struct ath9k_channel *chan = ah->curchan;
  694. struct ar5416AniState *aniState = &chan->ani;
  695. s32 value, value2;
  696. switch (cmd & ah->ani_function) {
  697. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  698. /*
  699. * on == 1 means ofdm weak signal detection is ON
  700. * on == 1 is the default, for less noise immunity
  701. *
  702. * on == 0 means ofdm weak signal detection is OFF
  703. * on == 0 means more noise imm
  704. */
  705. u32 on = param ? 1 : 0;
  706. /*
  707. * make register setting for default
  708. * (weak sig detect ON) come from INI file
  709. */
  710. int m1ThreshLow = on ?
  711. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  712. int m2ThreshLow = on ?
  713. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  714. int m1Thresh = on ?
  715. aniState->iniDef.m1Thresh : m1Thresh_off;
  716. int m2Thresh = on ?
  717. aniState->iniDef.m2Thresh : m2Thresh_off;
  718. int m2CountThr = on ?
  719. aniState->iniDef.m2CountThr : m2CountThr_off;
  720. int m2CountThrLow = on ?
  721. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  722. int m1ThreshLowExt = on ?
  723. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  724. int m2ThreshLowExt = on ?
  725. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  726. int m1ThreshExt = on ?
  727. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  728. int m2ThreshExt = on ?
  729. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  730. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  731. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  732. m1ThreshLow);
  733. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  734. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  735. m2ThreshLow);
  736. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  737. AR_PHY_SFCORR_M1_THRESH, m1Thresh);
  738. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  739. AR_PHY_SFCORR_M2_THRESH, m2Thresh);
  740. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  741. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
  742. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  743. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  744. m2CountThrLow);
  745. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  746. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
  747. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  748. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
  749. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  750. AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
  751. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  752. AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
  753. if (on)
  754. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  755. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  756. else
  757. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  758. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  759. if (!on != aniState->ofdmWeakSigDetectOff) {
  760. ath_dbg(common, ATH_DBG_ANI,
  761. "** ch %d: ofdm weak signal: %s=>%s\n",
  762. chan->channel,
  763. !aniState->ofdmWeakSigDetectOff ?
  764. "on" : "off",
  765. on ? "on" : "off");
  766. if (on)
  767. ah->stats.ast_ani_ofdmon++;
  768. else
  769. ah->stats.ast_ani_ofdmoff++;
  770. aniState->ofdmWeakSigDetectOff = !on;
  771. }
  772. break;
  773. }
  774. case ATH9K_ANI_FIRSTEP_LEVEL:{
  775. u32 level = param;
  776. if (level >= ARRAY_SIZE(firstep_table)) {
  777. ath_dbg(common, ATH_DBG_ANI,
  778. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  779. level, ARRAY_SIZE(firstep_table));
  780. return false;
  781. }
  782. /*
  783. * make register setting relative to default
  784. * from INI file & cap value
  785. */
  786. value = firstep_table[level] -
  787. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  788. aniState->iniDef.firstep;
  789. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  790. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  791. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  792. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  793. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  794. AR_PHY_FIND_SIG_FIRSTEP,
  795. value);
  796. /*
  797. * we need to set first step low register too
  798. * make register setting relative to default
  799. * from INI file & cap value
  800. */
  801. value2 = firstep_table[level] -
  802. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  803. aniState->iniDef.firstepLow;
  804. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  805. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  806. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  807. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  808. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  809. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  810. if (level != aniState->firstepLevel) {
  811. ath_dbg(common, ATH_DBG_ANI,
  812. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  813. chan->channel,
  814. aniState->firstepLevel,
  815. level,
  816. ATH9K_ANI_FIRSTEP_LVL_NEW,
  817. value,
  818. aniState->iniDef.firstep);
  819. ath_dbg(common, ATH_DBG_ANI,
  820. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  821. chan->channel,
  822. aniState->firstepLevel,
  823. level,
  824. ATH9K_ANI_FIRSTEP_LVL_NEW,
  825. value2,
  826. aniState->iniDef.firstepLow);
  827. if (level > aniState->firstepLevel)
  828. ah->stats.ast_ani_stepup++;
  829. else if (level < aniState->firstepLevel)
  830. ah->stats.ast_ani_stepdown++;
  831. aniState->firstepLevel = level;
  832. }
  833. break;
  834. }
  835. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  836. u32 level = param;
  837. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  838. ath_dbg(common, ATH_DBG_ANI,
  839. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  840. level, ARRAY_SIZE(cycpwrThr1_table));
  841. return false;
  842. }
  843. /*
  844. * make register setting relative to default
  845. * from INI file & cap value
  846. */
  847. value = cycpwrThr1_table[level] -
  848. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  849. aniState->iniDef.cycpwrThr1;
  850. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  851. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  852. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  853. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  854. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  855. AR_PHY_TIMING5_CYCPWR_THR1,
  856. value);
  857. /*
  858. * set AR_PHY_EXT_CCA for extension channel
  859. * make register setting relative to default
  860. * from INI file & cap value
  861. */
  862. value2 = cycpwrThr1_table[level] -
  863. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  864. aniState->iniDef.cycpwrThr1Ext;
  865. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  866. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  867. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  868. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  869. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  870. AR_PHY_EXT_CYCPWR_THR1, value2);
  871. if (level != aniState->spurImmunityLevel) {
  872. ath_dbg(common, ATH_DBG_ANI,
  873. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  874. chan->channel,
  875. aniState->spurImmunityLevel,
  876. level,
  877. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  878. value,
  879. aniState->iniDef.cycpwrThr1);
  880. ath_dbg(common, ATH_DBG_ANI,
  881. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  882. chan->channel,
  883. aniState->spurImmunityLevel,
  884. level,
  885. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  886. value2,
  887. aniState->iniDef.cycpwrThr1Ext);
  888. if (level > aniState->spurImmunityLevel)
  889. ah->stats.ast_ani_spurup++;
  890. else if (level < aniState->spurImmunityLevel)
  891. ah->stats.ast_ani_spurdown++;
  892. aniState->spurImmunityLevel = level;
  893. }
  894. break;
  895. }
  896. case ATH9K_ANI_MRC_CCK:{
  897. /*
  898. * is_on == 1 means MRC CCK ON (default, less noise imm)
  899. * is_on == 0 means MRC CCK is OFF (more noise imm)
  900. */
  901. bool is_on = param ? 1 : 0;
  902. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  903. AR_PHY_MRC_CCK_ENABLE, is_on);
  904. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  905. AR_PHY_MRC_CCK_MUX_REG, is_on);
  906. if (!is_on != aniState->mrcCCKOff) {
  907. ath_dbg(common, ATH_DBG_ANI,
  908. "** ch %d: MRC CCK: %s=>%s\n",
  909. chan->channel,
  910. !aniState->mrcCCKOff ? "on" : "off",
  911. is_on ? "on" : "off");
  912. if (is_on)
  913. ah->stats.ast_ani_ccklow++;
  914. else
  915. ah->stats.ast_ani_cckhigh++;
  916. aniState->mrcCCKOff = !is_on;
  917. }
  918. break;
  919. }
  920. case ATH9K_ANI_PRESENT:
  921. break;
  922. default:
  923. ath_dbg(common, ATH_DBG_ANI, "invalid cmd %u\n", cmd);
  924. return false;
  925. }
  926. ath_dbg(common, ATH_DBG_ANI,
  927. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  928. aniState->spurImmunityLevel,
  929. !aniState->ofdmWeakSigDetectOff ? "on" : "off",
  930. aniState->firstepLevel,
  931. !aniState->mrcCCKOff ? "on" : "off",
  932. aniState->listenTime,
  933. aniState->ofdmPhyErrCount,
  934. aniState->cckPhyErrCount);
  935. return true;
  936. }
  937. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  938. int16_t nfarray[NUM_NF_READINGS])
  939. {
  940. #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
  941. #define AR_PHY_CH_MINCCA_PWR_S 20
  942. #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
  943. #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
  944. int16_t nf;
  945. int i;
  946. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  947. if (ah->rxchainmask & BIT(i)) {
  948. nf = MS(REG_READ(ah, ah->nf_regs[i]),
  949. AR_PHY_CH_MINCCA_PWR);
  950. nfarray[i] = sign_extend32(nf, 8);
  951. if (IS_CHAN_HT40(ah->curchan)) {
  952. u8 ext_idx = AR9300_MAX_CHAINS + i;
  953. nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
  954. AR_PHY_CH_EXT_MINCCA_PWR);
  955. nfarray[ext_idx] = sign_extend32(nf, 8);
  956. }
  957. }
  958. }
  959. }
  960. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  961. {
  962. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  963. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  964. if (AR_SREV_9330(ah))
  965. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9330_2GHZ;
  966. else
  967. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  968. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  969. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  970. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  971. }
  972. /*
  973. * Initialize the ANI register values with default (ini) values.
  974. * This routine is called during a (full) hardware reset after
  975. * all the registers are initialised from the INI.
  976. */
  977. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  978. {
  979. struct ar5416AniState *aniState;
  980. struct ath_common *common = ath9k_hw_common(ah);
  981. struct ath9k_channel *chan = ah->curchan;
  982. struct ath9k_ani_default *iniDef;
  983. u32 val;
  984. aniState = &ah->curchan->ani;
  985. iniDef = &aniState->iniDef;
  986. ath_dbg(common, ATH_DBG_ANI,
  987. "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
  988. ah->hw_version.macVersion,
  989. ah->hw_version.macRev,
  990. ah->opmode,
  991. chan->channel,
  992. chan->channelFlags);
  993. val = REG_READ(ah, AR_PHY_SFCORR);
  994. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  995. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  996. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  997. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  998. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  999. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  1000. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  1001. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  1002. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  1003. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  1004. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  1005. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  1006. iniDef->firstep = REG_READ_FIELD(ah,
  1007. AR_PHY_FIND_SIG,
  1008. AR_PHY_FIND_SIG_FIRSTEP);
  1009. iniDef->firstepLow = REG_READ_FIELD(ah,
  1010. AR_PHY_FIND_SIG_LOW,
  1011. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  1012. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  1013. AR_PHY_TIMING5,
  1014. AR_PHY_TIMING5_CYCPWR_THR1);
  1015. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  1016. AR_PHY_EXT_CCA,
  1017. AR_PHY_EXT_CYCPWR_THR1);
  1018. /* these levels just got reset to defaults by the INI */
  1019. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
  1020. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
  1021. aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
  1022. aniState->mrcCCKOff = !ATH9K_ANI_ENABLE_MRC_CCK;
  1023. }
  1024. static void ar9003_hw_set_radar_params(struct ath_hw *ah,
  1025. struct ath_hw_radar_conf *conf)
  1026. {
  1027. u32 radar_0 = 0, radar_1 = 0;
  1028. if (!conf) {
  1029. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  1030. return;
  1031. }
  1032. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  1033. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1034. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1035. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1036. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1037. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1038. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1039. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1040. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1041. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1042. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1043. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1044. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1045. if (conf->ext_channel)
  1046. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1047. else
  1048. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1049. }
  1050. static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
  1051. {
  1052. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1053. conf->fir_power = -28;
  1054. conf->radar_rssi = 0;
  1055. conf->pulse_height = 10;
  1056. conf->pulse_rssi = 24;
  1057. conf->pulse_inband = 8;
  1058. conf->pulse_maxlen = 255;
  1059. conf->pulse_inband_step = 12;
  1060. conf->radar_inband = 8;
  1061. }
  1062. static void ar9003_hw_antdiv_comb_conf_get(struct ath_hw *ah,
  1063. struct ath_hw_antcomb_conf *antconf)
  1064. {
  1065. u32 regval;
  1066. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1067. antconf->main_lna_conf = (regval & AR_PHY_9485_ANT_DIV_MAIN_LNACONF) >>
  1068. AR_PHY_9485_ANT_DIV_MAIN_LNACONF_S;
  1069. antconf->alt_lna_conf = (regval & AR_PHY_9485_ANT_DIV_ALT_LNACONF) >>
  1070. AR_PHY_9485_ANT_DIV_ALT_LNACONF_S;
  1071. antconf->fast_div_bias = (regval & AR_PHY_9485_ANT_FAST_DIV_BIAS) >>
  1072. AR_PHY_9485_ANT_FAST_DIV_BIAS_S;
  1073. if (AR_SREV_9330_11(ah)) {
  1074. antconf->lna1_lna2_delta = -9;
  1075. antconf->div_group = 1;
  1076. } else if (AR_SREV_9485(ah)) {
  1077. antconf->lna1_lna2_delta = -9;
  1078. antconf->div_group = 2;
  1079. } else {
  1080. antconf->lna1_lna2_delta = -3;
  1081. antconf->div_group = 0;
  1082. }
  1083. }
  1084. static void ar9003_hw_antdiv_comb_conf_set(struct ath_hw *ah,
  1085. struct ath_hw_antcomb_conf *antconf)
  1086. {
  1087. u32 regval;
  1088. regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
  1089. regval &= ~(AR_PHY_9485_ANT_DIV_MAIN_LNACONF |
  1090. AR_PHY_9485_ANT_DIV_ALT_LNACONF |
  1091. AR_PHY_9485_ANT_FAST_DIV_BIAS |
  1092. AR_PHY_9485_ANT_DIV_MAIN_GAINTB |
  1093. AR_PHY_9485_ANT_DIV_ALT_GAINTB);
  1094. regval |= ((antconf->main_lna_conf <<
  1095. AR_PHY_9485_ANT_DIV_MAIN_LNACONF_S)
  1096. & AR_PHY_9485_ANT_DIV_MAIN_LNACONF);
  1097. regval |= ((antconf->alt_lna_conf << AR_PHY_9485_ANT_DIV_ALT_LNACONF_S)
  1098. & AR_PHY_9485_ANT_DIV_ALT_LNACONF);
  1099. regval |= ((antconf->fast_div_bias << AR_PHY_9485_ANT_FAST_DIV_BIAS_S)
  1100. & AR_PHY_9485_ANT_FAST_DIV_BIAS);
  1101. regval |= ((antconf->main_gaintb << AR_PHY_9485_ANT_DIV_MAIN_GAINTB_S)
  1102. & AR_PHY_9485_ANT_DIV_MAIN_GAINTB);
  1103. regval |= ((antconf->alt_gaintb << AR_PHY_9485_ANT_DIV_ALT_GAINTB_S)
  1104. & AR_PHY_9485_ANT_DIV_ALT_GAINTB);
  1105. REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
  1106. }
  1107. static int ar9003_hw_fast_chan_change(struct ath_hw *ah,
  1108. struct ath9k_channel *chan,
  1109. u8 *ini_reloaded)
  1110. {
  1111. unsigned int regWrites = 0;
  1112. u32 modesIndex;
  1113. switch (chan->chanmode) {
  1114. case CHANNEL_A:
  1115. case CHANNEL_A_HT20:
  1116. modesIndex = 1;
  1117. break;
  1118. case CHANNEL_A_HT40PLUS:
  1119. case CHANNEL_A_HT40MINUS:
  1120. modesIndex = 2;
  1121. break;
  1122. case CHANNEL_G:
  1123. case CHANNEL_G_HT20:
  1124. case CHANNEL_B:
  1125. modesIndex = 4;
  1126. break;
  1127. case CHANNEL_G_HT40PLUS:
  1128. case CHANNEL_G_HT40MINUS:
  1129. modesIndex = 3;
  1130. break;
  1131. default:
  1132. return -EINVAL;
  1133. }
  1134. if (modesIndex == ah->modes_index) {
  1135. *ini_reloaded = false;
  1136. goto set_rfmode;
  1137. }
  1138. ar9003_hw_prog_ini(ah, &ah->iniSOC[ATH_INI_POST], modesIndex);
  1139. ar9003_hw_prog_ini(ah, &ah->iniMac[ATH_INI_POST], modesIndex);
  1140. ar9003_hw_prog_ini(ah, &ah->iniBB[ATH_INI_POST], modesIndex);
  1141. ar9003_hw_prog_ini(ah, &ah->iniRadio[ATH_INI_POST], modesIndex);
  1142. if (AR_SREV_9462_20(ah))
  1143. ar9003_hw_prog_ini(ah,
  1144. &ah->ini_radio_post_sys2ant,
  1145. modesIndex);
  1146. REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
  1147. /*
  1148. * For 5GHz channels requiring Fast Clock, apply
  1149. * different modal values.
  1150. */
  1151. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  1152. REG_WRITE_ARRAY(&ah->iniModesAdditional, modesIndex, regWrites);
  1153. if (AR_SREV_9330(ah))
  1154. REG_WRITE_ARRAY(&ah->iniModesAdditional, 1, regWrites);
  1155. if (AR_SREV_9340(ah) && !ah->is_clk_25mhz)
  1156. REG_WRITE_ARRAY(&ah->iniModesAdditional_40M, 1, regWrites);
  1157. ah->modes_index = modesIndex;
  1158. *ini_reloaded = true;
  1159. set_rfmode:
  1160. ar9003_hw_set_rfmode(ah, chan);
  1161. return 0;
  1162. }
  1163. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  1164. {
  1165. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1166. struct ath_hw_ops *ops = ath9k_hw_ops(ah);
  1167. static const u32 ar9300_cca_regs[6] = {
  1168. AR_PHY_CCA_0,
  1169. AR_PHY_CCA_1,
  1170. AR_PHY_CCA_2,
  1171. AR_PHY_EXT_CCA,
  1172. AR_PHY_EXT_CCA_1,
  1173. AR_PHY_EXT_CCA_2,
  1174. };
  1175. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  1176. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  1177. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  1178. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  1179. priv_ops->init_bb = ar9003_hw_init_bb;
  1180. priv_ops->process_ini = ar9003_hw_process_ini;
  1181. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1182. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1183. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1184. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1185. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1186. priv_ops->ani_control = ar9003_hw_ani_control;
  1187. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1188. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1189. priv_ops->set_radar_params = ar9003_hw_set_radar_params;
  1190. priv_ops->fast_chan_change = ar9003_hw_fast_chan_change;
  1191. ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
  1192. ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
  1193. ar9003_hw_set_nf_limits(ah);
  1194. ar9003_hw_set_radar_conf(ah);
  1195. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1196. }
  1197. void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
  1198. {
  1199. struct ath_common *common = ath9k_hw_common(ah);
  1200. u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
  1201. u32 val, idle_count;
  1202. if (!idle_tmo_ms) {
  1203. /* disable IRQ, disable chip-reset for BB panic */
  1204. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1205. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
  1206. ~(AR_PHY_WATCHDOG_RST_ENABLE |
  1207. AR_PHY_WATCHDOG_IRQ_ENABLE));
  1208. /* disable watchdog in non-IDLE mode, disable in IDLE mode */
  1209. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1210. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
  1211. ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1212. AR_PHY_WATCHDOG_IDLE_ENABLE));
  1213. ath_dbg(common, ATH_DBG_RESET, "Disabled BB Watchdog\n");
  1214. return;
  1215. }
  1216. /* enable IRQ, disable chip-reset for BB watchdog */
  1217. val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
  1218. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1219. (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
  1220. ~AR_PHY_WATCHDOG_RST_ENABLE);
  1221. /* bound limit to 10 secs */
  1222. if (idle_tmo_ms > 10000)
  1223. idle_tmo_ms = 10000;
  1224. /*
  1225. * The time unit for watchdog event is 2^15 44/88MHz cycles.
  1226. *
  1227. * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
  1228. * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
  1229. *
  1230. * Given we use fast clock now in 5 GHz, these time units should
  1231. * be common for both 2 GHz and 5 GHz.
  1232. */
  1233. idle_count = (100 * idle_tmo_ms) / 74;
  1234. if (ah->curchan && IS_CHAN_HT40(ah->curchan))
  1235. idle_count = (100 * idle_tmo_ms) / 37;
  1236. /*
  1237. * enable watchdog in non-IDLE mode, disable in IDLE mode,
  1238. * set idle time-out.
  1239. */
  1240. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1241. AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1242. AR_PHY_WATCHDOG_IDLE_MASK |
  1243. (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
  1244. ath_dbg(common, ATH_DBG_RESET,
  1245. "Enabled BB Watchdog timeout (%u ms)\n",
  1246. idle_tmo_ms);
  1247. }
  1248. void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
  1249. {
  1250. /*
  1251. * we want to avoid printing in ISR context so we save the
  1252. * watchdog status to be printed later in bottom half context.
  1253. */
  1254. ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
  1255. /*
  1256. * the watchdog timer should reset on status read but to be sure
  1257. * sure we write 0 to the watchdog status bit.
  1258. */
  1259. REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
  1260. ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
  1261. }
  1262. void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
  1263. {
  1264. struct ath_common *common = ath9k_hw_common(ah);
  1265. u32 status;
  1266. if (likely(!(common->debug_mask & ATH_DBG_RESET)))
  1267. return;
  1268. status = ah->bb_watchdog_last_status;
  1269. ath_dbg(common, ATH_DBG_RESET,
  1270. "\n==== BB update: BB status=0x%08x ====\n", status);
  1271. ath_dbg(common, ATH_DBG_RESET,
  1272. "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
  1273. MS(status, AR_PHY_WATCHDOG_INFO),
  1274. MS(status, AR_PHY_WATCHDOG_DET_HANG),
  1275. MS(status, AR_PHY_WATCHDOG_RADAR_SM),
  1276. MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
  1277. MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
  1278. MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
  1279. MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
  1280. MS(status, AR_PHY_WATCHDOG_AGC_SM),
  1281. MS(status, AR_PHY_WATCHDOG_SRCH_SM));
  1282. ath_dbg(common, ATH_DBG_RESET,
  1283. "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
  1284. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
  1285. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
  1286. ath_dbg(common, ATH_DBG_RESET,
  1287. "** BB mode: BB_gen_controls=0x%08x **\n",
  1288. REG_READ(ah, AR_PHY_GEN_CTRL));
  1289. #define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
  1290. if (common->cc_survey.cycles)
  1291. ath_dbg(common, ATH_DBG_RESET,
  1292. "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
  1293. PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
  1294. ath_dbg(common, ATH_DBG_RESET,
  1295. "==== BB update: done ====\n\n");
  1296. }
  1297. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);
  1298. void ar9003_hw_disable_phy_restart(struct ath_hw *ah)
  1299. {
  1300. u32 val;
  1301. /* While receiving unsupported rate frame rx state machine
  1302. * gets into a state 0xb and if phy_restart happens in that
  1303. * state, BB would go hang. If RXSM is in 0xb state after
  1304. * first bb panic, ensure to disable the phy_restart.
  1305. */
  1306. if (!((MS(ah->bb_watchdog_last_status,
  1307. AR_PHY_WATCHDOG_RX_OFDM_SM) == 0xb) ||
  1308. ah->bb_hang_rx_ofdm))
  1309. return;
  1310. ah->bb_hang_rx_ofdm = true;
  1311. val = REG_READ(ah, AR_PHY_RESTART);
  1312. val &= ~AR_PHY_RESTART_ENA;
  1313. REG_WRITE(ah, AR_PHY_RESTART, val);
  1314. }
  1315. EXPORT_SYMBOL(ar9003_hw_disable_phy_restart);