ar9003_phy.c 41 KB

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