31 #include <linux/slab.h>
32 #include <linux/sched.h>
34 #include <asm/unaligned.h>
40 #define IWL_CMD_ENTRY(x) [x] = #x
133 IWL_ERR(priv,
"Error Reply type 0x%08X cmd REPLY_ERROR (0x%02X) "
134 "seq 0x%04X ser 0x%08X\n",
164 IWL_ERR(priv,
"CSA notif (fail) : channel %d\n",
172 static int iwlagn_rx_spectrum_measure_notif(
struct iwl_priv *priv,
181 "Spectrum Measure Notification: Start\n");
190 static int iwlagn_rx_pm_sleep_notif(
struct iwl_priv *priv,
194 #ifdef CONFIG_IWLWIFI_DEBUG
203 static int iwlagn_rx_pm_debug_statistics_notif(
struct iwl_priv *priv,
211 "notification for PM_DEBUG_STATISTIC_NOTIFIC:\n", len);
216 static int iwlagn_rx_beacon_notif(
struct iwl_priv *priv,
222 #ifdef CONFIG_IWLWIFI_DEBUG
226 IWL_DEBUG_RX(priv,
"beacon status %#x, retries:%d ibssmgr:%d "
227 "tsf:0x%.8x%.8x rate:%d\n",
246 static bool iwlagn_good_plcp_health(
struct iwl_priv *priv,
268 if ((delta * 100 / msecs) > threshold) {
270 "plcp health threshold %u delta %d msecs %u\n",
271 threshold, delta, msecs);
285 if (!iwl_is_any_associated(priv)) {
317 static void iwlagn_recover_from_statistics(
struct iwl_priv *priv,
331 if (!iwl_is_any_associated(priv))
339 !iwlagn_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs))
346 static void iwlagn_rx_calc_noise(
struct iwl_priv *priv)
349 int num_active_rx = 0;
350 int total_silence = 0;
351 int bcn_silence_a, bcn_silence_b, bcn_silence_c;
364 total_silence += bcn_silence_a;
368 total_silence += bcn_silence_b;
372 total_silence += bcn_silence_c;
378 last_rx_noise = (total_silence / num_active_rx) - 107;
383 bcn_silence_a, bcn_silence_b, bcn_silence_c,
387 #ifdef CONFIG_IWLWIFI_DEBUGFS
399 i < size /
sizeof(
__le32);
400 i++, prev++, cur++, delta++, max_delta++, accum++) {
412 iwlagn_accumulative_statistics(
struct iwl_priv *priv,
421 #define ACCUM(_name) \
422 accum_stats((__le32 *)&priv->statistics._name, \
424 (__le32 *)&priv->delta_stats._name, \
425 (__le32 *)&priv->max_delta_stats._name, \
426 (__le32 *)&priv->accum_stats._name, \
441 iwlagn_accumulative_statistics(
struct iwl_priv *priv,
453 static int iwlagn_rx_statistics(
struct iwl_priv *priv,
458 const int reg_recalib_period = 60;
473 IWL_DEBUG_RX(priv,
"Statistics notification received (%d bytes).\n",
480 stats = (
void *)&pkt->
data;
482 common = &stats->
general.common;
483 rx_non_phy = &stats->
rx.general.common;
484 rx_ofdm = &stats->
rx.ofdm;
485 rx_ofdm_ht = &stats->
rx.ofdm_ht;
486 rx_cck = &stats->
rx.cck;
488 bt_activity = &stats->
general.activity;
490 #ifdef CONFIG_IWLWIFI_DEBUGFS
492 priv->
statistics.num_bt_kills = stats->
rx.general.num_bt_kills;
493 le32_add_cpu(&priv->
statistics.accum_num_bt_kills,
498 stats = (
void *)&pkt->
data;
500 common = &stats->
general.common;
501 rx_non_phy = &stats->
rx.general;
502 rx_ofdm = &stats->
rx.ofdm;
503 rx_ofdm_ht = &stats->
rx.ofdm_ht;
504 rx_cck = &stats->
rx.cck;
508 WARN_ONCE(1,
"len %d doesn't match BT (%zu) or normal (%zu)\n",
519 iwlagn_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm,
520 rx_ofdm_ht, rx_cck, tx, bt_activity);
522 iwlagn_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp);
531 #ifdef CONFIG_IWLWIFI_DEBUGFS
534 sizeof(*bt_activity));
550 iwlagn_rx_calc_noise(priv);
553 if (priv->
lib->temperature && change)
554 priv->
lib->temperature(priv);
561 static int iwlagn_rx_reply_statistics(
struct iwl_priv *priv,
569 #ifdef CONFIG_IWLWIFI_DEBUGFS
570 memset(&priv->accum_stats, 0,
571 sizeof(priv->accum_stats));
572 memset(&priv->delta_stats, 0,
573 sizeof(priv->delta_stats));
574 memset(&priv->max_delta_stats, 0,
575 sizeof(priv->max_delta_stats));
579 iwlagn_rx_statistics(priv, rxb, cmd);
585 static int iwlagn_rx_card_state_notif(
struct iwl_priv *priv,
598 "Reached" :
"Not reached");
600 if (
flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
621 if (
flags & HW_CARD_DISABLED)
627 if (!(
flags & RXON_CARD_DISABLED))
639 static int iwlagn_rx_missed_beacon_notif(
struct iwl_priv *priv,
650 "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
663 static int iwlagn_rx_reply_rx_phy(
struct iwl_priv *priv,
679 static int iwlagn_set_decrypted_flag(
struct iwl_priv *priv,
707 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
715 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
728 static void iwlagn_pass_packet_to_mac80211(
struct iwl_priv *priv,
738 unsigned int hdrlen, fraglen;
743 "Dropping packet while interface is not open.\n");
749 iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats))
757 IWL_ERR(priv,
"alloc_skb failed\n");
764 hdrlen = (len <= skb_tailroom(skb)) ? len :
sizeof(*hdr);
770 int offset = (
void *)hdr + hdrlen -
786 if (!ether_addr_equal(hdr->
addr3,
793 memcpy(IEEE80211_SKB_RXCB(skb), stats,
sizeof(*stats));
798 static u32 iwlagn_translate_rx_status(
struct iwl_priv *priv,
u32 decrypt_in)
803 RX_RES_STATUS_STATION_FOUND)
804 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
810 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
815 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
824 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
851 IWL_DEBUG_RX(priv,
"decrypt_in:0x%x decrypt_out = 0x%x\n",
852 decrypt_in, decrypt_out);
858 static int iwlagn_calc_rssi(
struct iwl_priv *priv,
866 u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
887 max_rssi =
max_t(
u32, rssi_a, rssi_b);
888 max_rssi =
max_t(
u32, max_rssi, rssi_c);
891 rssi_a, rssi_b, rssi_c, max_rssi, agc);
899 static int iwlagn_rx_reply_rx(
struct iwl_priv *priv,
914 IWL_ERR(priv,
"MPDU frame without cached PHY data\n");
921 rx_pkt_status = *(
__le32 *)(pkt->
data +
sizeof(*amsdu) + len);
922 ampdu_status = iwlagn_translate_rx_status(priv,
959 rx_status.signal = iwlagn_calc_rssi(priv, phy_res);
1005 iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status,
1010 static int iwlagn_rx_noa_notification(
struct iwl_priv *priv,
1026 len += 1 + 1 + 3 + 1;
1035 new_data->
data[1] = len - 2;
1070 iwlagn_rx_spectrum_measure_notif;
1073 iwlagn_rx_pm_debug_statistics_notif;
1091 iwlagn_rx_missed_beacon_notif;
1107 if (priv->
cfg->bt_params)
1125 #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
1147 IWL_DEBUG_RX(priv,
"No handler needed for %s, 0x%02x\n",
1148 iwl_dvm_get_cmd_string(pkt->
hdr.cmd),