iwl-agn-rx.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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-agn-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. int num_active_rx = 0;
  66. int total_silence = 0;
  67. int bcn_silence_a, bcn_silence_b, bcn_silence_c;
  68. int last_rx_noise;
  69. if (iwl_bt_statistics(priv))
  70. rx_info = &(priv->_agn.statistics_bt.rx.general.common);
  71. else
  72. rx_info = &(priv->_agn.statistics.rx.general);
  73. bcn_silence_a =
  74. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  75. bcn_silence_b =
  76. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  77. bcn_silence_c =
  78. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  79. if (bcn_silence_a) {
  80. total_silence += bcn_silence_a;
  81. num_active_rx++;
  82. }
  83. if (bcn_silence_b) {
  84. total_silence += bcn_silence_b;
  85. num_active_rx++;
  86. }
  87. if (bcn_silence_c) {
  88. total_silence += bcn_silence_c;
  89. num_active_rx++;
  90. }
  91. /* Average among active antennas */
  92. if (num_active_rx)
  93. last_rx_noise = (total_silence / num_active_rx) - 107;
  94. else
  95. last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  96. IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
  97. bcn_silence_a, bcn_silence_b, bcn_silence_c,
  98. last_rx_noise);
  99. }
  100. #ifdef CONFIG_IWLWIFI_DEBUGFS
  101. /*
  102. * based on the assumption of all statistics counter are in DWORD
  103. * FIXME: This function is for debugging, do not deal with
  104. * the case of counters roll-over.
  105. */
  106. static void iwl_accumulative_statistics(struct iwl_priv *priv,
  107. __le32 *stats)
  108. {
  109. int i, size;
  110. __le32 *prev_stats;
  111. u32 *accum_stats;
  112. u32 *delta, *max_delta;
  113. struct statistics_general_common *general, *accum_general;
  114. struct statistics_tx *tx, *accum_tx;
  115. if (iwl_bt_statistics(priv)) {
  116. prev_stats = (__le32 *)&priv->_agn.statistics_bt;
  117. accum_stats = (u32 *)&priv->_agn.accum_statistics_bt;
  118. size = sizeof(struct iwl_bt_notif_statistics);
  119. general = &priv->_agn.statistics_bt.general.common;
  120. accum_general = &priv->_agn.accum_statistics_bt.general.common;
  121. tx = &priv->_agn.statistics_bt.tx;
  122. accum_tx = &priv->_agn.accum_statistics_bt.tx;
  123. delta = (u32 *)&priv->_agn.delta_statistics_bt;
  124. max_delta = (u32 *)&priv->_agn.max_delta_bt;
  125. } else {
  126. prev_stats = (__le32 *)&priv->_agn.statistics;
  127. accum_stats = (u32 *)&priv->_agn.accum_statistics;
  128. size = sizeof(struct iwl_notif_statistics);
  129. general = &priv->_agn.statistics.general.common;
  130. accum_general = &priv->_agn.accum_statistics.general.common;
  131. tx = &priv->_agn.statistics.tx;
  132. accum_tx = &priv->_agn.accum_statistics.tx;
  133. delta = (u32 *)&priv->_agn.delta_statistics;
  134. max_delta = (u32 *)&priv->_agn.max_delta;
  135. }
  136. for (i = sizeof(__le32); i < size;
  137. i += sizeof(__le32), stats++, prev_stats++, delta++,
  138. max_delta++, accum_stats++) {
  139. if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
  140. *delta = (le32_to_cpu(*stats) -
  141. le32_to_cpu(*prev_stats));
  142. *accum_stats += *delta;
  143. if (*delta > *max_delta)
  144. *max_delta = *delta;
  145. }
  146. }
  147. /* reset accumulative statistics for "no-counter" type statistics */
  148. accum_general->temperature = general->temperature;
  149. accum_general->temperature_m = general->temperature_m;
  150. accum_general->ttl_timestamp = general->ttl_timestamp;
  151. accum_tx->tx_power.ant_a = tx->tx_power.ant_a;
  152. accum_tx->tx_power.ant_b = tx->tx_power.ant_b;
  153. accum_tx->tx_power.ant_c = tx->tx_power.ant_c;
  154. }
  155. #endif
  156. #define REG_RECALIB_PERIOD (60)
  157. void iwl_rx_statistics(struct iwl_priv *priv,
  158. struct iwl_rx_mem_buffer *rxb)
  159. {
  160. int change;
  161. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  162. if (iwl_bt_statistics(priv)) {
  163. IWL_DEBUG_RX(priv,
  164. "Statistics notification received (%d vs %d).\n",
  165. (int)sizeof(struct iwl_bt_notif_statistics),
  166. le32_to_cpu(pkt->len_n_flags) &
  167. FH_RSCSR_FRAME_SIZE_MSK);
  168. change = ((priv->_agn.statistics_bt.general.common.temperature !=
  169. pkt->u.stats_bt.general.common.temperature) ||
  170. ((priv->_agn.statistics_bt.flag &
  171. STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  172. (pkt->u.stats_bt.flag &
  173. STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
  174. #ifdef CONFIG_IWLWIFI_DEBUGFS
  175. iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats_bt);
  176. #endif
  177. } else {
  178. IWL_DEBUG_RX(priv,
  179. "Statistics notification received (%d vs %d).\n",
  180. (int)sizeof(struct iwl_notif_statistics),
  181. le32_to_cpu(pkt->len_n_flags) &
  182. FH_RSCSR_FRAME_SIZE_MSK);
  183. change = ((priv->_agn.statistics.general.common.temperature !=
  184. pkt->u.stats.general.common.temperature) ||
  185. ((priv->_agn.statistics.flag &
  186. STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  187. (pkt->u.stats.flag &
  188. STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
  189. #ifdef CONFIG_IWLWIFI_DEBUGFS
  190. iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats);
  191. #endif
  192. }
  193. iwl_recover_from_statistics(priv, pkt);
  194. if (iwl_bt_statistics(priv))
  195. memcpy(&priv->_agn.statistics_bt, &pkt->u.stats_bt,
  196. sizeof(priv->_agn.statistics_bt));
  197. else
  198. memcpy(&priv->_agn.statistics, &pkt->u.stats,
  199. sizeof(priv->_agn.statistics));
  200. set_bit(STATUS_STATISTICS, &priv->status);
  201. /* Reschedule the statistics timer to occur in
  202. * REG_RECALIB_PERIOD seconds to ensure we get a
  203. * thermal update even if the uCode doesn't give
  204. * us one */
  205. mod_timer(&priv->statistics_periodic, jiffies +
  206. msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  207. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  208. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  209. iwl_rx_calc_noise(priv);
  210. queue_work(priv->workqueue, &priv->run_time_calib_work);
  211. }
  212. if (priv->cfg->ops->lib->temp_ops.temperature && change)
  213. priv->cfg->ops->lib->temp_ops.temperature(priv);
  214. }
  215. void iwl_reply_statistics(struct iwl_priv *priv,
  216. struct iwl_rx_mem_buffer *rxb)
  217. {
  218. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  219. if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
  220. #ifdef CONFIG_IWLWIFI_DEBUGFS
  221. memset(&priv->_agn.accum_statistics, 0,
  222. sizeof(struct iwl_notif_statistics));
  223. memset(&priv->_agn.delta_statistics, 0,
  224. sizeof(struct iwl_notif_statistics));
  225. memset(&priv->_agn.max_delta, 0,
  226. sizeof(struct iwl_notif_statistics));
  227. memset(&priv->_agn.accum_statistics_bt, 0,
  228. sizeof(struct iwl_bt_notif_statistics));
  229. memset(&priv->_agn.delta_statistics_bt, 0,
  230. sizeof(struct iwl_bt_notif_statistics));
  231. memset(&priv->_agn.max_delta_bt, 0,
  232. sizeof(struct iwl_bt_notif_statistics));
  233. #endif
  234. IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
  235. }
  236. iwl_rx_statistics(priv, rxb);
  237. }