iwlwifi: mvm: program DTIM timings properly
authorJohannes Berg <johannes.berg@intel.com>
Tue, 5 Feb 2013 17:10:04 +0000 (18:10 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Mon, 18 Feb 2013 19:17:38 +0000 (20:17 +0100)
For the firmware to know when DTIM beacons arrive
we have to program the DTIM time in TSF and system
time in the MAC context. Since mac80211 now tracks
the different times (on demand), this becomes easy.

Reviewed-by: Emmanuel Grumbach <emmanuel.grumbach@intel.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
drivers/net/wireless/iwlwifi/mvm/mac-ctxt.c
drivers/net/wireless/iwlwifi/mvm/mac80211.c
drivers/net/wireless/iwlwifi/mvm/rx.c

index 0854dc3388816d3ce0ed9a7aa7aec9dd63f6a818..c33bec83b8070b6a85cbe868fcee9f1fb2be9ec0 100644 (file)
@@ -585,10 +585,43 @@ static void iwl_mvm_mac_ctxt_cmd_fill_sta(struct iwl_mvm *mvm,
                                          struct iwl_mac_data_sta *ctxt_sta)
 {
        /* We need the dtim_period to set the MAC as associated */
-       if (vif->bss_conf.assoc && vif->bss_conf.dtim_period)
+       if (vif->bss_conf.assoc && vif->bss_conf.dtim_period) {
+               u32 dtim_offs;
+
+               /*
+                * The DTIM count counts down, so when it is N that means N
+                * more beacon intervals happen until the DTIM TBTT. Therefore
+                * add this to the current time. If that ends up being in the
+                * future, the firmware will handle it.
+                *
+                * Also note that the system_timestamp (which we get here as
+                * "sync_device_ts") and TSF timestamp aren't at exactly the
+                * same offset in the frame -- the TSF is at the first symbol
+                * of the TSF, the system timestamp is at signal acquisition
+                * time. This means there's an offset between them of at most
+                * a few hundred microseconds (24 * 8 bits + PLCP time gives
+                * 384us in the longest case), this is currently not relevant
+                * as the firmware wakes up around 2ms before the TBTT.
+                */
+               dtim_offs = vif->bss_conf.sync_dtim_count *
+                               vif->bss_conf.beacon_int;
+               /* convert TU to usecs */
+               dtim_offs *= 1024;
+
+               ctxt_sta->dtim_tsf =
+                       cpu_to_le64(vif->bss_conf.sync_tsf + dtim_offs);
+               ctxt_sta->dtim_time =
+                       cpu_to_le32(vif->bss_conf.sync_device_ts + dtim_offs);
+
+               IWL_DEBUG_INFO(mvm, "DTIM TBTT is 0x%llx/0x%x, offset %d\n",
+                              le64_to_cpu(ctxt_sta->dtim_tsf),
+                              le32_to_cpu(ctxt_sta->dtim_time),
+                              dtim_offs);
+
                ctxt_sta->is_assoc = cpu_to_le32(1);
-       else
+       } else {
                ctxt_sta->is_assoc = cpu_to_le32(0);
+       }
 
        ctxt_sta->bi = cpu_to_le32(vif->bss_conf.beacon_int);
        ctxt_sta->bi_reciprocal =
index 6fb084f2c257ad4a3c60d27e5a26f473639148cd..76794940e1f081f900442598077c7b042dd36336 100644 (file)
@@ -115,7 +115,8 @@ int iwl_mvm_mac_setup_register(struct iwl_mvm *mvm)
                    IEEE80211_HW_WANT_MONITOR_VIF |
                    IEEE80211_HW_SUPPORTS_PS |
                    IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
-                   IEEE80211_HW_AMPDU_AGGREGATION;
+                   IEEE80211_HW_AMPDU_AGGREGATION |
+                   IEEE80211_HW_TIMING_BEACON_ONLY;
 
        hw->queues = IWL_FIRST_AMPDU_QUEUE;
        hw->offchannel_tx_hw_queue = IWL_OFFCHANNEL_QUEUE;
index 3f3ce91ad5c27671eb639dbf0941abaea6a6223b..3f40ab05bbd8181d55d4e1999ebc77f5f977b6f9 100644 (file)
@@ -267,6 +267,7 @@ int iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
 
        /* rx_status carries information about the packet to mac80211 */
        rx_status.mactime = le64_to_cpu(phy_info->timestamp);
+       rx_status.device_timestamp = le32_to_cpu(phy_info->system_timestamp);
        rx_status.band =
                (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ?
                                IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;