iwlwifi: fix spelling errors
[linux-2.6-block.git] / drivers / net / wireless / iwlwifi / mvm / rx.c
index f922131b4eaba7a66ab8d2e14f749f5d8cb56206..6177e24f4c016d09c8496186d65c394d05bb5eb3 100644 (file)
@@ -6,7 +6,7 @@
  * GPL LICENSE SUMMARY
  *
  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
- * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
+ * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of version 2 of the GNU General Public License as
@@ -32,7 +32,7 @@
  * BSD LICENSE
  *
  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
- * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
+ * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -345,6 +345,25 @@ int iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
                struct iwl_mvm_sta *mvmsta;
                mvmsta = iwl_mvm_sta_from_mac80211(sta);
                rs_update_last_rssi(mvm, &mvmsta->lq_sta, rx_status);
+
+               if (iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_RSSI) &&
+                   ieee80211_is_beacon(hdr->frame_control)) {
+                       struct iwl_fw_dbg_trigger_tlv *trig;
+                       struct iwl_fw_dbg_trigger_low_rssi *rssi_trig;
+                       bool trig_check;
+                       s32 rssi;
+
+                       trig = iwl_fw_dbg_get_trigger(mvm->fw,
+                                                     FW_DBG_TRIGGER_RSSI);
+                       rssi_trig = (void *)trig->data;
+                       rssi = le32_to_cpu(rssi_trig->rssi);
+
+                       trig_check =
+                               iwl_fw_dbg_trigger_check_stop(mvm, mvmsta->vif,
+                                                             trig);
+                       if (trig_check && rx_status->signal < rssi)
+                               iwl_mvm_fw_dbg_collect_trig(mvm, trig, NULL, 0);
+               }
        }
 
        rcu_read_unlock();
@@ -416,35 +435,43 @@ int iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
 }
 
 static void iwl_mvm_update_rx_statistics(struct iwl_mvm *mvm,
-                                        struct iwl_notif_statistics *stats)
+                                        struct mvm_statistics_rx *rx_stats)
 {
-       /*
-        * NOTE FW aggregates the statistics - BUT the statistics are cleared
-        * when the driver issues REPLY_STATISTICS_CMD 0x9c with CLEAR_STATS
-        * bit set.
-        */
        lockdep_assert_held(&mvm->mutex);
-       memcpy(&mvm->rx_stats, &stats->rx, sizeof(struct mvm_statistics_rx));
+
+       mvm->rx_stats = *rx_stats;
 }
 
 struct iwl_mvm_stat_data {
-       struct iwl_notif_statistics *stats;
        struct iwl_mvm *mvm;
+       __le32 mac_id;
+       __s8 beacon_filter_average_energy;
+       struct mvm_statistics_general_v8 *general;
 };
 
 static void iwl_mvm_stat_iterator(void *_data, u8 *mac,
                                  struct ieee80211_vif *vif)
 {
        struct iwl_mvm_stat_data *data = _data;
-       struct iwl_notif_statistics *stats = data->stats;
        struct iwl_mvm *mvm = data->mvm;
-       int sig = -stats->general.beacon_filter_average_energy;
+       int sig = -data->beacon_filter_average_energy;
        int last_event;
        int thold = vif->bss_conf.cqm_rssi_thold;
        int hyst = vif->bss_conf.cqm_rssi_hyst;
-       u16 id = le32_to_cpu(stats->rx.general.mac_id);
+       u16 id = le32_to_cpu(data->mac_id);
        struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
 
+       /* This doesn't need the MAC ID check since it's not taking the
+        * data copied into the "data" struct, but rather the data from
+        * the notification directly.
+        */
+       if (data->general) {
+               mvmvif->beacon_stats.num_beacons =
+                       le32_to_cpu(data->general->beacon_counter[mvmvif->id]);
+               mvmvif->beacon_stats.avg_signal =
+                       -data->general->beacon_average_energy[mvmvif->id];
+       }
+
        if (mvmvif->id != id)
                return;
 
@@ -500,34 +527,101 @@ static void iwl_mvm_stat_iterator(void *_data, u8 *mac,
        }
 }
 
