ar9003_phy.c 44 KB

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