ar9003_phy.c 44 KB

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