ar9003_phy.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  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)) {
  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))
  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. ar9003_hw_override_ini(ah);
  563. ar9003_hw_set_channel_regs(ah, chan);
  564. ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
  565. /* Set TX power */
  566. ah->eep_ops->set_txpower(ah, chan,
  567. ath9k_regd_get_ctl(regulatory, chan),
  568. channel->max_antenna_gain * 2,
  569. channel->max_power * 2,
  570. min((u32) MAX_RATE_POWER,
  571. (u32) regulatory->power_limit), false);
  572. return 0;
  573. }
  574. static void ar9003_hw_set_rfmode(struct ath_hw *ah,
  575. struct ath9k_channel *chan)
  576. {
  577. u32 rfMode = 0;
  578. if (chan == NULL)
  579. return;
  580. rfMode |= (IS_CHAN_B(chan) || IS_CHAN_G(chan))
  581. ? AR_PHY_MODE_DYNAMIC : AR_PHY_MODE_OFDM;
  582. if (IS_CHAN_A_FAST_CLOCK(ah, chan))
  583. rfMode |= (AR_PHY_MODE_DYNAMIC | AR_PHY_MODE_DYN_CCK_DISABLE);
  584. REG_WRITE(ah, AR_PHY_MODE, rfMode);
  585. }
  586. static void ar9003_hw_mark_phy_inactive(struct ath_hw *ah)
  587. {
  588. REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_DIS);
  589. }
  590. static void ar9003_hw_set_delta_slope(struct ath_hw *ah,
  591. struct ath9k_channel *chan)
  592. {
  593. u32 coef_scaled, ds_coef_exp, ds_coef_man;
  594. u32 clockMhzScaled = 0x64000000;
  595. struct chan_centers centers;
  596. /*
  597. * half and quarter rate can divide the scaled clock by 2 or 4
  598. * scale for selected channel bandwidth
  599. */
  600. if (IS_CHAN_HALF_RATE(chan))
  601. clockMhzScaled = clockMhzScaled >> 1;
  602. else if (IS_CHAN_QUARTER_RATE(chan))
  603. clockMhzScaled = clockMhzScaled >> 2;
  604. /*
  605. * ALGO -> coef = 1e8/fcarrier*fclock/40;
  606. * scaled coef to provide precision for this floating calculation
  607. */
  608. ath9k_hw_get_channel_centers(ah, chan, &centers);
  609. coef_scaled = clockMhzScaled / centers.synth_center;
  610. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  611. &ds_coef_exp);
  612. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  613. AR_PHY_TIMING3_DSC_MAN, ds_coef_man);
  614. REG_RMW_FIELD(ah, AR_PHY_TIMING3,
  615. AR_PHY_TIMING3_DSC_EXP, ds_coef_exp);
  616. /*
  617. * For Short GI,
  618. * scaled coeff is 9/10 that of normal coeff
  619. */
  620. coef_scaled = (9 * coef_scaled) / 10;
  621. ath9k_hw_get_delta_slope_vals(ah, coef_scaled, &ds_coef_man,
  622. &ds_coef_exp);
  623. /* for short gi */
  624. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  625. AR_PHY_SGI_DSC_MAN, ds_coef_man);
  626. REG_RMW_FIELD(ah, AR_PHY_SGI_DELTA,
  627. AR_PHY_SGI_DSC_EXP, ds_coef_exp);
  628. }
  629. static bool ar9003_hw_rfbus_req(struct ath_hw *ah)
  630. {
  631. REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
  632. return ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
  633. AR_PHY_RFBUS_GRANT_EN, AH_WAIT_TIMEOUT);
  634. }
  635. /*
  636. * Wait for the frequency synth to settle (synth goes on via PHY_ACTIVE_EN).
  637. * Read the phy active delay register. Value is in 100ns increments.
  638. */
  639. static void ar9003_hw_rfbus_done(struct ath_hw *ah)
  640. {
  641. u32 synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
  642. if (IS_CHAN_B(ah->curchan))
  643. synthDelay = (4 * synthDelay) / 22;
  644. else
  645. synthDelay /= 10;
  646. udelay(synthDelay + BASE_ACTIVATE_DELAY);
  647. REG_WRITE(ah, AR_PHY_RFBUS_REQ, 0);
  648. }
  649. static void ar9003_hw_set_diversity(struct ath_hw *ah, bool value)
  650. {
  651. u32 v = REG_READ(ah, AR_PHY_CCK_DETECT);
  652. if (value)
  653. v |= AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  654. else
  655. v &= ~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV;
  656. REG_WRITE(ah, AR_PHY_CCK_DETECT, v);
  657. }
  658. static bool ar9003_hw_ani_control(struct ath_hw *ah,
  659. enum ath9k_ani_cmd cmd, int param)
  660. {
  661. struct ath_common *common = ath9k_hw_common(ah);
  662. struct ath9k_channel *chan = ah->curchan;
  663. struct ar5416AniState *aniState = &chan->ani;
  664. s32 value, value2;
  665. switch (cmd & ah->ani_function) {
  666. case ATH9K_ANI_OFDM_WEAK_SIGNAL_DETECTION:{
  667. /*
  668. * on == 1 means ofdm weak signal detection is ON
  669. * on == 1 is the default, for less noise immunity
  670. *
  671. * on == 0 means ofdm weak signal detection is OFF
  672. * on == 0 means more noise imm
  673. */
  674. u32 on = param ? 1 : 0;
  675. /*
  676. * make register setting for default
  677. * (weak sig detect ON) come from INI file
  678. */
  679. int m1ThreshLow = on ?
  680. aniState->iniDef.m1ThreshLow : m1ThreshLow_off;
  681. int m2ThreshLow = on ?
  682. aniState->iniDef.m2ThreshLow : m2ThreshLow_off;
  683. int m1Thresh = on ?
  684. aniState->iniDef.m1Thresh : m1Thresh_off;
  685. int m2Thresh = on ?
  686. aniState->iniDef.m2Thresh : m2Thresh_off;
  687. int m2CountThr = on ?
  688. aniState->iniDef.m2CountThr : m2CountThr_off;
  689. int m2CountThrLow = on ?
  690. aniState->iniDef.m2CountThrLow : m2CountThrLow_off;
  691. int m1ThreshLowExt = on ?
  692. aniState->iniDef.m1ThreshLowExt : m1ThreshLowExt_off;
  693. int m2ThreshLowExt = on ?
  694. aniState->iniDef.m2ThreshLowExt : m2ThreshLowExt_off;
  695. int m1ThreshExt = on ?
  696. aniState->iniDef.m1ThreshExt : m1ThreshExt_off;
  697. int m2ThreshExt = on ?
  698. aniState->iniDef.m2ThreshExt : m2ThreshExt_off;
  699. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  700. AR_PHY_SFCORR_LOW_M1_THRESH_LOW,
  701. m1ThreshLow);
  702. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  703. AR_PHY_SFCORR_LOW_M2_THRESH_LOW,
  704. m2ThreshLow);
  705. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  706. AR_PHY_SFCORR_M1_THRESH, m1Thresh);
  707. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  708. AR_PHY_SFCORR_M2_THRESH, m2Thresh);
  709. REG_RMW_FIELD(ah, AR_PHY_SFCORR,
  710. AR_PHY_SFCORR_M2COUNT_THR, m2CountThr);
  711. REG_RMW_FIELD(ah, AR_PHY_SFCORR_LOW,
  712. AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW,
  713. m2CountThrLow);
  714. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  715. AR_PHY_SFCORR_EXT_M1_THRESH_LOW, m1ThreshLowExt);
  716. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  717. AR_PHY_SFCORR_EXT_M2_THRESH_LOW, m2ThreshLowExt);
  718. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  719. AR_PHY_SFCORR_EXT_M1_THRESH, m1ThreshExt);
  720. REG_RMW_FIELD(ah, AR_PHY_SFCORR_EXT,
  721. AR_PHY_SFCORR_EXT_M2_THRESH, m2ThreshExt);
  722. if (on)
  723. REG_SET_BIT(ah, AR_PHY_SFCORR_LOW,
  724. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  725. else
  726. REG_CLR_BIT(ah, AR_PHY_SFCORR_LOW,
  727. AR_PHY_SFCORR_LOW_USE_SELF_CORR_LOW);
  728. if (!on != aniState->ofdmWeakSigDetectOff) {
  729. ath_dbg(common, ATH_DBG_ANI,
  730. "** ch %d: ofdm weak signal: %s=>%s\n",
  731. chan->channel,
  732. !aniState->ofdmWeakSigDetectOff ?
  733. "on" : "off",
  734. on ? "on" : "off");
  735. if (on)
  736. ah->stats.ast_ani_ofdmon++;
  737. else
  738. ah->stats.ast_ani_ofdmoff++;
  739. aniState->ofdmWeakSigDetectOff = !on;
  740. }
  741. break;
  742. }
  743. case ATH9K_ANI_FIRSTEP_LEVEL:{
  744. u32 level = param;
  745. if (level >= ARRAY_SIZE(firstep_table)) {
  746. ath_dbg(common, ATH_DBG_ANI,
  747. "ATH9K_ANI_FIRSTEP_LEVEL: level out of range (%u > %zu)\n",
  748. level, ARRAY_SIZE(firstep_table));
  749. return false;
  750. }
  751. /*
  752. * make register setting relative to default
  753. * from INI file & cap value
  754. */
  755. value = firstep_table[level] -
  756. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  757. aniState->iniDef.firstep;
  758. if (value < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  759. value = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  760. if (value > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  761. value = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  762. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG,
  763. AR_PHY_FIND_SIG_FIRSTEP,
  764. value);
  765. /*
  766. * we need to set first step low register too
  767. * make register setting relative to default
  768. * from INI file & cap value
  769. */
  770. value2 = firstep_table[level] -
  771. firstep_table[ATH9K_ANI_FIRSTEP_LVL_NEW] +
  772. aniState->iniDef.firstepLow;
  773. if (value2 < ATH9K_SIG_FIRSTEP_SETTING_MIN)
  774. value2 = ATH9K_SIG_FIRSTEP_SETTING_MIN;
  775. if (value2 > ATH9K_SIG_FIRSTEP_SETTING_MAX)
  776. value2 = ATH9K_SIG_FIRSTEP_SETTING_MAX;
  777. REG_RMW_FIELD(ah, AR_PHY_FIND_SIG_LOW,
  778. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW, value2);
  779. if (level != aniState->firstepLevel) {
  780. ath_dbg(common, ATH_DBG_ANI,
  781. "** ch %d: level %d=>%d[def:%d] firstep[level]=%d ini=%d\n",
  782. chan->channel,
  783. aniState->firstepLevel,
  784. level,
  785. ATH9K_ANI_FIRSTEP_LVL_NEW,
  786. value,
  787. aniState->iniDef.firstep);
  788. ath_dbg(common, ATH_DBG_ANI,
  789. "** ch %d: level %d=>%d[def:%d] firstep_low[level]=%d ini=%d\n",
  790. chan->channel,
  791. aniState->firstepLevel,
  792. level,
  793. ATH9K_ANI_FIRSTEP_LVL_NEW,
  794. value2,
  795. aniState->iniDef.firstepLow);
  796. if (level > aniState->firstepLevel)
  797. ah->stats.ast_ani_stepup++;
  798. else if (level < aniState->firstepLevel)
  799. ah->stats.ast_ani_stepdown++;
  800. aniState->firstepLevel = level;
  801. }
  802. break;
  803. }
  804. case ATH9K_ANI_SPUR_IMMUNITY_LEVEL:{
  805. u32 level = param;
  806. if (level >= ARRAY_SIZE(cycpwrThr1_table)) {
  807. ath_dbg(common, ATH_DBG_ANI,
  808. "ATH9K_ANI_SPUR_IMMUNITY_LEVEL: level out of range (%u > %zu)\n",
  809. level, ARRAY_SIZE(cycpwrThr1_table));
  810. return false;
  811. }
  812. /*
  813. * make register setting relative to default
  814. * from INI file & cap value
  815. */
  816. value = cycpwrThr1_table[level] -
  817. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  818. aniState->iniDef.cycpwrThr1;
  819. if (value < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  820. value = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  821. if (value > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  822. value = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  823. REG_RMW_FIELD(ah, AR_PHY_TIMING5,
  824. AR_PHY_TIMING5_CYCPWR_THR1,
  825. value);
  826. /*
  827. * set AR_PHY_EXT_CCA for extension channel
  828. * make register setting relative to default
  829. * from INI file & cap value
  830. */
  831. value2 = cycpwrThr1_table[level] -
  832. cycpwrThr1_table[ATH9K_ANI_SPUR_IMMUNE_LVL_NEW] +
  833. aniState->iniDef.cycpwrThr1Ext;
  834. if (value2 < ATH9K_SIG_SPUR_IMM_SETTING_MIN)
  835. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MIN;
  836. if (value2 > ATH9K_SIG_SPUR_IMM_SETTING_MAX)
  837. value2 = ATH9K_SIG_SPUR_IMM_SETTING_MAX;
  838. REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
  839. AR_PHY_EXT_CYCPWR_THR1, value2);
  840. if (level != aniState->spurImmunityLevel) {
  841. ath_dbg(common, ATH_DBG_ANI,
  842. "** ch %d: level %d=>%d[def:%d] cycpwrThr1[level]=%d ini=%d\n",
  843. chan->channel,
  844. aniState->spurImmunityLevel,
  845. level,
  846. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  847. value,
  848. aniState->iniDef.cycpwrThr1);
  849. ath_dbg(common, ATH_DBG_ANI,
  850. "** ch %d: level %d=>%d[def:%d] cycpwrThr1Ext[level]=%d ini=%d\n",
  851. chan->channel,
  852. aniState->spurImmunityLevel,
  853. level,
  854. ATH9K_ANI_SPUR_IMMUNE_LVL_NEW,
  855. value2,
  856. aniState->iniDef.cycpwrThr1Ext);
  857. if (level > aniState->spurImmunityLevel)
  858. ah->stats.ast_ani_spurup++;
  859. else if (level < aniState->spurImmunityLevel)
  860. ah->stats.ast_ani_spurdown++;
  861. aniState->spurImmunityLevel = level;
  862. }
  863. break;
  864. }
  865. case ATH9K_ANI_MRC_CCK:{
  866. /*
  867. * is_on == 1 means MRC CCK ON (default, less noise imm)
  868. * is_on == 0 means MRC CCK is OFF (more noise imm)
  869. */
  870. bool is_on = param ? 1 : 0;
  871. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  872. AR_PHY_MRC_CCK_ENABLE, is_on);
  873. REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
  874. AR_PHY_MRC_CCK_MUX_REG, is_on);
  875. if (!is_on != aniState->mrcCCKOff) {
  876. ath_dbg(common, ATH_DBG_ANI,
  877. "** ch %d: MRC CCK: %s=>%s\n",
  878. chan->channel,
  879. !aniState->mrcCCKOff ? "on" : "off",
  880. is_on ? "on" : "off");
  881. if (is_on)
  882. ah->stats.ast_ani_ccklow++;
  883. else
  884. ah->stats.ast_ani_cckhigh++;
  885. aniState->mrcCCKOff = !is_on;
  886. }
  887. break;
  888. }
  889. case ATH9K_ANI_PRESENT:
  890. break;
  891. default:
  892. ath_dbg(common, ATH_DBG_ANI, "invalid cmd %u\n", cmd);
  893. return false;
  894. }
  895. ath_dbg(common, ATH_DBG_ANI,
  896. "ANI parameters: SI=%d, ofdmWS=%s FS=%d MRCcck=%s listenTime=%d ofdmErrs=%d cckErrs=%d\n",
  897. aniState->spurImmunityLevel,
  898. !aniState->ofdmWeakSigDetectOff ? "on" : "off",
  899. aniState->firstepLevel,
  900. !aniState->mrcCCKOff ? "on" : "off",
  901. aniState->listenTime,
  902. aniState->ofdmPhyErrCount,
  903. aniState->cckPhyErrCount);
  904. return true;
  905. }
  906. static void ar9003_hw_do_getnf(struct ath_hw *ah,
  907. int16_t nfarray[NUM_NF_READINGS])
  908. {
  909. #define AR_PHY_CH_MINCCA_PWR 0x1FF00000
  910. #define AR_PHY_CH_MINCCA_PWR_S 20
  911. #define AR_PHY_CH_EXT_MINCCA_PWR 0x01FF0000
  912. #define AR_PHY_CH_EXT_MINCCA_PWR_S 16
  913. int16_t nf;
  914. int i;
  915. for (i = 0; i < AR9300_MAX_CHAINS; i++) {
  916. if (ah->rxchainmask & BIT(i)) {
  917. nf = MS(REG_READ(ah, ah->nf_regs[i]),
  918. AR_PHY_CH_MINCCA_PWR);
  919. nfarray[i] = sign_extend32(nf, 8);
  920. if (IS_CHAN_HT40(ah->curchan)) {
  921. u8 ext_idx = AR9300_MAX_CHAINS + i;
  922. nf = MS(REG_READ(ah, ah->nf_regs[ext_idx]),
  923. AR_PHY_CH_EXT_MINCCA_PWR);
  924. nfarray[ext_idx] = sign_extend32(nf, 8);
  925. }
  926. }
  927. }
  928. }
  929. static void ar9003_hw_set_nf_limits(struct ath_hw *ah)
  930. {
  931. ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_2GHZ;
  932. ah->nf_2g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_2GHZ;
  933. ah->nf_2g.nominal = AR_PHY_CCA_NOM_VAL_9300_2GHZ;
  934. ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_5GHZ;
  935. ah->nf_5g.min = AR_PHY_CCA_MIN_GOOD_VAL_9300_5GHZ;
  936. ah->nf_5g.nominal = AR_PHY_CCA_NOM_VAL_9300_5GHZ;
  937. }
  938. /*
  939. * Initialize the ANI register values with default (ini) values.
  940. * This routine is called during a (full) hardware reset after
  941. * all the registers are initialised from the INI.
  942. */
  943. static void ar9003_hw_ani_cache_ini_regs(struct ath_hw *ah)
  944. {
  945. struct ar5416AniState *aniState;
  946. struct ath_common *common = ath9k_hw_common(ah);
  947. struct ath9k_channel *chan = ah->curchan;
  948. struct ath9k_ani_default *iniDef;
  949. u32 val;
  950. aniState = &ah->curchan->ani;
  951. iniDef = &aniState->iniDef;
  952. ath_dbg(common, ATH_DBG_ANI,
  953. "ver %d.%d opmode %u chan %d Mhz/0x%x\n",
  954. ah->hw_version.macVersion,
  955. ah->hw_version.macRev,
  956. ah->opmode,
  957. chan->channel,
  958. chan->channelFlags);
  959. val = REG_READ(ah, AR_PHY_SFCORR);
  960. iniDef->m1Thresh = MS(val, AR_PHY_SFCORR_M1_THRESH);
  961. iniDef->m2Thresh = MS(val, AR_PHY_SFCORR_M2_THRESH);
  962. iniDef->m2CountThr = MS(val, AR_PHY_SFCORR_M2COUNT_THR);
  963. val = REG_READ(ah, AR_PHY_SFCORR_LOW);
  964. iniDef->m1ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M1_THRESH_LOW);
  965. iniDef->m2ThreshLow = MS(val, AR_PHY_SFCORR_LOW_M2_THRESH_LOW);
  966. iniDef->m2CountThrLow = MS(val, AR_PHY_SFCORR_LOW_M2COUNT_THR_LOW);
  967. val = REG_READ(ah, AR_PHY_SFCORR_EXT);
  968. iniDef->m1ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH);
  969. iniDef->m2ThreshExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH);
  970. iniDef->m1ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M1_THRESH_LOW);
  971. iniDef->m2ThreshLowExt = MS(val, AR_PHY_SFCORR_EXT_M2_THRESH_LOW);
  972. iniDef->firstep = REG_READ_FIELD(ah,
  973. AR_PHY_FIND_SIG,
  974. AR_PHY_FIND_SIG_FIRSTEP);
  975. iniDef->firstepLow = REG_READ_FIELD(ah,
  976. AR_PHY_FIND_SIG_LOW,
  977. AR_PHY_FIND_SIG_LOW_FIRSTEP_LOW);
  978. iniDef->cycpwrThr1 = REG_READ_FIELD(ah,
  979. AR_PHY_TIMING5,
  980. AR_PHY_TIMING5_CYCPWR_THR1);
  981. iniDef->cycpwrThr1Ext = REG_READ_FIELD(ah,
  982. AR_PHY_EXT_CCA,
  983. AR_PHY_EXT_CYCPWR_THR1);
  984. /* these levels just got reset to defaults by the INI */
  985. aniState->spurImmunityLevel = ATH9K_ANI_SPUR_IMMUNE_LVL_NEW;
  986. aniState->firstepLevel = ATH9K_ANI_FIRSTEP_LVL_NEW;
  987. aniState->ofdmWeakSigDetectOff = !ATH9K_ANI_USE_OFDM_WEAK_SIG;
  988. aniState->mrcCCKOff = !ATH9K_ANI_ENABLE_MRC_CCK;
  989. }
  990. static void ar9003_hw_set_radar_params(struct ath_hw *ah,
  991. struct ath_hw_radar_conf *conf)
  992. {
  993. u32 radar_0 = 0, radar_1 = 0;
  994. if (!conf) {
  995. REG_CLR_BIT(ah, AR_PHY_RADAR_0, AR_PHY_RADAR_0_ENA);
  996. return;
  997. }
  998. radar_0 |= AR_PHY_RADAR_0_ENA | AR_PHY_RADAR_0_FFT_ENA;
  999. radar_0 |= SM(conf->fir_power, AR_PHY_RADAR_0_FIRPWR);
  1000. radar_0 |= SM(conf->radar_rssi, AR_PHY_RADAR_0_RRSSI);
  1001. radar_0 |= SM(conf->pulse_height, AR_PHY_RADAR_0_HEIGHT);
  1002. radar_0 |= SM(conf->pulse_rssi, AR_PHY_RADAR_0_PRSSI);
  1003. radar_0 |= SM(conf->pulse_inband, AR_PHY_RADAR_0_INBAND);
  1004. radar_1 |= AR_PHY_RADAR_1_MAX_RRSSI;
  1005. radar_1 |= AR_PHY_RADAR_1_BLOCK_CHECK;
  1006. radar_1 |= SM(conf->pulse_maxlen, AR_PHY_RADAR_1_MAXLEN);
  1007. radar_1 |= SM(conf->pulse_inband_step, AR_PHY_RADAR_1_RELSTEP_THRESH);
  1008. radar_1 |= SM(conf->radar_inband, AR_PHY_RADAR_1_RELPWR_THRESH);
  1009. REG_WRITE(ah, AR_PHY_RADAR_0, radar_0);
  1010. REG_WRITE(ah, AR_PHY_RADAR_1, radar_1);
  1011. if (conf->ext_channel)
  1012. REG_SET_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1013. else
  1014. REG_CLR_BIT(ah, AR_PHY_RADAR_EXT, AR_PHY_RADAR_EXT_ENA);
  1015. }
  1016. static void ar9003_hw_set_radar_conf(struct ath_hw *ah)
  1017. {
  1018. struct ath_hw_radar_conf *conf = &ah->radar_conf;
  1019. conf->fir_power = -28;
  1020. conf->radar_rssi = 0;
  1021. conf->pulse_height = 10;
  1022. conf->pulse_rssi = 24;
  1023. conf->pulse_inband = 8;
  1024. conf->pulse_maxlen = 255;
  1025. conf->pulse_inband_step = 12;
  1026. conf->radar_inband = 8;
  1027. }
  1028. void ar9003_hw_attach_phy_ops(struct ath_hw *ah)
  1029. {
  1030. struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah);
  1031. static const u32 ar9300_cca_regs[6] = {
  1032. AR_PHY_CCA_0,
  1033. AR_PHY_CCA_1,
  1034. AR_PHY_CCA_2,
  1035. AR_PHY_EXT_CCA,
  1036. AR_PHY_EXT_CCA_1,
  1037. AR_PHY_EXT_CCA_2,
  1038. };
  1039. priv_ops->rf_set_freq = ar9003_hw_set_channel;
  1040. priv_ops->spur_mitigate_freq = ar9003_hw_spur_mitigate;
  1041. priv_ops->compute_pll_control = ar9003_hw_compute_pll_control;
  1042. priv_ops->set_channel_regs = ar9003_hw_set_channel_regs;
  1043. priv_ops->init_bb = ar9003_hw_init_bb;
  1044. priv_ops->process_ini = ar9003_hw_process_ini;
  1045. priv_ops->set_rfmode = ar9003_hw_set_rfmode;
  1046. priv_ops->mark_phy_inactive = ar9003_hw_mark_phy_inactive;
  1047. priv_ops->set_delta_slope = ar9003_hw_set_delta_slope;
  1048. priv_ops->rfbus_req = ar9003_hw_rfbus_req;
  1049. priv_ops->rfbus_done = ar9003_hw_rfbus_done;
  1050. priv_ops->set_diversity = ar9003_hw_set_diversity;
  1051. priv_ops->ani_control = ar9003_hw_ani_control;
  1052. priv_ops->do_getnf = ar9003_hw_do_getnf;
  1053. priv_ops->ani_cache_ini_regs = ar9003_hw_ani_cache_ini_regs;
  1054. priv_ops->set_radar_params = ar9003_hw_set_radar_params;
  1055. ar9003_hw_set_nf_limits(ah);
  1056. ar9003_hw_set_radar_conf(ah);
  1057. memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
  1058. }
  1059. void ar9003_hw_bb_watchdog_config(struct ath_hw *ah)
  1060. {
  1061. struct ath_common *common = ath9k_hw_common(ah);
  1062. u32 idle_tmo_ms = ah->bb_watchdog_timeout_ms;
  1063. u32 val, idle_count;
  1064. if (!idle_tmo_ms) {
  1065. /* disable IRQ, disable chip-reset for BB panic */
  1066. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1067. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) &
  1068. ~(AR_PHY_WATCHDOG_RST_ENABLE |
  1069. AR_PHY_WATCHDOG_IRQ_ENABLE));
  1070. /* disable watchdog in non-IDLE mode, disable in IDLE mode */
  1071. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1072. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1) &
  1073. ~(AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1074. AR_PHY_WATCHDOG_IDLE_ENABLE));
  1075. ath_dbg(common, ATH_DBG_RESET, "Disabled BB Watchdog\n");
  1076. return;
  1077. }
  1078. /* enable IRQ, disable chip-reset for BB watchdog */
  1079. val = REG_READ(ah, AR_PHY_WATCHDOG_CTL_2) & AR_PHY_WATCHDOG_CNTL2_MASK;
  1080. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_2,
  1081. (val | AR_PHY_WATCHDOG_IRQ_ENABLE) &
  1082. ~AR_PHY_WATCHDOG_RST_ENABLE);
  1083. /* bound limit to 10 secs */
  1084. if (idle_tmo_ms > 10000)
  1085. idle_tmo_ms = 10000;
  1086. /*
  1087. * The time unit for watchdog event is 2^15 44/88MHz cycles.
  1088. *
  1089. * For HT20 we have a time unit of 2^15/44 MHz = .74 ms per tick
  1090. * For HT40 we have a time unit of 2^15/88 MHz = .37 ms per tick
  1091. *
  1092. * Given we use fast clock now in 5 GHz, these time units should
  1093. * be common for both 2 GHz and 5 GHz.
  1094. */
  1095. idle_count = (100 * idle_tmo_ms) / 74;
  1096. if (ah->curchan && IS_CHAN_HT40(ah->curchan))
  1097. idle_count = (100 * idle_tmo_ms) / 37;
  1098. /*
  1099. * enable watchdog in non-IDLE mode, disable in IDLE mode,
  1100. * set idle time-out.
  1101. */
  1102. REG_WRITE(ah, AR_PHY_WATCHDOG_CTL_1,
  1103. AR_PHY_WATCHDOG_NON_IDLE_ENABLE |
  1104. AR_PHY_WATCHDOG_IDLE_MASK |
  1105. (AR_PHY_WATCHDOG_NON_IDLE_MASK & (idle_count << 2)));
  1106. ath_dbg(common, ATH_DBG_RESET,
  1107. "Enabled BB Watchdog timeout (%u ms)\n",
  1108. idle_tmo_ms);
  1109. }
  1110. void ar9003_hw_bb_watchdog_read(struct ath_hw *ah)
  1111. {
  1112. /*
  1113. * we want to avoid printing in ISR context so we save the
  1114. * watchdog status to be printed later in bottom half context.
  1115. */
  1116. ah->bb_watchdog_last_status = REG_READ(ah, AR_PHY_WATCHDOG_STATUS);
  1117. /*
  1118. * the watchdog timer should reset on status read but to be sure
  1119. * sure we write 0 to the watchdog status bit.
  1120. */
  1121. REG_WRITE(ah, AR_PHY_WATCHDOG_STATUS,
  1122. ah->bb_watchdog_last_status & ~AR_PHY_WATCHDOG_STATUS_CLR);
  1123. }
  1124. void ar9003_hw_bb_watchdog_dbg_info(struct ath_hw *ah)
  1125. {
  1126. struct ath_common *common = ath9k_hw_common(ah);
  1127. u32 status;
  1128. if (likely(!(common->debug_mask & ATH_DBG_RESET)))
  1129. return;
  1130. status = ah->bb_watchdog_last_status;
  1131. ath_dbg(common, ATH_DBG_RESET,
  1132. "\n==== BB update: BB status=0x%08x ====\n", status);
  1133. ath_dbg(common, ATH_DBG_RESET,
  1134. "** BB state: wd=%u det=%u rdar=%u rOFDM=%d rCCK=%u tOFDM=%u tCCK=%u agc=%u src=%u **\n",
  1135. MS(status, AR_PHY_WATCHDOG_INFO),
  1136. MS(status, AR_PHY_WATCHDOG_DET_HANG),
  1137. MS(status, AR_PHY_WATCHDOG_RADAR_SM),
  1138. MS(status, AR_PHY_WATCHDOG_RX_OFDM_SM),
  1139. MS(status, AR_PHY_WATCHDOG_RX_CCK_SM),
  1140. MS(status, AR_PHY_WATCHDOG_TX_OFDM_SM),
  1141. MS(status, AR_PHY_WATCHDOG_TX_CCK_SM),
  1142. MS(status, AR_PHY_WATCHDOG_AGC_SM),
  1143. MS(status, AR_PHY_WATCHDOG_SRCH_SM));
  1144. ath_dbg(common, ATH_DBG_RESET,
  1145. "** BB WD cntl: cntl1=0x%08x cntl2=0x%08x **\n",
  1146. REG_READ(ah, AR_PHY_WATCHDOG_CTL_1),
  1147. REG_READ(ah, AR_PHY_WATCHDOG_CTL_2));
  1148. ath_dbg(common, ATH_DBG_RESET,
  1149. "** BB mode: BB_gen_controls=0x%08x **\n",
  1150. REG_READ(ah, AR_PHY_GEN_CTRL));
  1151. #define PCT(_field) (common->cc_survey._field * 100 / common->cc_survey.cycles)
  1152. if (common->cc_survey.cycles)
  1153. ath_dbg(common, ATH_DBG_RESET,
  1154. "** BB busy times: rx_clear=%d%%, rx_frame=%d%%, tx_frame=%d%% **\n",
  1155. PCT(rx_busy), PCT(rx_frame), PCT(tx_frame));
  1156. ath_dbg(common, ATH_DBG_RESET,
  1157. "==== BB update: done ====\n\n");
  1158. }
  1159. EXPORT_SYMBOL(ar9003_hw_bb_watchdog_dbg_info);