ar9003_phy.c 39 KB

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