-/*
- * iwl_mvm_rx_statistics - STATISTICS_NOTIFICATION handler
- *
- * TODO: This handler is implemented partially.
- */
-int iwl_mvm_rx_statistics(struct iwl_mvm *mvm,
-                         struct iwl_rx_cmd_buffer *rxb,
-                         struct iwl_device_cmd *cmd)
+static inline void
+iwl_mvm_rx_stats_check_trigger(struct iwl_mvm *mvm, struct iwl_rx_packet *pkt)
 {
-       struct iwl_rx_packet *pkt = rxb_addr(rxb);
-       struct iwl_notif_statistics *stats = (void *)&pkt->data;
+       struct iwl_fw_dbg_trigger_tlv *trig;
+       struct iwl_fw_dbg_trigger_stats *trig_stats;
+       u32 trig_offset, trig_thold;
+
+       if (!iwl_fw_dbg_trigger_enabled(mvm->fw, FW_DBG_TRIGGER_STATS))
+               return;
+
+       trig = iwl_fw_dbg_get_trigger(mvm->fw, FW_DBG_TRIGGER_STATS);
+       trig_stats = (void *)trig->data;
+
+       if (!iwl_fw_dbg_trigger_check_stop(mvm, NULL, trig))
+               return;
+
+       trig_offset = le32_to_cpu(trig_stats->stop_offset);
+       trig_thold = le32_to_cpu(trig_stats->stop_threshold);
+
+       if (WARN_ON_ONCE(trig_offset >= iwl_rx_packet_payload_len(pkt)))
+               return;
+
+       if (le32_to_cpup((__le32 *) (pkt->data + trig_offset)) < trig_thold)
+               return;
+
+       iwl_mvm_fw_dbg_collect_trig(mvm, trig, NULL, 0);
+}
+
+void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
+                                 struct iwl_rx_packet *pkt)
+{
+       size_t v8_len = sizeof(struct iwl_notif_statistics_v8);
+       size_t v10_len = sizeof(struct iwl_notif_statistics_v10);
        struct iwl_mvm_stat_data data = {
-               .stats = stats,
                .mvm = mvm,
        };
+       u32 temperature;
+
+       if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_STATS_V10) {
+               struct iwl_notif_statistics_v10 *stats = (void *)&pkt->data;
+
+               if (iwl_rx_packet_payload_len(pkt) != v10_len)
+                       goto invalid;
+
+               temperature = le32_to_cpu(stats->general.radio_temperature);
+               data.mac_id = stats->rx.general.mac_id;
+               data.beacon_filter_average_energy =
+                       stats->general.beacon_filter_average_energy;
+
+               iwl_mvm_update_rx_statistics(mvm, &stats->rx);
+
+               mvm->radio_stats.rx_time = le64_to_cpu(stats->general.rx_time);
+               mvm->radio_stats.tx_time = le64_to_cpu(stats->general.tx_time);
+               mvm->radio_stats.on_time_rf =
+                       le64_to_cpu(stats->general.on_time_rf);
+               mvm->radio_stats.on_time_scan =
+                       le64_to_cpu(stats->general.on_time_scan);
+
+               data.general = &stats->general;
+       } else {
+               struct iwl_notif_statistics_v8 *stats = (void *)&pkt->data;
+
+               if (iwl_rx_packet_payload_len(pkt) != v8_len)
+                       goto invalid;
+
+               temperature = le32_to_cpu(stats->general.radio_temperature);
+               data.mac_id = stats->rx.general.mac_id;
+               data.beacon_filter_average_energy =
+                       stats->general.beacon_filter_average_energy;
+
+               iwl_mvm_update_rx_statistics(mvm, &stats->rx);
+       }
+
+       iwl_mvm_rx_stats_check_trigger(mvm, pkt);
 
        /* Only handle rx statistics temperature changes if async temp
         * notifications are not supported
         */
        if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_ASYNC_DTM))
-               iwl_mvm_tt_temp_changed(mvm,
-                               le32_to_cpu(stats->general.radio_temperature));
-
-       iwl_mvm_update_rx_statistics(mvm, stats);
+               iwl_mvm_tt_temp_changed(mvm, temperature);
 
        ieee80211_iterate_active_interfaces(mvm->hw,
                                            IEEE80211_IFACE_ITER_NORMAL,
                                            iwl_mvm_stat_iterator,
                                            &data);
+       return;
+ invalid:
+       IWL_ERR(mvm, "received invalid statistics size (%d)!\n",
+               iwl_rx_packet_payload_len(pkt));
+}
+
+int iwl_mvm_rx_statistics(struct iwl_mvm *mvm,
+                         struct iwl_rx_cmd_buffer *rxb,
+                         struct iwl_device_cmd *cmd)
+{
+       iwl_mvm_handle_rx_statistics(mvm, rxb_addr(rxb));
        return 0;
 }