ar9003_phy.c 42 KB

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