iwl-agn-rx.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/sched.h>
  33. #include "iwl-dev.h"
  34. #include "iwl-core.h"
  35. #include "iwl-calib.h"
  36. #include "iwl-sta.h"
  37. #include "iwl-io.h"
  38. #include "iwl-helpers.h"
  39. #include "iwl-agn-hw.h"
  40. #include "iwl-agn.h"
  41. void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
  42. struct iwl_rx_mem_buffer *rxb)
  43. {
  44. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  45. struct iwl_missed_beacon_notif *missed_beacon;
  46. missed_beacon = &pkt->u.missed_beacon;
  47. if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
  48. priv->missed_beacon_threshold) {
  49. IWL_DEBUG_CALIB(priv,
  50. "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
  51. le32_to_cpu(missed_beacon->consecutive_missed_beacons),
  52. le32_to_cpu(missed_beacon->total_missed_becons),
  53. le32_to_cpu(missed_beacon->num_recvd_beacons),
  54. le32_to_cpu(missed_beacon->num_expected_beacons));
  55. if (!test_bit(STATUS_SCANNING, &priv->status))
  56. iwl_init_sensitivity(priv);
  57. }
  58. }
  59. /* Calculate noise level, based on measurements during network silence just
  60. * before arriving beacon. This measurement can be done only if we know
  61. * exactly when to expect beacons, therefore only when we're associated. */
  62. static void iwl_rx_calc_noise(struct iwl_priv *priv)
  63. {
  64. struct statistics_rx_non_phy *rx_info
  65. = &(priv->_agn.statistics.rx.general);
  66. int num_active_rx = 0;
  67. int total_silence = 0;
  68. int bcn_silence_a =
  69. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  70. int bcn_silence_b =
  71. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  72. int bcn_silence_c =
  73. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  74. int last_rx_noise;
  75. if (bcn_silence_a) {
  76. total_silence += bcn_silence_a;
  77. num_active_rx++;
  78. }
  79. if (bcn_silence_b) {
  80. total_silence += bcn_silence_b;
  81. num_active_rx++;
  82. }
  83. if (bcn_silence_c) {
  84. total_silence += bcn_silence_c;
  85. num_active_rx++;
  86. }
  87. /* Average among active antennas */
  88. if (num_active_rx)
  89. last_rx_noise = (total_silence / num_active_rx) - 107;
  90. else
  91. last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  92. IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
  93. bcn_silence_a, bcn_silence_b, bcn_silence_c,
  94. last_rx_noise);
  95. }
  96. #ifdef CONFIG_IWLWIFI_DEBUGFS
  97. /*
  98. * based on the assumption of all statistics counter are in DWORD
  99. * FIXME: This function is for debugging, do not deal with
  100. * the case of counters roll-over.
  101. */
  102. static void iwl_accumulative_statistics(struct iwl_priv *priv,
  103. __le32 *stats)
  104. {
  105. int i;
  106. __le32 *prev_stats;
  107. u32 *accum_stats;
  108. u32 *delta, *max_delta;
  109. prev_stats = (__le32 *)&priv->_agn.statistics;
  110. accum_stats = (u32 *)&priv->_agn.accum_statistics;
  111. delta = (u32 *)&priv->_agn.delta_statistics;
  112. max_delta = (u32 *)&priv->_agn.max_delta;
  113. for (i = sizeof(__le32); i < sizeof(struct iwl_notif_statistics);
  114. i += sizeof(__le32), stats++, prev_stats++, delta++,
  115. max_delta++, accum_stats++) {
  116. if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
  117. *delta = (le32_to_cpu(*stats) -
  118. le32_to_cpu(*prev_stats));
  119. *accum_stats += *delta;
  120. if (*delta > *max_delta)
  121. *max_delta = *delta;
  122. }
  123. }
  124. /* reset accumulative statistics for "no-counter" type statistics */
  125. priv->_agn.accum_statistics.general.temperature =
  126. priv->_agn.statistics.general.temperature;
  127. priv->_agn.accum_statistics.general.temperature_m =
  128. priv->_agn.statistics.general.temperature_m;
  129. priv->_agn.accum_statistics.general.ttl_timestamp =
  130. priv->_agn.statistics.general.ttl_timestamp;
  131. priv->_agn.accum_statistics.tx.tx_power.ant_a =
  132. priv->_agn.statistics.tx.tx_power.ant_a;
  133. priv->_agn.accum_statistics.tx.tx_power.ant_b =
  134. priv->_agn.statistics.tx.tx_power.ant_b;
  135. priv->_agn.accum_statistics.tx.tx_power.ant_c =
  136. priv->_agn.statistics.tx.tx_power.ant_c;
  137. }
  138. #endif
  139. #define REG_RECALIB_PERIOD (60)
  140. /**
  141. * iwl_good_plcp_health - checks for plcp error.
  142. *
  143. * When the plcp error is exceeding the thresholds, reset the radio
  144. * to improve the throughput.
  145. */
  146. bool iwl_good_plcp_health(struct iwl_priv *priv,
  147. struct iwl_rx_packet *pkt)
  148. {
  149. bool rc = true;
  150. int combined_plcp_delta;
  151. unsigned int plcp_msec;
  152. unsigned long plcp_received_jiffies;
  153. if (priv->cfg->plcp_delta_threshold ==
  154. IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
  155. IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
  156. return rc;
  157. }
  158. /*
  159. * check for plcp_err and trigger radio reset if it exceeds
  160. * the plcp error threshold plcp_delta.
  161. */
  162. plcp_received_jiffies = jiffies;
  163. plcp_msec = jiffies_to_msecs((long) plcp_received_jiffies -
  164. (long) priv->plcp_jiffies);
  165. priv->plcp_jiffies = plcp_received_jiffies;
  166. /*
  167. * check to make sure plcp_msec is not 0 to prevent division
  168. * by zero.
  169. */
  170. if (plcp_msec) {
  171. combined_plcp_delta =
  172. (le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err) -
  173. le32_to_cpu(priv->_agn.statistics.rx.ofdm.plcp_err)) +
  174. (le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err) -
  175. le32_to_cpu(priv->_agn.statistics.rx.ofdm_ht.plcp_err));
  176. if ((combined_plcp_delta > 0) &&
  177. ((combined_plcp_delta * 100) / plcp_msec) >
  178. priv->cfg->plcp_delta_threshold) {
  179. /*
  180. * if plcp_err exceed the threshold,
  181. * the following data is printed in csv format:
  182. * Text: plcp_err exceeded %d,
  183. * Received ofdm.plcp_err,
  184. * Current ofdm.plcp_err,
  185. * Received ofdm_ht.plcp_err,
  186. * Current ofdm_ht.plcp_err,
  187. * combined_plcp_delta,
  188. * plcp_msec
  189. */
  190. IWL_DEBUG_RADIO(priv, "plcp_err exceeded %u, "
  191. "%u, %u, %u, %u, %d, %u mSecs\n",
  192. priv->cfg->plcp_delta_threshold,
  193. le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err),
  194. le32_to_cpu(
  195. priv->_agn.statistics.rx.ofdm.plcp_err),
  196. le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err),
  197. le32_to_cpu(
  198. priv->_agn.statistics.rx.ofdm_ht.plcp_err),
  199. combined_plcp_delta, plcp_msec);
  200. rc = false;
  201. }
  202. }
  203. return rc;
  204. }
  205. void iwl_rx_statistics(struct iwl_priv *priv,
  206. struct iwl_rx_mem_buffer *rxb)
  207. {
  208. int change;
  209. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  210. IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n",
  211. (int)sizeof(priv->_agn.statistics),
  212. le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
  213. change = ((priv->_agn.statistics.general.temperature !=
  214. pkt->u.stats.general.temperature) ||
  215. ((priv->_agn.statistics.flag &
  216. STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  217. (pkt->u.stats.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
  218. #ifdef CONFIG_IWLWIFI_DEBUGFS
  219. iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats);
  220. #endif
  221. iwl_recover_from_statistics(priv, pkt);
  222. memcpy(&priv->_agn.statistics, &pkt->u.stats,
  223. sizeof(priv->_agn.statistics));
  224. set_bit(STATUS_STATISTICS, &priv->status);
  225. /* Reschedule the statistics timer to occur in
  226. * REG_RECALIB_PERIOD seconds to ensure we get a
  227. * thermal update even if the uCode doesn't give
  228. * us one */
  229. mod_timer(&priv->statistics_periodic, jiffies +
  230. msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  231. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  232. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  233. iwl_rx_calc_noise(priv);
  234. queue_work(priv->workqueue, &priv->run_time_calib_work);
  235. }
  236. if (priv->cfg->ops->lib->temp_ops.temperature && change)
  237. priv->cfg->ops->lib->temp_ops.temperature(priv);
  238. }
  239. void iwl_reply_statistics(struct iwl_priv *priv,
  240. struct iwl_rx_mem_buffer *rxb)
  241. {
  242. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  243. if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
  244. #ifdef CONFIG_IWLWIFI_DEBUGFS
  245. memset(&priv->_agn.accum_statistics, 0,
  246. sizeof(struct iwl_notif_statistics));
  247. memset(&priv->_agn.delta_statistics, 0,
  248. sizeof(struct iwl_notif_statistics));
  249. memset(&priv->_agn.max_delta, 0,
  250. sizeof(struct iwl_notif_statistics));
  251. #endif
  252. IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
  253. }
  254. iwl_rx_statistics(priv, rxb);
  255. }