iwl-4965-rx.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 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-4965-calib.h"
  36. #include "iwl-sta.h"
  37. #include "iwl-io.h"
  38. #include "iwl-helpers.h"
  39. #include "iwl-4965-hw.h"
  40. #include "iwl-4965.h"
  41. void iwl4965_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. iwl4965_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 iwl4965_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. rx_info = &(priv->_4965.statistics.rx.general);
  70. bcn_silence_a =
  71. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  72. bcn_silence_b =
  73. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  74. bcn_silence_c =
  75. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  76. if (bcn_silence_a) {
  77. total_silence += bcn_silence_a;
  78. num_active_rx++;
  79. }
  80. if (bcn_silence_b) {
  81. total_silence += bcn_silence_b;
  82. num_active_rx++;
  83. }
  84. if (bcn_silence_c) {
  85. total_silence += bcn_silence_c;
  86. num_active_rx++;
  87. }
  88. /* Average among active antennas */
  89. if (num_active_rx)
  90. last_rx_noise = (total_silence / num_active_rx) - 107;
  91. else
  92. last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  93. IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
  94. bcn_silence_a, bcn_silence_b, bcn_silence_c,
  95. last_rx_noise);
  96. }
  97. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
  98. /*
  99. * based on the assumption of all statistics counter are in DWORD
  100. * FIXME: This function is for debugging, do not deal with
  101. * the case of counters roll-over.
  102. */
  103. static void iwl4965_accumulative_statistics(struct iwl_priv *priv,
  104. __le32 *stats)
  105. {
  106. int i, size;
  107. __le32 *prev_stats;
  108. u32 *accum_stats;
  109. u32 *delta, *max_delta;
  110. struct statistics_general_common *general, *accum_general;
  111. struct statistics_tx *tx, *accum_tx;
  112. prev_stats = (__le32 *)&priv->_4965.statistics;
  113. accum_stats = (u32 *)&priv->_4965.accum_statistics;
  114. size = sizeof(struct iwl_notif_statistics);
  115. general = &priv->_4965.statistics.general.common;
  116. accum_general = &priv->_4965.accum_statistics.general.common;
  117. tx = &priv->_4965.statistics.tx;
  118. accum_tx = &priv->_4965.accum_statistics.tx;
  119. delta = (u32 *)&priv->_4965.delta_statistics;
  120. max_delta = (u32 *)&priv->_4965.max_delta;
  121. for (i = sizeof(__le32); i < size;
  122. i += sizeof(__le32), stats++, prev_stats++, delta++,
  123. max_delta++, accum_stats++) {
  124. if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
  125. *delta = (le32_to_cpu(*stats) -
  126. le32_to_cpu(*prev_stats));
  127. *accum_stats += *delta;
  128. if (*delta > *max_delta)
  129. *max_delta = *delta;
  130. }
  131. }
  132. /* reset accumulative statistics for "no-counter" type statistics */
  133. accum_general->temperature = general->temperature;
  134. accum_general->ttl_timestamp = general->ttl_timestamp;
  135. }
  136. #endif
  137. #define REG_RECALIB_PERIOD (60)
  138. /**
  139. * iwl4965_good_plcp_health - checks for plcp error.
  140. *
  141. * When the plcp error is exceeding the thresholds, reset the radio
  142. * to improve the throughput.
  143. */
  144. bool iwl4965_good_plcp_health(struct iwl_priv *priv,
  145. struct iwl_rx_packet *pkt)
  146. {
  147. bool rc = true;
  148. int combined_plcp_delta;
  149. unsigned int plcp_msec;
  150. unsigned long plcp_received_jiffies;
  151. if (priv->cfg->base_params->plcp_delta_threshold ==
  152. IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
  153. IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
  154. return rc;
  155. }
  156. /*
  157. * check for plcp_err and trigger radio reset if it exceeds
  158. * the plcp error threshold plcp_delta.
  159. */
  160. plcp_received_jiffies = jiffies;
  161. plcp_msec = jiffies_to_msecs((long) plcp_received_jiffies -
  162. (long) priv->plcp_jiffies);
  163. priv->plcp_jiffies = plcp_received_jiffies;
  164. /*
  165. * check to make sure plcp_msec is not 0 to prevent division
  166. * by zero.
  167. */
  168. if (plcp_msec) {
  169. struct statistics_rx_phy *ofdm;
  170. struct statistics_rx_ht_phy *ofdm_ht;
  171. ofdm = &pkt->u.stats.rx.ofdm;
  172. ofdm_ht = &pkt->u.stats.rx.ofdm_ht;
  173. combined_plcp_delta =
  174. (le32_to_cpu(ofdm->plcp_err) -
  175. le32_to_cpu(priv->_4965.statistics.
  176. rx.ofdm.plcp_err)) +
  177. (le32_to_cpu(ofdm_ht->plcp_err) -
  178. le32_to_cpu(priv->_4965.statistics.
  179. rx.ofdm_ht.plcp_err));
  180. if ((combined_plcp_delta > 0) &&
  181. ((combined_plcp_delta * 100) / plcp_msec) >
  182. priv->cfg->base_params->plcp_delta_threshold) {
  183. /*
  184. * if plcp_err exceed the threshold,
  185. * the following data is printed in csv format:
  186. * Text: plcp_err exceeded %d,
  187. * Received ofdm.plcp_err,
  188. * Current ofdm.plcp_err,
  189. * Received ofdm_ht.plcp_err,
  190. * Current ofdm_ht.plcp_err,
  191. * combined_plcp_delta,
  192. * plcp_msec
  193. */
  194. IWL_DEBUG_RADIO(priv, "plcp_err exceeded %u, "
  195. "%u, %u, %u, %u, %d, %u mSecs\n",
  196. priv->cfg->base_params->plcp_delta_threshold,
  197. le32_to_cpu(ofdm->plcp_err),
  198. le32_to_cpu(ofdm->plcp_err),
  199. le32_to_cpu(ofdm_ht->plcp_err),
  200. le32_to_cpu(ofdm_ht->plcp_err),
  201. combined_plcp_delta, plcp_msec);
  202. rc = false;
  203. }
  204. }
  205. return rc;
  206. }
  207. void iwl4965_rx_statistics(struct iwl_priv *priv,
  208. struct iwl_rx_mem_buffer *rxb)
  209. {
  210. int change;
  211. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  212. IWL_DEBUG_RX(priv,
  213. "Statistics notification received (%d vs %d).\n",
  214. (int)sizeof(struct iwl_notif_statistics),
  215. le32_to_cpu(pkt->len_n_flags) &
  216. FH_RSCSR_FRAME_SIZE_MSK);
  217. change = ((priv->_4965.statistics.general.common.temperature !=
  218. pkt->u.stats.general.common.temperature) ||
  219. ((priv->_4965.statistics.flag &
  220. STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  221. (pkt->u.stats.flag &
  222. STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
  223. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
  224. iwl4965_accumulative_statistics(priv, (__le32 *)&pkt->u.stats);
  225. #endif
  226. iwl_legacy_recover_from_statistics(priv, pkt);
  227. memcpy(&priv->_4965.statistics, &pkt->u.stats,
  228. sizeof(priv->_4965.statistics));
  229. set_bit(STATUS_STATISTICS, &priv->status);
  230. /* Reschedule the statistics timer to occur in
  231. * REG_RECALIB_PERIOD seconds to ensure we get a
  232. * thermal update even if the uCode doesn't give
  233. * us one */
  234. mod_timer(&priv->statistics_periodic, jiffies +
  235. msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  236. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  237. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  238. iwl4965_rx_calc_noise(priv);
  239. queue_work(priv->workqueue, &priv->run_time_calib_work);
  240. }
  241. if (priv->cfg->ops->lib->temp_ops.temperature && change)
  242. priv->cfg->ops->lib->temp_ops.temperature(priv);
  243. }
  244. void iwl4965_reply_statistics(struct iwl_priv *priv,
  245. struct iwl_rx_mem_buffer *rxb)
  246. {
  247. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  248. if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
  249. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
  250. memset(&priv->_4965.accum_statistics, 0,
  251. sizeof(struct iwl_notif_statistics));
  252. memset(&priv->_4965.delta_statistics, 0,
  253. sizeof(struct iwl_notif_statistics));
  254. memset(&priv->_4965.max_delta, 0,
  255. sizeof(struct iwl_notif_statistics));
  256. #endif
  257. IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
  258. }
  259. iwl4965_rx_statistics(priv, rxb);
  260. }