iwl-agn-calib.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  22. * USA
  23. *
  24. * The full GNU General Public License is included in this distribution
  25. * in the file called LICENSE.GPL.
  26. *
  27. * Contact Information:
  28. * Intel Linux Wireless <ilw@linux.intel.com>
  29. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  30. *
  31. * BSD LICENSE
  32. *
  33. * Copyright(c) 2005 - 2010 Intel Corporation. All rights reserved.
  34. * All rights reserved.
  35. *
  36. * Redistribution and use in source and binary forms, with or without
  37. * modification, are permitted provided that the following conditions
  38. * are met:
  39. *
  40. * * Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * * Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in
  44. * the documentation and/or other materials provided with the
  45. * distribution.
  46. * * Neither the name Intel Corporation nor the names of its
  47. * contributors may be used to endorse or promote products derived
  48. * from this software without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  51. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  52. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  53. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  54. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  55. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  56. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  57. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  58. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  59. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  60. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  61. *****************************************************************************/
  62. #include <linux/slab.h>
  63. #include <net/mac80211.h>
  64. #include "iwl-dev.h"
  65. #include "iwl-core.h"
  66. #include "iwl-calib.h"
  67. /*****************************************************************************
  68. * INIT calibrations framework
  69. *****************************************************************************/
  70. struct statistics_general_data {
  71. u32 beacon_silence_rssi_a;
  72. u32 beacon_silence_rssi_b;
  73. u32 beacon_silence_rssi_c;
  74. u32 beacon_energy_a;
  75. u32 beacon_energy_b;
  76. u32 beacon_energy_c;
  77. };
  78. int iwl_send_calib_results(struct iwl_priv *priv)
  79. {
  80. int ret = 0;
  81. int i = 0;
  82. struct iwl_host_cmd hcmd = {
  83. .id = REPLY_PHY_CALIBRATION_CMD,
  84. .flags = CMD_SIZE_HUGE,
  85. };
  86. for (i = 0; i < IWL_CALIB_MAX; i++) {
  87. if ((BIT(i) & priv->hw_params.calib_init_cfg) &&
  88. priv->calib_results[i].buf) {
  89. hcmd.len = priv->calib_results[i].buf_len;
  90. hcmd.data = priv->calib_results[i].buf;
  91. ret = iwl_send_cmd_sync(priv, &hcmd);
  92. if (ret) {
  93. IWL_ERR(priv, "Error %d iteration %d\n",
  94. ret, i);
  95. break;
  96. }
  97. }
  98. }
  99. return ret;
  100. }
  101. int iwl_calib_set(struct iwl_calib_result *res, const u8 *buf, int len)
  102. {
  103. if (res->buf_len != len) {
  104. kfree(res->buf);
  105. res->buf = kzalloc(len, GFP_ATOMIC);
  106. }
  107. if (unlikely(res->buf == NULL))
  108. return -ENOMEM;
  109. res->buf_len = len;
  110. memcpy(res->buf, buf, len);
  111. return 0;
  112. }
  113. void iwl_calib_free_results(struct iwl_priv *priv)
  114. {
  115. int i;
  116. for (i = 0; i < IWL_CALIB_MAX; i++) {
  117. kfree(priv->calib_results[i].buf);
  118. priv->calib_results[i].buf = NULL;
  119. priv->calib_results[i].buf_len = 0;
  120. }
  121. }
  122. /*****************************************************************************
  123. * RUNTIME calibrations framework
  124. *****************************************************************************/
  125. /* "false alarms" are signals that our DSP tries to lock onto,
  126. * but then determines that they are either noise, or transmissions
  127. * from a distant wireless network (also "noise", really) that get
  128. * "stepped on" by stronger transmissions within our own network.
  129. * This algorithm attempts to set a sensitivity level that is high
  130. * enough to receive all of our own network traffic, but not so
  131. * high that our DSP gets too busy trying to lock onto non-network
  132. * activity/noise. */
  133. static int iwl_sens_energy_cck(struct iwl_priv *priv,
  134. u32 norm_fa,
  135. u32 rx_enable_time,
  136. struct statistics_general_data *rx_info)
  137. {
  138. u32 max_nrg_cck = 0;
  139. int i = 0;
  140. u8 max_silence_rssi = 0;
  141. u32 silence_ref = 0;
  142. u8 silence_rssi_a = 0;
  143. u8 silence_rssi_b = 0;
  144. u8 silence_rssi_c = 0;
  145. u32 val;
  146. /* "false_alarms" values below are cross-multiplications to assess the
  147. * numbers of false alarms within the measured period of actual Rx
  148. * (Rx is off when we're txing), vs the min/max expected false alarms
  149. * (some should be expected if rx is sensitive enough) in a
  150. * hypothetical listening period of 200 time units (TU), 204.8 msec:
  151. *
  152. * MIN_FA/fixed-time < false_alarms/actual-rx-time < MAX_FA/beacon-time
  153. *
  154. * */
  155. u32 false_alarms = norm_fa * 200 * 1024;
  156. u32 max_false_alarms = MAX_FA_CCK * rx_enable_time;
  157. u32 min_false_alarms = MIN_FA_CCK * rx_enable_time;
  158. struct iwl_sensitivity_data *data = NULL;
  159. const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
  160. data = &(priv->sensitivity_data);
  161. data->nrg_auto_corr_silence_diff = 0;
  162. /* Find max silence rssi among all 3 receivers.
  163. * This is background noise, which may include transmissions from other
  164. * networks, measured during silence before our network's beacon */
  165. silence_rssi_a = (u8)((rx_info->beacon_silence_rssi_a &
  166. ALL_BAND_FILTER) >> 8);
  167. silence_rssi_b = (u8)((rx_info->beacon_silence_rssi_b &
  168. ALL_BAND_FILTER) >> 8);
  169. silence_rssi_c = (u8)((rx_info->beacon_silence_rssi_c &
  170. ALL_BAND_FILTER) >> 8);
  171. val = max(silence_rssi_b, silence_rssi_c);
  172. max_silence_rssi = max(silence_rssi_a, (u8) val);
  173. /* Store silence rssi in 20-beacon history table */
  174. data->nrg_silence_rssi[data->nrg_silence_idx] = max_silence_rssi;
  175. data->nrg_silence_idx++;
  176. if (data->nrg_silence_idx >= NRG_NUM_PREV_STAT_L)
  177. data->nrg_silence_idx = 0;
  178. /* Find max silence rssi across 20 beacon history */
  179. for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) {
  180. val = data->nrg_silence_rssi[i];
  181. silence_ref = max(silence_ref, val);
  182. }
  183. IWL_DEBUG_CALIB(priv, "silence a %u, b %u, c %u, 20-bcn max %u\n",
  184. silence_rssi_a, silence_rssi_b, silence_rssi_c,
  185. silence_ref);
  186. /* Find max rx energy (min value!) among all 3 receivers,
  187. * measured during beacon frame.
  188. * Save it in 10-beacon history table. */
  189. i = data->nrg_energy_idx;
  190. val = min(rx_info->beacon_energy_b, rx_info->beacon_energy_c);
  191. data->nrg_value[i] = min(rx_info->beacon_energy_a, val);
  192. data->nrg_energy_idx++;
  193. if (data->nrg_energy_idx >= 10)
  194. data->nrg_energy_idx = 0;
  195. /* Find min rx energy (max value) across 10 beacon history.
  196. * This is the minimum signal level that we want to receive well.
  197. * Add backoff (margin so we don't miss slightly lower energy frames).
  198. * This establishes an upper bound (min value) for energy threshold. */
  199. max_nrg_cck = data->nrg_value[0];
  200. for (i = 1; i < 10; i++)
  201. max_nrg_cck = (u32) max(max_nrg_cck, (data->nrg_value[i]));
  202. max_nrg_cck += 6;
  203. IWL_DEBUG_CALIB(priv, "rx energy a %u, b %u, c %u, 10-bcn max/min %u\n",
  204. rx_info->beacon_energy_a, rx_info->beacon_energy_b,
  205. rx_info->beacon_energy_c, max_nrg_cck - 6);
  206. /* Count number of consecutive beacons with fewer-than-desired
  207. * false alarms. */
  208. if (false_alarms < min_false_alarms)
  209. data->num_in_cck_no_fa++;
  210. else
  211. data->num_in_cck_no_fa = 0;
  212. IWL_DEBUG_CALIB(priv, "consecutive bcns with few false alarms = %u\n",
  213. data->num_in_cck_no_fa);
  214. /* If we got too many false alarms this time, reduce sensitivity */
  215. if ((false_alarms > max_false_alarms) &&
  216. (data->auto_corr_cck > AUTO_CORR_MAX_TH_CCK)) {
  217. IWL_DEBUG_CALIB(priv, "norm FA %u > max FA %u\n",
  218. false_alarms, max_false_alarms);
  219. IWL_DEBUG_CALIB(priv, "... reducing sensitivity\n");
  220. data->nrg_curr_state = IWL_FA_TOO_MANY;
  221. /* Store for "fewer than desired" on later beacon */
  222. data->nrg_silence_ref = silence_ref;
  223. /* increase energy threshold (reduce nrg value)
  224. * to decrease sensitivity */
  225. data->nrg_th_cck = data->nrg_th_cck - NRG_STEP_CCK;
  226. /* Else if we got fewer than desired, increase sensitivity */
  227. } else if (false_alarms < min_false_alarms) {
  228. data->nrg_curr_state = IWL_FA_TOO_FEW;
  229. /* Compare silence level with silence level for most recent
  230. * healthy number or too many false alarms */
  231. data->nrg_auto_corr_silence_diff = (s32)data->nrg_silence_ref -
  232. (s32)silence_ref;
  233. IWL_DEBUG_CALIB(priv, "norm FA %u < min FA %u, silence diff %d\n",
  234. false_alarms, min_false_alarms,
  235. data->nrg_auto_corr_silence_diff);
  236. /* Increase value to increase sensitivity, but only if:
  237. * 1a) previous beacon did *not* have *too many* false alarms
  238. * 1b) AND there's a significant difference in Rx levels
  239. * from a previous beacon with too many, or healthy # FAs
  240. * OR 2) We've seen a lot of beacons (100) with too few
  241. * false alarms */
  242. if ((data->nrg_prev_state != IWL_FA_TOO_MANY) &&
  243. ((data->nrg_auto_corr_silence_diff > NRG_DIFF) ||
  244. (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) {
  245. IWL_DEBUG_CALIB(priv, "... increasing sensitivity\n");
  246. /* Increase nrg value to increase sensitivity */
  247. val = data->nrg_th_cck + NRG_STEP_CCK;
  248. data->nrg_th_cck = min((u32)ranges->min_nrg_cck, val);
  249. } else {
  250. IWL_DEBUG_CALIB(priv, "... but not changing sensitivity\n");
  251. }
  252. /* Else we got a healthy number of false alarms, keep status quo */
  253. } else {
  254. IWL_DEBUG_CALIB(priv, " FA in safe zone\n");
  255. data->nrg_curr_state = IWL_FA_GOOD_RANGE;
  256. /* Store for use in "fewer than desired" with later beacon */
  257. data->nrg_silence_ref = silence_ref;
  258. /* If previous beacon had too many false alarms,
  259. * give it some extra margin by reducing sensitivity again
  260. * (but don't go below measured energy of desired Rx) */
  261. if (IWL_FA_TOO_MANY == data->nrg_prev_state) {
  262. IWL_DEBUG_CALIB(priv, "... increasing margin\n");
  263. if (data->nrg_th_cck > (max_nrg_cck + NRG_MARGIN))
  264. data->nrg_th_cck -= NRG_MARGIN;
  265. else
  266. data->nrg_th_cck = max_nrg_cck;
  267. }
  268. }
  269. /* Make sure the energy threshold does not go above the measured
  270. * energy of the desired Rx signals (reduced by backoff margin),
  271. * or else we might start missing Rx frames.
  272. * Lower value is higher energy, so we use max()!
  273. */
  274. data->nrg_th_cck = max(max_nrg_cck, data->nrg_th_cck);
  275. IWL_DEBUG_CALIB(priv, "new nrg_th_cck %u\n", data->nrg_th_cck);
  276. data->nrg_prev_state = data->nrg_curr_state;
  277. /* Auto-correlation CCK algorithm */
  278. if (false_alarms > min_false_alarms) {
  279. /* increase auto_corr values to decrease sensitivity
  280. * so the DSP won't be disturbed by the noise
  281. */
  282. if (data->auto_corr_cck < AUTO_CORR_MAX_TH_CCK)
  283. data->auto_corr_cck = AUTO_CORR_MAX_TH_CCK + 1;
  284. else {
  285. val = data->auto_corr_cck + AUTO_CORR_STEP_CCK;
  286. data->auto_corr_cck =
  287. min((u32)ranges->auto_corr_max_cck, val);
  288. }
  289. val = data->auto_corr_cck_mrc + AUTO_CORR_STEP_CCK;
  290. data->auto_corr_cck_mrc =
  291. min((u32)ranges->auto_corr_max_cck_mrc, val);
  292. } else if ((false_alarms < min_false_alarms) &&
  293. ((data->nrg_auto_corr_silence_diff > NRG_DIFF) ||
  294. (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) {
  295. /* Decrease auto_corr values to increase sensitivity */
  296. val = data->auto_corr_cck - AUTO_CORR_STEP_CCK;
  297. data->auto_corr_cck =
  298. max((u32)ranges->auto_corr_min_cck, val);
  299. val = data->auto_corr_cck_mrc - AUTO_CORR_STEP_CCK;
  300. data->auto_corr_cck_mrc =
  301. max((u32)ranges->auto_corr_min_cck_mrc, val);
  302. }
  303. return 0;
  304. }
  305. static int iwl_sens_auto_corr_ofdm(struct iwl_priv *priv,
  306. u32 norm_fa,
  307. u32 rx_enable_time)
  308. {
  309. u32 val;
  310. u32 false_alarms = norm_fa * 200 * 1024;
  311. u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time;
  312. u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time;
  313. struct iwl_sensitivity_data *data = NULL;
  314. const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
  315. data = &(priv->sensitivity_data);
  316. /* If we got too many false alarms this time, reduce sensitivity */
  317. if (false_alarms > max_false_alarms) {
  318. IWL_DEBUG_CALIB(priv, "norm FA %u > max FA %u)\n",
  319. false_alarms, max_false_alarms);
  320. val = data->auto_corr_ofdm + AUTO_CORR_STEP_OFDM;
  321. data->auto_corr_ofdm =
  322. min((u32)ranges->auto_corr_max_ofdm, val);
  323. val = data->auto_corr_ofdm_mrc + AUTO_CORR_STEP_OFDM;
  324. data->auto_corr_ofdm_mrc =
  325. min((u32)ranges->auto_corr_max_ofdm_mrc, val);
  326. val = data->auto_corr_ofdm_x1 + AUTO_CORR_STEP_OFDM;
  327. data->auto_corr_ofdm_x1 =
  328. min((u32)ranges->auto_corr_max_ofdm_x1, val);
  329. val = data->auto_corr_ofdm_mrc_x1 + AUTO_CORR_STEP_OFDM;
  330. data->auto_corr_ofdm_mrc_x1 =
  331. min((u32)ranges->auto_corr_max_ofdm_mrc_x1, val);
  332. }
  333. /* Else if we got fewer than desired, increase sensitivity */
  334. else if (false_alarms < min_false_alarms) {
  335. IWL_DEBUG_CALIB(priv, "norm FA %u < min FA %u\n",
  336. false_alarms, min_false_alarms);
  337. val = data->auto_corr_ofdm - AUTO_CORR_STEP_OFDM;
  338. data->auto_corr_ofdm =
  339. max((u32)ranges->auto_corr_min_ofdm, val);
  340. val = data->auto_corr_ofdm_mrc - AUTO_CORR_STEP_OFDM;
  341. data->auto_corr_ofdm_mrc =
  342. max((u32)ranges->auto_corr_min_ofdm_mrc, val);
  343. val = data->auto_corr_ofdm_x1 - AUTO_CORR_STEP_OFDM;
  344. data->auto_corr_ofdm_x1 =
  345. max((u32)ranges->auto_corr_min_ofdm_x1, val);
  346. val = data->auto_corr_ofdm_mrc_x1 - AUTO_CORR_STEP_OFDM;
  347. data->auto_corr_ofdm_mrc_x1 =
  348. max((u32)ranges->auto_corr_min_ofdm_mrc_x1, val);
  349. } else {
  350. IWL_DEBUG_CALIB(priv, "min FA %u < norm FA %u < max FA %u OK\n",
  351. min_false_alarms, false_alarms, max_false_alarms);
  352. }
  353. return 0;
  354. }
  355. static void iwl_prepare_legacy_sensitivity_tbl(struct iwl_priv *priv,
  356. struct iwl_sensitivity_data *data,
  357. __le16 *tbl)
  358. {
  359. tbl[HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX] =
  360. cpu_to_le16((u16)data->auto_corr_ofdm);
  361. tbl[HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX] =
  362. cpu_to_le16((u16)data->auto_corr_ofdm_mrc);
  363. tbl[HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX] =
  364. cpu_to_le16((u16)data->auto_corr_ofdm_x1);
  365. tbl[HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX] =
  366. cpu_to_le16((u16)data->auto_corr_ofdm_mrc_x1);
  367. tbl[HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX] =
  368. cpu_to_le16((u16)data->auto_corr_cck);
  369. tbl[HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX] =
  370. cpu_to_le16((u16)data->auto_corr_cck_mrc);
  371. tbl[HD_MIN_ENERGY_CCK_DET_INDEX] =
  372. cpu_to_le16((u16)data->nrg_th_cck);
  373. tbl[HD_MIN_ENERGY_OFDM_DET_INDEX] =
  374. cpu_to_le16((u16)data->nrg_th_ofdm);
  375. tbl[HD_BARKER_CORR_TH_ADD_MIN_INDEX] =
  376. cpu_to_le16(data->barker_corr_th_min);
  377. tbl[HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX] =
  378. cpu_to_le16(data->barker_corr_th_min_mrc);
  379. tbl[HD_OFDM_ENERGY_TH_IN_INDEX] =
  380. cpu_to_le16(data->nrg_th_cca);
  381. IWL_DEBUG_CALIB(priv, "ofdm: ac %u mrc %u x1 %u mrc_x1 %u thresh %u\n",
  382. data->auto_corr_ofdm, data->auto_corr_ofdm_mrc,
  383. data->auto_corr_ofdm_x1, data->auto_corr_ofdm_mrc_x1,
  384. data->nrg_th_ofdm);
  385. IWL_DEBUG_CALIB(priv, "cck: ac %u mrc %u thresh %u\n",
  386. data->auto_corr_cck, data->auto_corr_cck_mrc,
  387. data->nrg_th_cck);
  388. }
  389. /* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */
  390. static int iwl_sensitivity_write(struct iwl_priv *priv)
  391. {
  392. struct iwl_sensitivity_cmd cmd;
  393. struct iwl_sensitivity_data *data = NULL;
  394. struct iwl_host_cmd cmd_out = {
  395. .id = SENSITIVITY_CMD,
  396. .len = sizeof(struct iwl_sensitivity_cmd),
  397. .flags = CMD_ASYNC,
  398. .data = &cmd,
  399. };
  400. data = &(priv->sensitivity_data);
  401. memset(&cmd, 0, sizeof(cmd));
  402. iwl_prepare_legacy_sensitivity_tbl(priv, data, &cmd.table[0]);
  403. /* Update uCode's "work" table, and copy it to DSP */
  404. cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE;
  405. /* Don't send command to uCode if nothing has changed */
  406. if (!memcmp(&cmd.table[0], &(priv->sensitivity_tbl[0]),
  407. sizeof(u16)*HD_TABLE_SIZE)) {
  408. IWL_DEBUG_CALIB(priv, "No change in SENSITIVITY_CMD\n");
  409. return 0;
  410. }
  411. /* Copy table for comparison next time */
  412. memcpy(&(priv->sensitivity_tbl[0]), &(cmd.table[0]),
  413. sizeof(u16)*HD_TABLE_SIZE);
  414. return iwl_send_cmd(priv, &cmd_out);
  415. }
  416. /* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */
  417. static int iwl_enhance_sensitivity_write(struct iwl_priv *priv)
  418. {
  419. struct iwl_enhance_sensitivity_cmd cmd;
  420. struct iwl_sensitivity_data *data = NULL;
  421. struct iwl_host_cmd cmd_out = {
  422. .id = SENSITIVITY_CMD,
  423. .len = sizeof(struct iwl_enhance_sensitivity_cmd),
  424. .flags = CMD_ASYNC,
  425. .data = &cmd,
  426. };
  427. data = &(priv->sensitivity_data);
  428. memset(&cmd, 0, sizeof(cmd));
  429. iwl_prepare_legacy_sensitivity_tbl(priv, data, &cmd.enhance_table[0]);
  430. cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX] =
  431. HD_INA_NON_SQUARE_DET_OFDM_DATA;
  432. cmd.enhance_table[HD_INA_NON_SQUARE_DET_CCK_INDEX] =
  433. HD_INA_NON_SQUARE_DET_CCK_DATA;
  434. cmd.enhance_table[HD_CORR_11_INSTEAD_OF_CORR_9_EN_INDEX] =
  435. HD_CORR_11_INSTEAD_OF_CORR_9_EN_DATA;
  436. cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_INDEX] =
  437. HD_OFDM_NON_SQUARE_DET_SLOPE_MRC_DATA;
  438. cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_INDEX] =
  439. HD_OFDM_NON_SQUARE_DET_INTERCEPT_MRC_DATA;
  440. cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_SLOPE_INDEX] =
  441. HD_OFDM_NON_SQUARE_DET_SLOPE_DATA;
  442. cmd.enhance_table[HD_OFDM_NON_SQUARE_DET_INTERCEPT_INDEX] =
  443. HD_OFDM_NON_SQUARE_DET_INTERCEPT_DATA;
  444. cmd.enhance_table[HD_CCK_NON_SQUARE_DET_SLOPE_MRC_INDEX] =
  445. HD_CCK_NON_SQUARE_DET_SLOPE_MRC_DATA;
  446. cmd.enhance_table[HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_INDEX] =
  447. HD_CCK_NON_SQUARE_DET_INTERCEPT_MRC_DATA;
  448. cmd.enhance_table[HD_CCK_NON_SQUARE_DET_SLOPE_INDEX] =
  449. HD_CCK_NON_SQUARE_DET_SLOPE_DATA;
  450. cmd.enhance_table[HD_CCK_NON_SQUARE_DET_INTERCEPT_INDEX] =
  451. HD_CCK_NON_SQUARE_DET_INTERCEPT_DATA;
  452. /* Update uCode's "work" table, and copy it to DSP */
  453. cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE;
  454. /* Don't send command to uCode if nothing has changed */
  455. if (!memcmp(&cmd.enhance_table[0], &(priv->sensitivity_tbl[0]),
  456. sizeof(u16)*HD_TABLE_SIZE) &&
  457. !memcmp(&cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX],
  458. &(priv->enhance_sensitivity_tbl[0]),
  459. sizeof(u16)*ENHANCE_HD_TABLE_ENTRIES)) {
  460. IWL_DEBUG_CALIB(priv, "No change in SENSITIVITY_CMD\n");
  461. return 0;
  462. }
  463. /* Copy table for comparison next time */
  464. memcpy(&(priv->sensitivity_tbl[0]), &(cmd.enhance_table[0]),
  465. sizeof(u16)*HD_TABLE_SIZE);
  466. memcpy(&(priv->enhance_sensitivity_tbl[0]),
  467. &(cmd.enhance_table[HD_INA_NON_SQUARE_DET_OFDM_INDEX]),
  468. sizeof(u16)*ENHANCE_HD_TABLE_ENTRIES);
  469. return iwl_send_cmd(priv, &cmd_out);
  470. }
  471. void iwl_init_sensitivity(struct iwl_priv *priv)
  472. {
  473. int ret = 0;
  474. int i;
  475. struct iwl_sensitivity_data *data = NULL;
  476. const struct iwl_sensitivity_ranges *ranges = priv->hw_params.sens;
  477. if (priv->disable_sens_cal)
  478. return;
  479. IWL_DEBUG_CALIB(priv, "Start iwl_init_sensitivity\n");
  480. /* Clear driver's sensitivity algo data */
  481. data = &(priv->sensitivity_data);
  482. if (ranges == NULL)
  483. return;
  484. memset(data, 0, sizeof(struct iwl_sensitivity_data));
  485. data->num_in_cck_no_fa = 0;
  486. data->nrg_curr_state = IWL_FA_TOO_MANY;
  487. data->nrg_prev_state = IWL_FA_TOO_MANY;
  488. data->nrg_silence_ref = 0;
  489. data->nrg_silence_idx = 0;
  490. data->nrg_energy_idx = 0;
  491. for (i = 0; i < 10; i++)
  492. data->nrg_value[i] = 0;
  493. for (i = 0; i < NRG_NUM_PREV_STAT_L; i++)
  494. data->nrg_silence_rssi[i] = 0;
  495. data->auto_corr_ofdm = ranges->auto_corr_min_ofdm;
  496. data->auto_corr_ofdm_mrc = ranges->auto_corr_min_ofdm_mrc;
  497. data->auto_corr_ofdm_x1 = ranges->auto_corr_min_ofdm_x1;
  498. data->auto_corr_ofdm_mrc_x1 = ranges->auto_corr_min_ofdm_mrc_x1;
  499. data->auto_corr_cck = AUTO_CORR_CCK_MIN_VAL_DEF;
  500. data->auto_corr_cck_mrc = ranges->auto_corr_min_cck_mrc;
  501. data->nrg_th_cck = ranges->nrg_th_cck;
  502. data->nrg_th_ofdm = ranges->nrg_th_ofdm;
  503. data->barker_corr_th_min = ranges->barker_corr_th_min;
  504. data->barker_corr_th_min_mrc = ranges->barker_corr_th_min_mrc;
  505. data->nrg_th_cca = ranges->nrg_th_cca;
  506. data->last_bad_plcp_cnt_ofdm = 0;
  507. data->last_fa_cnt_ofdm = 0;
  508. data->last_bad_plcp_cnt_cck = 0;
  509. data->last_fa_cnt_cck = 0;
  510. if (priv->enhance_sensitivity_table)
  511. ret |= iwl_enhance_sensitivity_write(priv);
  512. else
  513. ret |= iwl_sensitivity_write(priv);
  514. IWL_DEBUG_CALIB(priv, "<<return 0x%X\n", ret);
  515. }
  516. void iwl_sensitivity_calibration(struct iwl_priv *priv, void *resp)
  517. {
  518. u32 rx_enable_time;
  519. u32 fa_cck;
  520. u32 fa_ofdm;
  521. u32 bad_plcp_cck;
  522. u32 bad_plcp_ofdm;
  523. u32 norm_fa_ofdm;
  524. u32 norm_fa_cck;
  525. struct iwl_sensitivity_data *data = NULL;
  526. struct statistics_rx_non_phy *rx_info;
  527. struct statistics_rx_phy *ofdm, *cck;
  528. unsigned long flags;
  529. struct statistics_general_data statis;
  530. if (priv->disable_sens_cal)
  531. return;
  532. data = &(priv->sensitivity_data);
  533. if (!iwl_is_associated(priv)) {
  534. IWL_DEBUG_CALIB(priv, "<< - not associated\n");
  535. return;
  536. }
  537. spin_lock_irqsave(&priv->lock, flags);
  538. if (priv->cfg->bt_statistics) {
  539. rx_info = &(((struct iwl_bt_notif_statistics *)resp)->
  540. rx.general.common);
  541. ofdm = &(((struct iwl_bt_notif_statistics *)resp)->rx.ofdm);
  542. cck = &(((struct iwl_bt_notif_statistics *)resp)->rx.cck);
  543. } else {
  544. rx_info = &(((struct iwl_notif_statistics *)resp)->rx.general);
  545. ofdm = &(((struct iwl_notif_statistics *)resp)->rx.ofdm);
  546. cck = &(((struct iwl_notif_statistics *)resp)->rx.cck);
  547. }
  548. if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
  549. IWL_DEBUG_CALIB(priv, "<< invalid data.\n");
  550. spin_unlock_irqrestore(&priv->lock, flags);
  551. return;
  552. }
  553. /* Extract Statistics: */
  554. rx_enable_time = le32_to_cpu(rx_info->channel_load);
  555. fa_cck = le32_to_cpu(cck->false_alarm_cnt);
  556. fa_ofdm = le32_to_cpu(ofdm->false_alarm_cnt);
  557. bad_plcp_cck = le32_to_cpu(cck->plcp_err);
  558. bad_plcp_ofdm = le32_to_cpu(ofdm->plcp_err);
  559. statis.beacon_silence_rssi_a =
  560. le32_to_cpu(rx_info->beacon_silence_rssi_a);
  561. statis.beacon_silence_rssi_b =
  562. le32_to_cpu(rx_info->beacon_silence_rssi_b);
  563. statis.beacon_silence_rssi_c =
  564. le32_to_cpu(rx_info->beacon_silence_rssi_c);
  565. statis.beacon_energy_a =
  566. le32_to_cpu(rx_info->beacon_energy_a);
  567. statis.beacon_energy_b =
  568. le32_to_cpu(rx_info->beacon_energy_b);
  569. statis.beacon_energy_c =
  570. le32_to_cpu(rx_info->beacon_energy_c);
  571. spin_unlock_irqrestore(&priv->lock, flags);
  572. IWL_DEBUG_CALIB(priv, "rx_enable_time = %u usecs\n", rx_enable_time);
  573. if (!rx_enable_time) {
  574. IWL_DEBUG_CALIB(priv, "<< RX Enable Time == 0!\n");
  575. return;
  576. }
  577. /* These statistics increase monotonically, and do not reset
  578. * at each beacon. Calculate difference from last value, or just
  579. * use the new statistics value if it has reset or wrapped around. */
  580. if (data->last_bad_plcp_cnt_cck > bad_plcp_cck)
  581. data->last_bad_plcp_cnt_cck = bad_plcp_cck;
  582. else {
  583. bad_plcp_cck -= data->last_bad_plcp_cnt_cck;
  584. data->last_bad_plcp_cnt_cck += bad_plcp_cck;
  585. }
  586. if (data->last_bad_plcp_cnt_ofdm > bad_plcp_ofdm)
  587. data->last_bad_plcp_cnt_ofdm = bad_plcp_ofdm;
  588. else {
  589. bad_plcp_ofdm -= data->last_bad_plcp_cnt_ofdm;
  590. data->last_bad_plcp_cnt_ofdm += bad_plcp_ofdm;
  591. }
  592. if (data->last_fa_cnt_ofdm > fa_ofdm)
  593. data->last_fa_cnt_ofdm = fa_ofdm;
  594. else {
  595. fa_ofdm -= data->last_fa_cnt_ofdm;
  596. data->last_fa_cnt_ofdm += fa_ofdm;
  597. }
  598. if (data->last_fa_cnt_cck > fa_cck)
  599. data->last_fa_cnt_cck = fa_cck;
  600. else {
  601. fa_cck -= data->last_fa_cnt_cck;
  602. data->last_fa_cnt_cck += fa_cck;
  603. }
  604. /* Total aborted signal locks */
  605. norm_fa_ofdm = fa_ofdm + bad_plcp_ofdm;
  606. norm_fa_cck = fa_cck + bad_plcp_cck;
  607. IWL_DEBUG_CALIB(priv, "cck: fa %u badp %u ofdm: fa %u badp %u\n", fa_cck,
  608. bad_plcp_cck, fa_ofdm, bad_plcp_ofdm);
  609. iwl_sens_auto_corr_ofdm(priv, norm_fa_ofdm, rx_enable_time);
  610. iwl_sens_energy_cck(priv, norm_fa_cck, rx_enable_time, &statis);
  611. if (priv->enhance_sensitivity_table)
  612. iwl_enhance_sensitivity_write(priv);
  613. else
  614. iwl_sensitivity_write(priv);
  615. }
  616. static inline u8 find_first_chain(u8 mask)
  617. {
  618. if (mask & ANT_A)
  619. return CHAIN_A;
  620. if (mask & ANT_B)
  621. return CHAIN_B;
  622. return CHAIN_C;
  623. }
  624. /*
  625. * Accumulate 20 beacons of signal and noise statistics for each of
  626. * 3 receivers/antennas/rx-chains, then figure out:
  627. * 1) Which antennas are connected.
  628. * 2) Differential rx gain settings to balance the 3 receivers.
  629. */
  630. void iwl_chain_noise_calibration(struct iwl_priv *priv, void *stat_resp)
  631. {
  632. struct iwl_chain_noise_data *data = NULL;
  633. u32 chain_noise_a;
  634. u32 chain_noise_b;
  635. u32 chain_noise_c;
  636. u32 chain_sig_a;
  637. u32 chain_sig_b;
  638. u32 chain_sig_c;
  639. u32 average_sig[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
  640. u32 average_noise[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
  641. u32 max_average_sig;
  642. u16 max_average_sig_antenna_i;
  643. u32 min_average_noise = MIN_AVERAGE_NOISE_MAX_VALUE;
  644. u16 min_average_noise_antenna_i = INITIALIZATION_VALUE;
  645. u16 i = 0;
  646. u16 rxon_chnum = INITIALIZATION_VALUE;
  647. u16 stat_chnum = INITIALIZATION_VALUE;
  648. u8 rxon_band24;
  649. u8 stat_band24;
  650. u32 active_chains = 0;
  651. u8 num_tx_chains;
  652. unsigned long flags;
  653. struct statistics_rx_non_phy *rx_info;
  654. u8 first_chain;
  655. if (priv->disable_chain_noise_cal)
  656. return;
  657. data = &(priv->chain_noise_data);
  658. /*
  659. * Accumulate just the first "chain_noise_num_beacons" after
  660. * the first association, then we're done forever.
  661. */
  662. if (data->state != IWL_CHAIN_NOISE_ACCUMULATE) {
  663. if (data->state == IWL_CHAIN_NOISE_ALIVE)
  664. IWL_DEBUG_CALIB(priv, "Wait for noise calib reset\n");
  665. return;
  666. }
  667. spin_lock_irqsave(&priv->lock, flags);
  668. if (priv->cfg->bt_statistics) {
  669. rx_info = &(((struct iwl_bt_notif_statistics *)stat_resp)->
  670. rx.general.common);
  671. } else {
  672. rx_info = &(((struct iwl_notif_statistics *)stat_resp)->
  673. rx.general);
  674. }
  675. if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
  676. IWL_DEBUG_CALIB(priv, " << Interference data unavailable\n");
  677. spin_unlock_irqrestore(&priv->lock, flags);
  678. return;
  679. }
  680. rxon_band24 = !!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK);
  681. rxon_chnum = le16_to_cpu(priv->staging_rxon.channel);
  682. if (priv->cfg->bt_statistics) {
  683. stat_band24 = !!(((struct iwl_bt_notif_statistics *)
  684. stat_resp)->flag &
  685. STATISTICS_REPLY_FLG_BAND_24G_MSK);
  686. stat_chnum = le32_to_cpu(((struct iwl_bt_notif_statistics *)
  687. stat_resp)->flag) >> 16;
  688. } else {
  689. stat_band24 = !!(((struct iwl_notif_statistics *)
  690. stat_resp)->flag &
  691. STATISTICS_REPLY_FLG_BAND_24G_MSK);
  692. stat_chnum = le32_to_cpu(((struct iwl_notif_statistics *)
  693. stat_resp)->flag) >> 16;
  694. }
  695. /* Make sure we accumulate data for just the associated channel
  696. * (even if scanning). */
  697. if ((rxon_chnum != stat_chnum) || (rxon_band24 != stat_band24)) {
  698. IWL_DEBUG_CALIB(priv, "Stats not from chan=%d, band24=%d\n",
  699. rxon_chnum, rxon_band24);
  700. spin_unlock_irqrestore(&priv->lock, flags);
  701. return;
  702. }
  703. /*
  704. * Accumulate beacon statistics values across
  705. * "chain_noise_num_beacons"
  706. */
  707. chain_noise_a = le32_to_cpu(rx_info->beacon_silence_rssi_a) &
  708. IN_BAND_FILTER;
  709. chain_noise_b = le32_to_cpu(rx_info->beacon_silence_rssi_b) &
  710. IN_BAND_FILTER;
  711. chain_noise_c = le32_to_cpu(rx_info->beacon_silence_rssi_c) &
  712. IN_BAND_FILTER;
  713. chain_sig_a = le32_to_cpu(rx_info->beacon_rssi_a) & IN_BAND_FILTER;
  714. chain_sig_b = le32_to_cpu(rx_info->beacon_rssi_b) & IN_BAND_FILTER;
  715. chain_sig_c = le32_to_cpu(rx_info->beacon_rssi_c) & IN_BAND_FILTER;
  716. spin_unlock_irqrestore(&priv->lock, flags);
  717. data->beacon_count++;
  718. data->chain_noise_a = (chain_noise_a + data->chain_noise_a);
  719. data->chain_noise_b = (chain_noise_b + data->chain_noise_b);
  720. data->chain_noise_c = (chain_noise_c + data->chain_noise_c);
  721. data->chain_signal_a = (chain_sig_a + data->chain_signal_a);
  722. data->chain_signal_b = (chain_sig_b + data->chain_signal_b);
  723. data->chain_signal_c = (chain_sig_c + data->chain_signal_c);
  724. IWL_DEBUG_CALIB(priv, "chan=%d, band24=%d, beacon=%d\n",
  725. rxon_chnum, rxon_band24, data->beacon_count);
  726. IWL_DEBUG_CALIB(priv, "chain_sig: a %d b %d c %d\n",
  727. chain_sig_a, chain_sig_b, chain_sig_c);
  728. IWL_DEBUG_CALIB(priv, "chain_noise: a %d b %d c %d\n",
  729. chain_noise_a, chain_noise_b, chain_noise_c);
  730. /* If this is the "chain_noise_num_beacons", determine:
  731. * 1) Disconnected antennas (using signal strengths)
  732. * 2) Differential gain (using silence noise) to balance receivers */
  733. if (data->beacon_count != priv->cfg->chain_noise_num_beacons)
  734. return;
  735. /* Analyze signal for disconnected antenna */
  736. average_sig[0] =
  737. (data->chain_signal_a) / priv->cfg->chain_noise_num_beacons;
  738. average_sig[1] =
  739. (data->chain_signal_b) / priv->cfg->chain_noise_num_beacons;
  740. average_sig[2] =
  741. (data->chain_signal_c) / priv->cfg->chain_noise_num_beacons;
  742. if (average_sig[0] >= average_sig[1]) {
  743. max_average_sig = average_sig[0];
  744. max_average_sig_antenna_i = 0;
  745. active_chains = (1 << max_average_sig_antenna_i);
  746. } else {
  747. max_average_sig = average_sig[1];
  748. max_average_sig_antenna_i = 1;
  749. active_chains = (1 << max_average_sig_antenna_i);
  750. }
  751. if (average_sig[2] >= max_average_sig) {
  752. max_average_sig = average_sig[2];
  753. max_average_sig_antenna_i = 2;
  754. active_chains = (1 << max_average_sig_antenna_i);
  755. }
  756. IWL_DEBUG_CALIB(priv, "average_sig: a %d b %d c %d\n",
  757. average_sig[0], average_sig[1], average_sig[2]);
  758. IWL_DEBUG_CALIB(priv, "max_average_sig = %d, antenna %d\n",
  759. max_average_sig, max_average_sig_antenna_i);
  760. /* Compare signal strengths for all 3 receivers. */
  761. for (i = 0; i < NUM_RX_CHAINS; i++) {
  762. if (i != max_average_sig_antenna_i) {
  763. s32 rssi_delta = (max_average_sig - average_sig[i]);
  764. /* If signal is very weak, compared with
  765. * strongest, mark it as disconnected. */
  766. if (rssi_delta > MAXIMUM_ALLOWED_PATHLOSS)
  767. data->disconn_array[i] = 1;
  768. else
  769. active_chains |= (1 << i);
  770. IWL_DEBUG_CALIB(priv, "i = %d rssiDelta = %d "
  771. "disconn_array[i] = %d\n",
  772. i, rssi_delta, data->disconn_array[i]);
  773. }
  774. }
  775. /*
  776. * The above algorithm sometimes fails when the ucode
  777. * reports 0 for all chains. It's not clear why that
  778. * happens to start with, but it is then causing trouble
  779. * because this can make us enable more chains than the
  780. * hardware really has.
  781. *
  782. * To be safe, simply mask out any chains that we know
  783. * are not on the device.
  784. */
  785. active_chains &= priv->hw_params.valid_rx_ant;
  786. num_tx_chains = 0;
  787. for (i = 0; i < NUM_RX_CHAINS; i++) {
  788. /* loops on all the bits of
  789. * priv->hw_setting.valid_tx_ant */
  790. u8 ant_msk = (1 << i);
  791. if (!(priv->hw_params.valid_tx_ant & ant_msk))
  792. continue;
  793. num_tx_chains++;
  794. if (data->disconn_array[i] == 0)
  795. /* there is a Tx antenna connected */
  796. break;
  797. if (num_tx_chains == priv->hw_params.tx_chains_num &&
  798. data->disconn_array[i]) {
  799. /*
  800. * If all chains are disconnected
  801. * connect the first valid tx chain
  802. */
  803. first_chain =
  804. find_first_chain(priv->cfg->valid_tx_ant);
  805. data->disconn_array[first_chain] = 0;
  806. active_chains |= BIT(first_chain);
  807. IWL_DEBUG_CALIB(priv, "All Tx chains are disconnected W/A - declare %d as connected\n",
  808. first_chain);
  809. break;
  810. }
  811. }
  812. if (active_chains != priv->hw_params.valid_rx_ant &&
  813. active_chains != priv->chain_noise_data.active_chains)
  814. IWL_DEBUG_CALIB(priv,
  815. "Detected that not all antennas are connected! "
  816. "Connected: %#x, valid: %#x.\n",
  817. active_chains, priv->hw_params.valid_rx_ant);
  818. /* Save for use within RXON, TX, SCAN commands, etc. */
  819. priv->chain_noise_data.active_chains = active_chains;
  820. IWL_DEBUG_CALIB(priv, "active_chains (bitwise) = 0x%x\n",
  821. active_chains);
  822. /* Analyze noise for rx balance */
  823. average_noise[0] =
  824. ((data->chain_noise_a) / priv->cfg->chain_noise_num_beacons);
  825. average_noise[1] =
  826. ((data->chain_noise_b) / priv->cfg->chain_noise_num_beacons);
  827. average_noise[2] =
  828. ((data->chain_noise_c) / priv->cfg->chain_noise_num_beacons);
  829. for (i = 0; i < NUM_RX_CHAINS; i++) {
  830. if (!(data->disconn_array[i]) &&
  831. (average_noise[i] <= min_average_noise)) {
  832. /* This means that chain i is active and has
  833. * lower noise values so far: */
  834. min_average_noise = average_noise[i];
  835. min_average_noise_antenna_i = i;
  836. }
  837. }
  838. IWL_DEBUG_CALIB(priv, "average_noise: a %d b %d c %d\n",
  839. average_noise[0], average_noise[1],
  840. average_noise[2]);
  841. IWL_DEBUG_CALIB(priv, "min_average_noise = %d, antenna %d\n",
  842. min_average_noise, min_average_noise_antenna_i);
  843. if (priv->cfg->ops->utils->gain_computation)
  844. priv->cfg->ops->utils->gain_computation(priv, average_noise,
  845. min_average_noise_antenna_i, min_average_noise,
  846. find_first_chain(priv->cfg->valid_rx_ant));
  847. /* Some power changes may have been made during the calibration.
  848. * Update and commit the RXON
  849. */
  850. if (priv->cfg->ops->lib->update_chain_flags)
  851. priv->cfg->ops->lib->update_chain_flags(priv);
  852. data->state = IWL_CHAIN_NOISE_DONE;
  853. iwl_power_update_mode(priv, false);
  854. }
  855. void iwl_reset_run_time_calib(struct iwl_priv *priv)
  856. {
  857. int i;
  858. memset(&(priv->sensitivity_data), 0,
  859. sizeof(struct iwl_sensitivity_data));
  860. memset(&(priv->chain_noise_data), 0,
  861. sizeof(struct iwl_chain_noise_data));
  862. for (i = 0; i < NUM_RX_CHAINS; i++)
  863. priv->chain_noise_data.delta_gain_code[i] =
  864. CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
  865. /* Ask for statistics now, the uCode will send notification
  866. * periodically after association */
  867. iwl_send_statistics_request(priv, CMD_ASYNC, true);
  868. }