iwl-agn-rx.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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->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->statistics;
  110. accum_stats = (u32 *)&priv->accum_statistics;
  111. delta = (u32 *)&priv->delta_statistics;
  112. max_delta = (u32 *)&priv->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->accum_statistics.general.temperature =
  126. priv->statistics.general.temperature;
  127. priv->accum_statistics.general.temperature_m =
  128. priv->statistics.general.temperature_m;
  129. priv->accum_statistics.general.ttl_timestamp =
  130. priv->statistics.general.ttl_timestamp;
  131. priv->accum_statistics.tx.tx_power.ant_a =
  132. priv->statistics.tx.tx_power.ant_a;
  133. priv->accum_statistics.tx.tx_power.ant_b =
  134. priv->statistics.tx.tx_power.ant_b;
  135. priv->accum_statistics.tx.tx_power.ant_c =
  136. priv->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. /*
  154. * check for plcp_err and trigger radio reset if it exceeds
  155. * the plcp error threshold plcp_delta.
  156. */
  157. plcp_received_jiffies = jiffies;
  158. plcp_msec = jiffies_to_msecs((long) plcp_received_jiffies -
  159. (long) priv->plcp_jiffies);
  160. priv->plcp_jiffies = plcp_received_jiffies;
  161. /*
  162. * check to make sure plcp_msec is not 0 to prevent division
  163. * by zero.
  164. */
  165. if (plcp_msec) {
  166. combined_plcp_delta =
  167. (le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err) -
  168. le32_to_cpu(priv->statistics.rx.ofdm.plcp_err)) +
  169. (le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err) -
  170. le32_to_cpu(priv->statistics.rx.ofdm_ht.plcp_err));
  171. if ((combined_plcp_delta > 0) &&
  172. ((combined_plcp_delta * 100) / plcp_msec) >
  173. priv->cfg->plcp_delta_threshold) {
  174. /*
  175. * if plcp_err exceed the threshold,
  176. * the following data is printed in csv format:
  177. * Text: plcp_err exceeded %d,
  178. * Received ofdm.plcp_err,
  179. * Current ofdm.plcp_err,
  180. * Received ofdm_ht.plcp_err,
  181. * Current ofdm_ht.plcp_err,
  182. * combined_plcp_delta,
  183. * plcp_msec
  184. */
  185. IWL_DEBUG_RADIO(priv, "plcp_err exceeded %u, "
  186. "%u, %u, %u, %u, %d, %u mSecs\n",
  187. priv->cfg->plcp_delta_threshold,
  188. le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err),
  189. le32_to_cpu(
  190. priv->statistics.rx.ofdm.plcp_err),
  191. le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err),
  192. le32_to_cpu(
  193. priv->statistics.rx.ofdm_ht.plcp_err),
  194. combined_plcp_delta, plcp_msec);
  195. rc = false;
  196. }
  197. }
  198. return rc;
  199. }
  200. void iwl_rx_statistics(struct iwl_priv *priv,
  201. struct iwl_rx_mem_buffer *rxb)
  202. {
  203. int change;
  204. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  205. IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n",
  206. (int)sizeof(priv->statistics),
  207. le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK);
  208. change = ((priv->statistics.general.temperature !=
  209. pkt->u.stats.general.temperature) ||
  210. ((priv->statistics.flag &
  211. STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  212. (pkt->u.stats.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
  213. #ifdef CONFIG_IWLWIFI_DEBUGFS
  214. iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats);
  215. #endif
  216. iwl_recover_from_statistics(priv, pkt);
  217. memcpy(&priv->statistics, &pkt->u.stats,
  218. sizeof(priv->statistics));
  219. set_bit(STATUS_STATISTICS, &priv->status);
  220. /* Reschedule the statistics timer to occur in
  221. * REG_RECALIB_PERIOD seconds to ensure we get a
  222. * thermal update even if the uCode doesn't give
  223. * us one */
  224. mod_timer(&priv->statistics_periodic, jiffies +
  225. msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  226. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  227. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  228. iwl_rx_calc_noise(priv);
  229. queue_work(priv->workqueue, &priv->run_time_calib_work);
  230. }
  231. if (priv->cfg->ops->lib->temp_ops.temperature && change)
  232. priv->cfg->ops->lib->temp_ops.temperature(priv);
  233. }
  234. void iwl_reply_statistics(struct iwl_priv *priv,
  235. struct iwl_rx_mem_buffer *rxb)
  236. {
  237. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  238. if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
  239. #ifdef CONFIG_IWLWIFI_DEBUGFS
  240. memset(&priv->accum_statistics, 0,
  241. sizeof(struct iwl_notif_statistics));
  242. memset(&priv->delta_statistics, 0,
  243. sizeof(struct iwl_notif_statistics));
  244. memset(&priv->max_delta, 0,
  245. sizeof(struct iwl_notif_statistics));
  246. #endif
  247. IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
  248. }
  249. iwl_rx_statistics(priv, rxb);
  250. }