iwl-agn-rx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. 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 (priv->cfg->bt_params &&
  70. priv->cfg->bt_params->bt_statistics)
  71. rx_info = &(priv->_agn.statistics_bt.rx.general.common);
  72. else
  73. rx_info = &(priv->_agn.statistics.rx.general);
  74. bcn_silence_a =
  75. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  76. bcn_silence_b =
  77. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  78. bcn_silence_c =
  79. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  80. if (bcn_silence_a) {
  81. total_silence += bcn_silence_a;
  82. num_active_rx++;
  83. }
  84. if (bcn_silence_b) {
  85. total_silence += bcn_silence_b;
  86. num_active_rx++;
  87. }
  88. if (bcn_silence_c) {
  89. total_silence += bcn_silence_c;
  90. num_active_rx++;
  91. }
  92. /* Average among active antennas */
  93. if (num_active_rx)
  94. last_rx_noise = (total_silence / num_active_rx) - 107;
  95. else
  96. last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  97. IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
  98. bcn_silence_a, bcn_silence_b, bcn_silence_c,
  99. last_rx_noise);
  100. }
  101. #ifdef CONFIG_IWLWIFI_DEBUGFS
  102. /*
  103. * based on the assumption of all statistics counter are in DWORD
  104. * FIXME: This function is for debugging, do not deal with
  105. * the case of counters roll-over.
  106. */
  107. static void iwl_accumulative_statistics(struct iwl_priv *priv,
  108. __le32 *stats)
  109. {
  110. int i, size;
  111. __le32 *prev_stats;
  112. u32 *accum_stats;
  113. u32 *delta, *max_delta;
  114. struct statistics_general_common *general, *accum_general;
  115. struct statistics_tx *tx, *accum_tx;
  116. if (priv->cfg->bt_params &&
  117. priv->cfg->bt_params->bt_statistics) {
  118. prev_stats = (__le32 *)&priv->_agn.statistics_bt;
  119. accum_stats = (u32 *)&priv->_agn.accum_statistics_bt;
  120. size = sizeof(struct iwl_bt_notif_statistics);
  121. general = &priv->_agn.statistics_bt.general.common;
  122. accum_general = &priv->_agn.accum_statistics_bt.general.common;
  123. tx = &priv->_agn.statistics_bt.tx;
  124. accum_tx = &priv->_agn.accum_statistics_bt.tx;
  125. delta = (u32 *)&priv->_agn.delta_statistics_bt;
  126. max_delta = (u32 *)&priv->_agn.max_delta_bt;
  127. } else {
  128. prev_stats = (__le32 *)&priv->_agn.statistics;
  129. accum_stats = (u32 *)&priv->_agn.accum_statistics;
  130. size = sizeof(struct iwl_notif_statistics);
  131. general = &priv->_agn.statistics.general.common;
  132. accum_general = &priv->_agn.accum_statistics.general.common;
  133. tx = &priv->_agn.statistics.tx;
  134. accum_tx = &priv->_agn.accum_statistics.tx;
  135. delta = (u32 *)&priv->_agn.delta_statistics;
  136. max_delta = (u32 *)&priv->_agn.max_delta;
  137. }
  138. for (i = sizeof(__le32); i < size;
  139. i += sizeof(__le32), stats++, prev_stats++, delta++,
  140. max_delta++, accum_stats++) {
  141. if (le32_to_cpu(*stats) > le32_to_cpu(*prev_stats)) {
  142. *delta = (le32_to_cpu(*stats) -
  143. le32_to_cpu(*prev_stats));
  144. *accum_stats += *delta;
  145. if (*delta > *max_delta)
  146. *max_delta = *delta;
  147. }
  148. }
  149. /* reset accumulative statistics for "no-counter" type statistics */
  150. accum_general->temperature = general->temperature;
  151. accum_general->temperature_m = general->temperature_m;
  152. accum_general->ttl_timestamp = general->ttl_timestamp;
  153. accum_tx->tx_power.ant_a = tx->tx_power.ant_a;
  154. accum_tx->tx_power.ant_b = tx->tx_power.ant_b;
  155. accum_tx->tx_power.ant_c = tx->tx_power.ant_c;
  156. }
  157. #endif
  158. #define REG_RECALIB_PERIOD (60)
  159. /**
  160. * iwl_good_plcp_health - checks for plcp error.
  161. *
  162. * When the plcp error is exceeding the thresholds, reset the radio
  163. * to improve the throughput.
  164. */
  165. bool iwl_good_plcp_health(struct iwl_priv *priv,
  166. struct iwl_rx_packet *pkt)
  167. {
  168. bool rc = true;
  169. int combined_plcp_delta;
  170. unsigned int plcp_msec;
  171. unsigned long plcp_received_jiffies;
  172. if (priv->cfg->base_params->plcp_delta_threshold ==
  173. IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
  174. IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
  175. return rc;
  176. }
  177. /*
  178. * check for plcp_err and trigger radio reset if it exceeds
  179. * the plcp error threshold plcp_delta.
  180. */
  181. plcp_received_jiffies = jiffies;
  182. plcp_msec = jiffies_to_msecs((long) plcp_received_jiffies -
  183. (long) priv->plcp_jiffies);
  184. priv->plcp_jiffies = plcp_received_jiffies;
  185. /*
  186. * check to make sure plcp_msec is not 0 to prevent division
  187. * by zero.
  188. */
  189. if (plcp_msec) {
  190. struct statistics_rx_phy *ofdm;
  191. struct statistics_rx_ht_phy *ofdm_ht;
  192. if (priv->cfg->bt_params &&
  193. priv->cfg->bt_params->bt_statistics) {
  194. ofdm = &pkt->u.stats_bt.rx.ofdm;
  195. ofdm_ht = &pkt->u.stats_bt.rx.ofdm_ht;
  196. combined_plcp_delta =
  197. (le32_to_cpu(ofdm->plcp_err) -
  198. le32_to_cpu(priv->_agn.statistics_bt.
  199. rx.ofdm.plcp_err)) +
  200. (le32_to_cpu(ofdm_ht->plcp_err) -
  201. le32_to_cpu(priv->_agn.statistics_bt.
  202. rx.ofdm_ht.plcp_err));
  203. } else {
  204. ofdm = &pkt->u.stats.rx.ofdm;
  205. ofdm_ht = &pkt->u.stats.rx.ofdm_ht;
  206. combined_plcp_delta =
  207. (le32_to_cpu(ofdm->plcp_err) -
  208. le32_to_cpu(priv->_agn.statistics.
  209. rx.ofdm.plcp_err)) +
  210. (le32_to_cpu(ofdm_ht->plcp_err) -
  211. le32_to_cpu(priv->_agn.statistics.
  212. rx.ofdm_ht.plcp_err));
  213. }
  214. if ((combined_plcp_delta > 0) &&
  215. ((combined_plcp_delta * 100) / plcp_msec) >
  216. priv->cfg->base_params->plcp_delta_threshold) {
  217. /*
  218. * if plcp_err exceed the threshold,
  219. * the following data is printed in csv format:
  220. * Text: plcp_err exceeded %d,
  221. * Received ofdm.plcp_err,
  222. * Current ofdm.plcp_err,
  223. * Received ofdm_ht.plcp_err,
  224. * Current ofdm_ht.plcp_err,
  225. * combined_plcp_delta,
  226. * plcp_msec
  227. */
  228. IWL_DEBUG_RADIO(priv, "plcp_err exceeded %u, "
  229. "%u, %u, %u, %u, %d, %u mSecs\n",
  230. priv->cfg->base_params->plcp_delta_threshold,
  231. le32_to_cpu(ofdm->plcp_err),
  232. le32_to_cpu(ofdm->plcp_err),
  233. le32_to_cpu(ofdm_ht->plcp_err),
  234. le32_to_cpu(ofdm_ht->plcp_err),
  235. combined_plcp_delta, plcp_msec);
  236. rc = false;
  237. }
  238. }
  239. return rc;
  240. }
  241. void iwl_rx_statistics(struct iwl_priv *priv,
  242. struct iwl_rx_mem_buffer *rxb)
  243. {
  244. int change;
  245. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  246. if (priv->cfg->bt_params &&
  247. priv->cfg->bt_params->bt_statistics) {
  248. IWL_DEBUG_RX(priv,
  249. "Statistics notification received (%d vs %d).\n",
  250. (int)sizeof(struct iwl_bt_notif_statistics),
  251. le32_to_cpu(pkt->len_n_flags) &
  252. FH_RSCSR_FRAME_SIZE_MSK);
  253. change = ((priv->_agn.statistics_bt.general.common.temperature !=
  254. pkt->u.stats_bt.general.common.temperature) ||
  255. ((priv->_agn.statistics_bt.flag &
  256. STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  257. (pkt->u.stats_bt.flag &
  258. STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
  259. #ifdef CONFIG_IWLWIFI_DEBUGFS
  260. iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats_bt);
  261. #endif
  262. } else {
  263. IWL_DEBUG_RX(priv,
  264. "Statistics notification received (%d vs %d).\n",
  265. (int)sizeof(struct iwl_notif_statistics),
  266. le32_to_cpu(pkt->len_n_flags) &
  267. FH_RSCSR_FRAME_SIZE_MSK);
  268. change = ((priv->_agn.statistics.general.common.temperature !=
  269. pkt->u.stats.general.common.temperature) ||
  270. ((priv->_agn.statistics.flag &
  271. STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
  272. (pkt->u.stats.flag &
  273. STATISTICS_REPLY_FLG_HT40_MODE_MSK)));
  274. #ifdef CONFIG_IWLWIFI_DEBUGFS
  275. iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats);
  276. #endif
  277. }
  278. iwl_recover_from_statistics(priv, pkt);
  279. if (priv->cfg->bt_params &&
  280. priv->cfg->bt_params->bt_statistics)
  281. memcpy(&priv->_agn.statistics_bt, &pkt->u.stats_bt,
  282. sizeof(priv->_agn.statistics_bt));
  283. else
  284. memcpy(&priv->_agn.statistics, &pkt->u.stats,
  285. sizeof(priv->_agn.statistics));
  286. set_bit(STATUS_STATISTICS, &priv->status);
  287. /* Reschedule the statistics timer to occur in
  288. * REG_RECALIB_PERIOD seconds to ensure we get a
  289. * thermal update even if the uCode doesn't give
  290. * us one */
  291. mod_timer(&priv->statistics_periodic, jiffies +
  292. msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  293. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  294. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  295. iwl_rx_calc_noise(priv);
  296. queue_work(priv->workqueue, &priv->run_time_calib_work);
  297. }
  298. if (priv->cfg->ops->lib->temp_ops.temperature && change)
  299. priv->cfg->ops->lib->temp_ops.temperature(priv);
  300. }
  301. void iwl_reply_statistics(struct iwl_priv *priv,
  302. struct iwl_rx_mem_buffer *rxb)
  303. {
  304. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  305. if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
  306. #ifdef CONFIG_IWLWIFI_DEBUGFS
  307. memset(&priv->_agn.accum_statistics, 0,
  308. sizeof(struct iwl_notif_statistics));
  309. memset(&priv->_agn.delta_statistics, 0,
  310. sizeof(struct iwl_notif_statistics));
  311. memset(&priv->_agn.max_delta, 0,
  312. sizeof(struct iwl_notif_statistics));
  313. memset(&priv->_agn.accum_statistics_bt, 0,
  314. sizeof(struct iwl_bt_notif_statistics));
  315. memset(&priv->_agn.delta_statistics_bt, 0,
  316. sizeof(struct iwl_bt_notif_statistics));
  317. memset(&priv->_agn.max_delta_bt, 0,
  318. sizeof(struct iwl_bt_notif_statistics));
  319. #endif
  320. IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
  321. }
  322. iwl_rx_statistics(priv, rxb);
  323. }