ar9003_phy.c 44 KB

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