diff options
author | John W. Linville <linville@tuxdriver.com> | 2011-10-11 15:35:42 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2011-10-11 15:35:42 -0400 |
commit | 094daf7db7c47861009899ce23f9177d761e20b0 (patch) | |
tree | a107065393720b80664157a035b206576e834793 /net/mac80211/sta_info.c | |
parent | 3ed6f6958c0ac21958285d8648f14d34da4bbcb3 (diff) | |
parent | 5f68a2b0a890d086e40fc7b55f4a0c32c28bc0d2 (diff) |
Merge branch 'master' of git://git.infradead.org/users/linville/wireless-next into for-davem
Conflicts:
Documentation/feature-removal-schedule.txt
Diffstat (limited to 'net/mac80211/sta_info.c')
-rw-r--r-- | net/mac80211/sta_info.c | 636 |
1 files changed, 515 insertions, 121 deletions
diff --git a/net/mac80211/sta_info.c b/net/mac80211/sta_info.c index 0a7e0fed3251..58b1c2bb26d2 100644 --- a/net/mac80211/sta_info.c +++ b/net/mac80211/sta_info.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include "sta_info.h" | 24 | #include "sta_info.h" |
25 | #include "debugfs_sta.h" | 25 | #include "debugfs_sta.h" |
26 | #include "mesh.h" | 26 | #include "mesh.h" |
27 | #include "wme.h" | ||
27 | 28 | ||
28 | /** | 29 | /** |
29 | * DOC: STA information lifetime rules | 30 | * DOC: STA information lifetime rules |
@@ -243,13 +244,22 @@ static void sta_unblock(struct work_struct *wk) | |||
243 | if (sta->dead) | 244 | if (sta->dead) |
244 | return; | 245 | return; |
245 | 246 | ||
246 | if (!test_sta_flags(sta, WLAN_STA_PS_STA)) | 247 | if (!test_sta_flag(sta, WLAN_STA_PS_STA)) |
247 | ieee80211_sta_ps_deliver_wakeup(sta); | 248 | ieee80211_sta_ps_deliver_wakeup(sta); |
248 | else if (test_and_clear_sta_flags(sta, WLAN_STA_PSPOLL)) { | 249 | else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL)) { |
249 | clear_sta_flags(sta, WLAN_STA_PS_DRIVER); | 250 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
251 | |||
252 | local_bh_disable(); | ||
250 | ieee80211_sta_ps_deliver_poll_response(sta); | 253 | ieee80211_sta_ps_deliver_poll_response(sta); |
254 | local_bh_enable(); | ||
255 | } else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD)) { | ||
256 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); | ||
257 | |||
258 | local_bh_disable(); | ||
259 | ieee80211_sta_ps_deliver_uapsd(sta); | ||
260 | local_bh_enable(); | ||
251 | } else | 261 | } else |
252 | clear_sta_flags(sta, WLAN_STA_PS_DRIVER); | 262 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
253 | } | 263 | } |
254 | 264 | ||
255 | static int sta_prepare_rate_control(struct ieee80211_local *local, | 265 | static int sta_prepare_rate_control(struct ieee80211_local *local, |
@@ -282,7 +292,6 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, | |||
282 | return NULL; | 292 | return NULL; |
283 | 293 | ||
284 | spin_lock_init(&sta->lock); | 294 | spin_lock_init(&sta->lock); |
285 | spin_lock_init(&sta->flaglock); | ||
286 | INIT_WORK(&sta->drv_unblock_wk, sta_unblock); | 295 | INIT_WORK(&sta->drv_unblock_wk, sta_unblock); |
287 | INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work); | 296 | INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work); |
288 | mutex_init(&sta->ampdu_mlme.mtx); | 297 | mutex_init(&sta->ampdu_mlme.mtx); |
@@ -309,8 +318,10 @@ struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata, | |||
309 | */ | 318 | */ |
310 | sta->timer_to_tid[i] = i; | 319 | sta->timer_to_tid[i] = i; |
311 | } | 320 | } |
312 | skb_queue_head_init(&sta->ps_tx_buf); | 321 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
313 | skb_queue_head_init(&sta->tx_filtered); | 322 | skb_queue_head_init(&sta->ps_tx_buf[i]); |
323 | skb_queue_head_init(&sta->tx_filtered[i]); | ||
324 | } | ||
314 | 325 | ||
315 | for (i = 0; i < NUM_RX_DATA_QUEUES; i++) | 326 | for (i = 0; i < NUM_RX_DATA_QUEUES; i++) |
316 | sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX); | 327 | sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX); |
@@ -641,54 +652,84 @@ static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid) | |||
641 | bss->tim[aid / 8] &= ~(1 << (aid % 8)); | 652 | bss->tim[aid / 8] &= ~(1 << (aid % 8)); |
642 | } | 653 | } |
643 | 654 | ||
644 | static void __sta_info_set_tim_bit(struct ieee80211_if_ap *bss, | 655 | static unsigned long ieee80211_tids_for_ac(int ac) |
645 | struct sta_info *sta) | ||
646 | { | 656 | { |
647 | BUG_ON(!bss); | 657 | /* If we ever support TIDs > 7, this obviously needs to be adjusted */ |
648 | 658 | switch (ac) { | |
649 | __bss_tim_set(bss, sta->sta.aid); | 659 | case IEEE80211_AC_VO: |
650 | 660 | return BIT(6) | BIT(7); | |
651 | if (sta->local->ops->set_tim) { | 661 | case IEEE80211_AC_VI: |
652 | sta->local->tim_in_locked_section = true; | 662 | return BIT(4) | BIT(5); |
653 | drv_set_tim(sta->local, &sta->sta, true); | 663 | case IEEE80211_AC_BE: |
654 | sta->local->tim_in_locked_section = false; | 664 | return BIT(0) | BIT(3); |
665 | case IEEE80211_AC_BK: | ||
666 | return BIT(1) | BIT(2); | ||
667 | default: | ||
668 | WARN_ON(1); | ||
669 | return 0; | ||
655 | } | 670 | } |
656 | } | 671 | } |
657 | 672 | ||
658 | void sta_info_set_tim_bit(struct sta_info *sta) | 673 | void sta_info_recalc_tim(struct sta_info *sta) |
659 | { | 674 | { |
675 | struct ieee80211_local *local = sta->local; | ||
676 | struct ieee80211_if_ap *bss = sta->sdata->bss; | ||
660 | unsigned long flags; | 677 | unsigned long flags; |
678 | bool indicate_tim = false; | ||
679 | u8 ignore_for_tim = sta->sta.uapsd_queues; | ||
680 | int ac; | ||
661 | 681 | ||
662 | BUG_ON(!sta->sdata->bss); | 682 | if (WARN_ON_ONCE(!sta->sdata->bss)) |
683 | return; | ||
663 | 684 | ||
664 | spin_lock_irqsave(&sta->local->sta_lock, flags); | 685 | /* No need to do anything if the driver does all */ |
665 | __sta_info_set_tim_bit(sta->sdata->bss, sta); | 686 | if (local->hw.flags & IEEE80211_HW_AP_LINK_PS) |
666 | spin_unlock_irqrestore(&sta->local->sta_lock, flags); | 687 | return; |
667 | } | ||
668 | 688 | ||
669 | static void __sta_info_clear_tim_bit(struct ieee80211_if_ap *bss, | 689 | if (sta->dead) |
670 | struct sta_info *sta) | 690 | goto done; |
671 | { | 691 | |
672 | BUG_ON(!bss); | 692 | /* |
693 | * If all ACs are delivery-enabled then we should build | ||
694 | * the TIM bit for all ACs anyway; if only some are then | ||
695 | * we ignore those and build the TIM bit using only the | ||
696 | * non-enabled ones. | ||
697 | */ | ||
698 | if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1) | ||
699 | ignore_for_tim = 0; | ||
700 | |||
701 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { | ||
702 | unsigned long tids; | ||
673 | 703 | ||
674 | __bss_tim_clear(bss, sta->sta.aid); | 704 | if (ignore_for_tim & BIT(ac)) |
705 | continue; | ||
706 | |||
707 | indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) || | ||
708 | !skb_queue_empty(&sta->ps_tx_buf[ac]); | ||
709 | if (indicate_tim) | ||
710 | break; | ||
675 | 711 | ||
676 | if (sta->local->ops->set_tim) { | 712 | tids = ieee80211_tids_for_ac(ac); |
677 | sta->local->tim_in_locked_section = true; | 713 | |
678 | drv_set_tim(sta->local, &sta->sta, false); | 714 | indicate_tim |= |
679 | sta->local->tim_in_locked_section = false; | 715 | sta->driver_buffered_tids & tids; |
680 | } | 716 | } |
681 | } | ||
682 | 717 | ||
683 | void sta_info_clear_tim_bit(struct sta_info *sta) | 718 | done: |
684 | { | 719 | spin_lock_irqsave(&local->sta_lock, flags); |
685 | unsigned long flags; | ||
686 | 720 | ||
687 | BUG_ON(!sta->sdata->bss); | 721 | if (indicate_tim) |
722 | __bss_tim_set(bss, sta->sta.aid); | ||
723 | else | ||
724 | __bss_tim_clear(bss, sta->sta.aid); | ||
725 | |||
726 | if (local->ops->set_tim) { | ||
727 | local->tim_in_locked_section = true; | ||
728 | drv_set_tim(local, &sta->sta, indicate_tim); | ||
729 | local->tim_in_locked_section = false; | ||
730 | } | ||
688 | 731 | ||
689 | spin_lock_irqsave(&sta->local->sta_lock, flags); | 732 | spin_unlock_irqrestore(&local->sta_lock, flags); |
690 | __sta_info_clear_tim_bit(sta->sdata->bss, sta); | ||
691 | spin_unlock_irqrestore(&sta->local->sta_lock, flags); | ||
692 | } | 733 | } |
693 | 734 | ||
694 | static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb) | 735 | static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb) |
@@ -711,21 +752,59 @@ static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb) | |||
711 | } | 752 | } |
712 | 753 | ||
713 | 754 | ||
714 | static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local, | 755 | static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local, |
715 | struct sta_info *sta) | 756 | struct sta_info *sta, int ac) |
716 | { | 757 | { |
717 | unsigned long flags; | 758 | unsigned long flags; |
718 | struct sk_buff *skb; | 759 | struct sk_buff *skb; |
719 | 760 | ||
761 | /* | ||
762 | * First check for frames that should expire on the filtered | ||
763 | * queue. Frames here were rejected by the driver and are on | ||
764 | * a separate queue to avoid reordering with normal PS-buffered | ||
765 | * frames. They also aren't accounted for right now in the | ||
766 | * total_ps_buffered counter. | ||
767 | */ | ||
768 | for (;;) { | ||
769 | spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags); | ||
770 | skb = skb_peek(&sta->tx_filtered[ac]); | ||
771 | if (sta_info_buffer_expired(sta, skb)) | ||
772 | skb = __skb_dequeue(&sta->tx_filtered[ac]); | ||
773 | else | ||
774 | skb = NULL; | ||
775 | spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags); | ||
776 | |||
777 | /* | ||
778 | * Frames are queued in order, so if this one | ||
779 | * hasn't expired yet we can stop testing. If | ||
780 | * we actually reached the end of the queue we | ||
781 | * also need to stop, of course. | ||
782 | */ | ||
783 | if (!skb) | ||
784 | break; | ||
785 | dev_kfree_skb(skb); | ||
786 | } | ||
787 | |||
788 | /* | ||
789 | * Now also check the normal PS-buffered queue, this will | ||
790 | * only find something if the filtered queue was emptied | ||
791 | * since the filtered frames are all before the normal PS | ||
792 | * buffered frames. | ||
793 | */ | ||
720 | for (;;) { | 794 | for (;;) { |
721 | spin_lock_irqsave(&sta->ps_tx_buf.lock, flags); | 795 | spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags); |
722 | skb = skb_peek(&sta->ps_tx_buf); | 796 | skb = skb_peek(&sta->ps_tx_buf[ac]); |
723 | if (sta_info_buffer_expired(sta, skb)) | 797 | if (sta_info_buffer_expired(sta, skb)) |
724 | skb = __skb_dequeue(&sta->ps_tx_buf); | 798 | skb = __skb_dequeue(&sta->ps_tx_buf[ac]); |
725 | else | 799 | else |
726 | skb = NULL; | 800 | skb = NULL; |
727 | spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags); | 801 | spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags); |
728 | 802 | ||
803 | /* | ||
804 | * frames are queued in order, so if this one | ||
805 | * hasn't expired yet (or we reached the end of | ||
806 | * the queue) we can stop testing | ||
807 | */ | ||
729 | if (!skb) | 808 | if (!skb) |
730 | break; | 809 | break; |
731 | 810 | ||
@@ -735,22 +814,47 @@ static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local, | |||
735 | sta->sta.addr); | 814 | sta->sta.addr); |
736 | #endif | 815 | #endif |
737 | dev_kfree_skb(skb); | 816 | dev_kfree_skb(skb); |
738 | |||
739 | if (skb_queue_empty(&sta->ps_tx_buf) && | ||
740 | !test_sta_flags(sta, WLAN_STA_PS_DRIVER_BUF)) | ||
741 | sta_info_clear_tim_bit(sta); | ||
742 | } | 817 | } |
743 | 818 | ||
744 | return !skb_queue_empty(&sta->ps_tx_buf); | 819 | /* |
820 | * Finally, recalculate the TIM bit for this station -- it might | ||
821 | * now be clear because the station was too slow to retrieve its | ||
822 | * frames. | ||
823 | */ | ||
824 | sta_info_recalc_tim(sta); | ||
825 | |||
826 | /* | ||
827 | * Return whether there are any frames still buffered, this is | ||
828 | * used to check whether the cleanup timer still needs to run, | ||
829 | * if there are no frames we don't need to rearm the timer. | ||
830 | */ | ||
831 | return !(skb_queue_empty(&sta->ps_tx_buf[ac]) && | ||
832 | skb_queue_empty(&sta->tx_filtered[ac])); | ||
833 | } | ||
834 | |||
835 | static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local, | ||
836 | struct sta_info *sta) | ||
837 | { | ||
838 | bool have_buffered = false; | ||
839 | int ac; | ||
840 | |||
841 | /* This is only necessary for stations on BSS interfaces */ | ||
842 | if (!sta->sdata->bss) | ||
843 | return false; | ||
844 | |||
845 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) | ||
846 | have_buffered |= | ||
847 | sta_info_cleanup_expire_buffered_ac(local, sta, ac); | ||
848 | |||
849 | return have_buffered; | ||
745 | } | 850 | } |
746 | 851 | ||
747 | static int __must_check __sta_info_destroy(struct sta_info *sta) | 852 | static int __must_check __sta_info_destroy(struct sta_info *sta) |
748 | { | 853 | { |
749 | struct ieee80211_local *local; | 854 | struct ieee80211_local *local; |
750 | struct ieee80211_sub_if_data *sdata; | 855 | struct ieee80211_sub_if_data *sdata; |
751 | struct sk_buff *skb; | ||
752 | unsigned long flags; | 856 | unsigned long flags; |
753 | int ret, i; | 857 | int ret, i, ac; |
754 | 858 | ||
755 | might_sleep(); | 859 | might_sleep(); |
756 | 860 | ||
@@ -766,7 +870,7 @@ static int __must_check __sta_info_destroy(struct sta_info *sta) | |||
766 | * sessions -- block that to make sure the tear-down | 870 | * sessions -- block that to make sure the tear-down |
767 | * will be sufficient. | 871 | * will be sufficient. |
768 | */ | 872 | */ |
769 | set_sta_flags(sta, WLAN_STA_BLOCK_BA); | 873 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
770 | ieee80211_sta_tear_down_BA_sessions(sta, true); | 874 | ieee80211_sta_tear_down_BA_sessions(sta, true); |
771 | 875 | ||
772 | spin_lock_irqsave(&local->sta_lock, flags); | 876 | spin_lock_irqsave(&local->sta_lock, flags); |
@@ -787,12 +891,15 @@ static int __must_check __sta_info_destroy(struct sta_info *sta) | |||
787 | 891 | ||
788 | sta->dead = true; | 892 | sta->dead = true; |
789 | 893 | ||
790 | if (test_and_clear_sta_flags(sta, | 894 | if (test_sta_flag(sta, WLAN_STA_PS_STA) || |
791 | WLAN_STA_PS_STA | WLAN_STA_PS_DRIVER)) { | 895 | test_sta_flag(sta, WLAN_STA_PS_DRIVER)) { |
792 | BUG_ON(!sdata->bss); | 896 | BUG_ON(!sdata->bss); |
793 | 897 | ||
898 | clear_sta_flag(sta, WLAN_STA_PS_STA); | ||
899 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); | ||
900 | |||
794 | atomic_dec(&sdata->bss->num_sta_ps); | 901 | atomic_dec(&sdata->bss->num_sta_ps); |
795 | sta_info_clear_tim_bit(sta); | 902 | sta_info_recalc_tim(sta); |
796 | } | 903 | } |
797 | 904 | ||
798 | local->num_sta--; | 905 | local->num_sta--; |
@@ -818,6 +925,12 @@ static int __must_check __sta_info_destroy(struct sta_info *sta) | |||
818 | */ | 925 | */ |
819 | synchronize_rcu(); | 926 | synchronize_rcu(); |
820 | 927 | ||
928 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { | ||
929 | local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]); | ||
930 | __skb_queue_purge(&sta->ps_tx_buf[ac]); | ||
931 | __skb_queue_purge(&sta->tx_filtered[ac]); | ||
932 | } | ||
933 | |||
821 | #ifdef CONFIG_MAC80211_MESH | 934 | #ifdef CONFIG_MAC80211_MESH |
822 | if (ieee80211_vif_is_mesh(&sdata->vif)) | 935 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
823 | mesh_accept_plinks_update(sdata); | 936 | mesh_accept_plinks_update(sdata); |
@@ -840,14 +953,6 @@ static int __must_check __sta_info_destroy(struct sta_info *sta) | |||
840 | } | 953 | } |
841 | #endif | 954 | #endif |
842 | 955 | ||
843 | while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) { | ||
844 | local->total_ps_buffered--; | ||
845 | dev_kfree_skb_any(skb); | ||
846 | } | ||
847 | |||
848 | while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) | ||
849 | dev_kfree_skb_any(skb); | ||
850 | |||
851 | __sta_info_free(local, sta); | 956 | __sta_info_free(local, sta); |
852 | 957 | ||
853 | return 0; | 958 | return 0; |
@@ -1013,7 +1118,8 @@ static void clear_sta_ps_flags(void *_sta) | |||
1013 | { | 1118 | { |
1014 | struct sta_info *sta = _sta; | 1119 | struct sta_info *sta = _sta; |
1015 | 1120 | ||
1016 | clear_sta_flags(sta, WLAN_STA_PS_DRIVER | WLAN_STA_PS_STA); | 1121 | clear_sta_flag(sta, WLAN_STA_PS_DRIVER); |
1122 | clear_sta_flag(sta, WLAN_STA_PS_STA); | ||
1017 | } | 1123 | } |
1018 | 1124 | ||
1019 | /* powersave support code */ | 1125 | /* powersave support code */ |
@@ -1021,88 +1127,343 @@ void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta) | |||
1021 | { | 1127 | { |
1022 | struct ieee80211_sub_if_data *sdata = sta->sdata; | 1128 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
1023 | struct ieee80211_local *local = sdata->local; | 1129 | struct ieee80211_local *local = sdata->local; |
1024 | int sent, buffered; | 1130 | struct sk_buff_head pending; |
1131 | int filtered = 0, buffered = 0, ac; | ||
1132 | |||
1133 | clear_sta_flag(sta, WLAN_STA_SP); | ||
1134 | |||
1135 | BUILD_BUG_ON(BITS_TO_LONGS(STA_TID_NUM) > 1); | ||
1136 | sta->driver_buffered_tids = 0; | ||
1025 | 1137 | ||
1026 | clear_sta_flags(sta, WLAN_STA_PS_DRIVER_BUF); | ||
1027 | if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS)) | 1138 | if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS)) |
1028 | drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta); | 1139 | drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta); |
1029 | 1140 | ||
1030 | if (!skb_queue_empty(&sta->ps_tx_buf)) | 1141 | skb_queue_head_init(&pending); |
1031 | sta_info_clear_tim_bit(sta); | ||
1032 | 1142 | ||
1033 | /* Send all buffered frames to the station */ | 1143 | /* Send all buffered frames to the station */ |
1034 | sent = ieee80211_add_pending_skbs(local, &sta->tx_filtered); | 1144 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
1035 | buffered = ieee80211_add_pending_skbs_fn(local, &sta->ps_tx_buf, | 1145 | int count = skb_queue_len(&pending), tmp; |
1036 | clear_sta_ps_flags, sta); | 1146 | |
1037 | sent += buffered; | 1147 | skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending); |
1148 | tmp = skb_queue_len(&pending); | ||
1149 | filtered += tmp - count; | ||
1150 | count = tmp; | ||
1151 | |||
1152 | skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending); | ||
1153 | tmp = skb_queue_len(&pending); | ||
1154 | buffered += tmp - count; | ||
1155 | } | ||
1156 | |||
1157 | ieee80211_add_pending_skbs_fn(local, &pending, clear_sta_ps_flags, sta); | ||
1158 | |||
1038 | local->total_ps_buffered -= buffered; | 1159 | local->total_ps_buffered -= buffered; |
1039 | 1160 | ||
1161 | sta_info_recalc_tim(sta); | ||
1162 | |||
1040 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | 1163 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
1041 | printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames " | 1164 | printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames " |
1042 | "since STA not sleeping anymore\n", sdata->name, | 1165 | "since STA not sleeping anymore\n", sdata->name, |
1043 | sta->sta.addr, sta->sta.aid, sent - buffered, buffered); | 1166 | sta->sta.addr, sta->sta.aid, filtered, buffered); |
1044 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | 1167 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ |
1045 | } | 1168 | } |
1046 | 1169 | ||
1047 | void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta) | 1170 | static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata, |
1171 | struct sta_info *sta, int tid, | ||
1172 | enum ieee80211_frame_release_type reason) | ||
1048 | { | 1173 | { |
1049 | struct ieee80211_sub_if_data *sdata = sta->sdata; | ||
1050 | struct ieee80211_local *local = sdata->local; | 1174 | struct ieee80211_local *local = sdata->local; |
1175 | struct ieee80211_qos_hdr *nullfunc; | ||
1051 | struct sk_buff *skb; | 1176 | struct sk_buff *skb; |
1052 | int no_pending_pkts; | 1177 | int size = sizeof(*nullfunc); |
1178 | __le16 fc; | ||
1179 | bool qos = test_sta_flag(sta, WLAN_STA_WME); | ||
1180 | struct ieee80211_tx_info *info; | ||
1053 | 1181 | ||
1054 | skb = skb_dequeue(&sta->tx_filtered); | 1182 | if (qos) { |
1055 | if (!skb) { | 1183 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | |
1056 | skb = skb_dequeue(&sta->ps_tx_buf); | 1184 | IEEE80211_STYPE_QOS_NULLFUNC | |
1057 | if (skb) | 1185 | IEEE80211_FCTL_FROMDS); |
1058 | local->total_ps_buffered--; | 1186 | } else { |
1187 | size -= 2; | ||
1188 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | | ||
1189 | IEEE80211_STYPE_NULLFUNC | | ||
1190 | IEEE80211_FCTL_FROMDS); | ||
1059 | } | 1191 | } |
1060 | no_pending_pkts = skb_queue_empty(&sta->tx_filtered) && | ||
1061 | skb_queue_empty(&sta->ps_tx_buf); | ||
1062 | 1192 | ||
1063 | if (skb) { | 1193 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); |
1064 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | 1194 | if (!skb) |
1065 | struct ieee80211_hdr *hdr = | 1195 | return; |
1066 | (struct ieee80211_hdr *) skb->data; | 1196 | |
1197 | skb_reserve(skb, local->hw.extra_tx_headroom); | ||
1198 | |||
1199 | nullfunc = (void *) skb_put(skb, size); | ||
1200 | nullfunc->frame_control = fc; | ||
1201 | nullfunc->duration_id = 0; | ||
1202 | memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); | ||
1203 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); | ||
1204 | memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); | ||
1205 | |||
1206 | if (qos) { | ||
1207 | skb->priority = tid; | ||
1208 | |||
1209 | skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]); | ||
1210 | |||
1211 | nullfunc->qos_ctrl = cpu_to_le16(tid); | ||
1212 | |||
1213 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) | ||
1214 | nullfunc->qos_ctrl |= | ||
1215 | cpu_to_le16(IEEE80211_QOS_CTL_EOSP); | ||
1216 | } | ||
1217 | |||
1218 | info = IEEE80211_SKB_CB(skb); | ||
1219 | |||
1220 | /* | ||
1221 | * Tell TX path to send this frame even though the | ||
1222 | * STA may still remain is PS mode after this frame | ||
1223 | * exchange. Also set EOSP to indicate this packet | ||
1224 | * ends the poll/service period. | ||
1225 | */ | ||
1226 | info->flags |= IEEE80211_TX_CTL_POLL_RESPONSE | | ||
1227 | IEEE80211_TX_STATUS_EOSP | | ||
1228 | IEEE80211_TX_CTL_REQ_TX_STATUS; | ||
1229 | |||
1230 | drv_allow_buffered_frames(local, sta, BIT(tid), 1, reason, false); | ||
1231 | |||
1232 | ieee80211_xmit(sdata, skb); | ||
1233 | } | ||
1234 | |||
1235 | static void | ||
1236 | ieee80211_sta_ps_deliver_response(struct sta_info *sta, | ||
1237 | int n_frames, u8 ignored_acs, | ||
1238 | enum ieee80211_frame_release_type reason) | ||
1239 | { | ||
1240 | struct ieee80211_sub_if_data *sdata = sta->sdata; | ||
1241 | struct ieee80211_local *local = sdata->local; | ||
1242 | bool found = false; | ||
1243 | bool more_data = false; | ||
1244 | int ac; | ||
1245 | unsigned long driver_release_tids = 0; | ||
1246 | struct sk_buff_head frames; | ||
1247 | |||
1248 | /* Service or PS-Poll period starts */ | ||
1249 | set_sta_flag(sta, WLAN_STA_SP); | ||
1250 | |||
1251 | __skb_queue_head_init(&frames); | ||
1252 | |||
1253 | /* | ||
1254 | * Get response frame(s) and more data bit for it. | ||
1255 | */ | ||
1256 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { | ||
1257 | unsigned long tids; | ||
1258 | |||
1259 | if (ignored_acs & BIT(ac)) | ||
1260 | continue; | ||
1261 | |||
1262 | tids = ieee80211_tids_for_ac(ac); | ||
1263 | |||
1264 | if (!found) { | ||
1265 | driver_release_tids = sta->driver_buffered_tids & tids; | ||
1266 | if (driver_release_tids) { | ||
1267 | found = true; | ||
1268 | } else { | ||
1269 | struct sk_buff *skb; | ||
1270 | |||
1271 | while (n_frames > 0) { | ||
1272 | skb = skb_dequeue(&sta->tx_filtered[ac]); | ||
1273 | if (!skb) { | ||
1274 | skb = skb_dequeue( | ||
1275 | &sta->ps_tx_buf[ac]); | ||
1276 | if (skb) | ||
1277 | local->total_ps_buffered--; | ||
1278 | } | ||
1279 | if (!skb) | ||
1280 | break; | ||
1281 | n_frames--; | ||
1282 | found = true; | ||
1283 | __skb_queue_tail(&frames, skb); | ||
1284 | } | ||
1285 | } | ||
1286 | |||
1287 | /* | ||
1288 | * If the driver has data on more than one TID then | ||
1289 | * certainly there's more data if we release just a | ||
1290 | * single frame now (from a single TID). | ||
1291 | */ | ||
1292 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL && | ||
1293 | hweight16(driver_release_tids) > 1) { | ||
1294 | more_data = true; | ||
1295 | driver_release_tids = | ||
1296 | BIT(ffs(driver_release_tids) - 1); | ||
1297 | break; | ||
1298 | } | ||
1299 | } | ||
1300 | |||
1301 | if (!skb_queue_empty(&sta->tx_filtered[ac]) || | ||
1302 | !skb_queue_empty(&sta->ps_tx_buf[ac])) { | ||
1303 | more_data = true; | ||
1304 | break; | ||
1305 | } | ||
1306 | } | ||
1307 | |||
1308 | if (!found) { | ||
1309 | int tid; | ||
1067 | 1310 | ||
1068 | /* | 1311 | /* |
1069 | * Tell TX path to send this frame even though the STA may | 1312 | * For PS-Poll, this can only happen due to a race condition |
1070 | * still remain is PS mode after this frame exchange. | 1313 | * when we set the TIM bit and the station notices it, but |
1314 | * before it can poll for the frame we expire it. | ||
1315 | * | ||
1316 | * For uAPSD, this is said in the standard (11.2.1.5 h): | ||
1317 | * At each unscheduled SP for a non-AP STA, the AP shall | ||
1318 | * attempt to transmit at least one MSDU or MMPDU, but no | ||
1319 | * more than the value specified in the Max SP Length field | ||
1320 | * in the QoS Capability element from delivery-enabled ACs, | ||
1321 | * that are destined for the non-AP STA. | ||
1322 | * | ||
1323 | * Since we have no other MSDU/MMPDU, transmit a QoS null frame. | ||
1071 | */ | 1324 | */ |
1072 | info->flags |= IEEE80211_TX_CTL_PSPOLL_RESPONSE; | ||
1073 | 1325 | ||
1074 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | 1326 | /* This will evaluate to 1, 3, 5 or 7. */ |
1075 | printk(KERN_DEBUG "STA %pM aid %d: PS Poll (entries after %d)\n", | 1327 | tid = 7 - ((ffs(~ignored_acs) - 1) << 1); |
1076 | sta->sta.addr, sta->sta.aid, | ||
1077 | skb_queue_len(&sta->ps_tx_buf)); | ||
1078 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | ||
1079 | 1328 | ||
1080 | /* Use MoreData flag to indicate whether there are more | 1329 | ieee80211_send_null_response(sdata, sta, tid, reason); |
1081 | * buffered frames for this STA */ | 1330 | return; |
1082 | if (no_pending_pkts) | 1331 | } |
1083 | hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA); | ||
1084 | else | ||
1085 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA); | ||
1086 | 1332 | ||
1087 | ieee80211_add_pending_skb(local, skb); | 1333 | if (!driver_release_tids) { |
1334 | struct sk_buff_head pending; | ||
1335 | struct sk_buff *skb; | ||
1336 | int num = 0; | ||
1337 | u16 tids = 0; | ||
1338 | |||
1339 | skb_queue_head_init(&pending); | ||
1340 | |||
1341 | while ((skb = __skb_dequeue(&frames))) { | ||
1342 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | ||
1343 | struct ieee80211_hdr *hdr = (void *) skb->data; | ||
1344 | u8 *qoshdr = NULL; | ||
1345 | |||
1346 | num++; | ||
1347 | |||
1348 | /* | ||
1349 | * Tell TX path to send this frame even though the | ||
1350 | * STA may still remain is PS mode after this frame | ||
1351 | * exchange. | ||
1352 | */ | ||
1353 | info->flags |= IEEE80211_TX_CTL_POLL_RESPONSE; | ||
1354 | |||
1355 | /* | ||
1356 | * Use MoreData flag to indicate whether there are | ||
1357 | * more buffered frames for this STA | ||
1358 | */ | ||
1359 | if (!more_data) | ||
1360 | hdr->frame_control &= | ||
1361 | cpu_to_le16(~IEEE80211_FCTL_MOREDATA); | ||
1362 | else | ||
1363 | hdr->frame_control |= | ||
1364 | cpu_to_le16(IEEE80211_FCTL_MOREDATA); | ||
1365 | |||
1366 | if (ieee80211_is_data_qos(hdr->frame_control) || | ||
1367 | ieee80211_is_qos_nullfunc(hdr->frame_control)) | ||
1368 | qoshdr = ieee80211_get_qos_ctl(hdr); | ||
1369 | |||
1370 | /* set EOSP for the frame */ | ||
1371 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD && | ||
1372 | qoshdr && skb_queue_empty(&frames)) | ||
1373 | *qoshdr |= IEEE80211_QOS_CTL_EOSP; | ||
1374 | |||
1375 | info->flags |= IEEE80211_TX_STATUS_EOSP | | ||
1376 | IEEE80211_TX_CTL_REQ_TX_STATUS; | ||
1377 | |||
1378 | if (qoshdr) | ||
1379 | tids |= BIT(*qoshdr & IEEE80211_QOS_CTL_TID_MASK); | ||
1380 | else | ||
1381 | tids |= BIT(0); | ||
1382 | |||
1383 | __skb_queue_tail(&pending, skb); | ||
1384 | } | ||
1088 | 1385 | ||
1089 | if (no_pending_pkts) | 1386 | drv_allow_buffered_frames(local, sta, tids, num, |
1090 | sta_info_clear_tim_bit(sta); | 1387 | reason, more_data); |
1091 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | 1388 | |
1389 | ieee80211_add_pending_skbs(local, &pending); | ||
1390 | |||
1391 | sta_info_recalc_tim(sta); | ||
1092 | } else { | 1392 | } else { |
1093 | /* | 1393 | /* |
1094 | * FIXME: This can be the result of a race condition between | 1394 | * We need to release a frame that is buffered somewhere in the |
1095 | * us expiring a frame and the station polling for it. | 1395 | * driver ... it'll have to handle that. |
1096 | * Should we send it a null-func frame indicating we | 1396 | * Note that, as per the comment above, it'll also have to see |
1097 | * have nothing buffered for it? | 1397 | * if there is more than just one frame on the specific TID that |
1398 | * we're releasing from, and it needs to set the more-data bit | ||
1399 | * accordingly if we tell it that there's no more data. If we do | ||
1400 | * tell it there's more data, then of course the more-data bit | ||
1401 | * needs to be set anyway. | ||
1402 | */ | ||
1403 | drv_release_buffered_frames(local, sta, driver_release_tids, | ||
1404 | n_frames, reason, more_data); | ||
1405 | |||
1406 | /* | ||
1407 | * Note that we don't recalculate the TIM bit here as it would | ||
1408 | * most likely have no effect at all unless the driver told us | ||
1409 | * that the TID became empty before returning here from the | ||
1410 | * release function. | ||
1411 | * Either way, however, when the driver tells us that the TID | ||
1412 | * became empty we'll do the TIM recalculation. | ||
1098 | */ | 1413 | */ |
1099 | printk(KERN_DEBUG "%s: STA %pM sent PS Poll even " | ||
1100 | "though there are no buffered frames for it\n", | ||
1101 | sdata->name, sta->sta.addr); | ||
1102 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | ||
1103 | } | 1414 | } |
1104 | } | 1415 | } |
1105 | 1416 | ||
1417 | void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta) | ||
1418 | { | ||
1419 | u8 ignore_for_response = sta->sta.uapsd_queues; | ||
1420 | |||
1421 | /* | ||
1422 | * If all ACs are delivery-enabled then we should reply | ||
1423 | * from any of them, if only some are enabled we reply | ||
1424 | * only from the non-enabled ones. | ||
1425 | */ | ||
1426 | if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1) | ||
1427 | ignore_for_response = 0; | ||
1428 | |||
1429 | ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response, | ||
1430 | IEEE80211_FRAME_RELEASE_PSPOLL); | ||
1431 | } | ||
1432 | |||
1433 | void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta) | ||
1434 | { | ||
1435 | int n_frames = sta->sta.max_sp; | ||
1436 | u8 delivery_enabled = sta->sta.uapsd_queues; | ||
1437 | |||
1438 | /* | ||
1439 | * If we ever grow support for TSPEC this might happen if | ||
1440 | * the TSPEC update from hostapd comes in between a trigger | ||
1441 | * frame setting WLAN_STA_UAPSD in the RX path and this | ||
1442 | * actually getting called. | ||
1443 | */ | ||
1444 | if (!delivery_enabled) | ||
1445 | return; | ||
1446 | |||
1447 | switch (sta->sta.max_sp) { | ||
1448 | case 1: | ||
1449 | n_frames = 2; | ||
1450 | break; | ||
1451 | case 2: | ||
1452 | n_frames = 4; | ||
1453 | break; | ||
1454 | case 3: | ||
1455 | n_frames = 6; | ||
1456 | break; | ||
1457 | case 0: | ||
1458 | /* XXX: what is a good value? */ | ||
1459 | n_frames = 8; | ||
1460 | break; | ||
1461 | } | ||
1462 | |||
1463 | ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled, | ||
1464 | IEEE80211_FRAME_RELEASE_UAPSD); | ||
1465 | } | ||
1466 | |||
1106 | void ieee80211_sta_block_awake(struct ieee80211_hw *hw, | 1467 | void ieee80211_sta_block_awake(struct ieee80211_hw *hw, |
1107 | struct ieee80211_sta *pubsta, bool block) | 1468 | struct ieee80211_sta *pubsta, bool block) |
1108 | { | 1469 | { |
@@ -1111,17 +1472,50 @@ void ieee80211_sta_block_awake(struct ieee80211_hw *hw, | |||
1111 | trace_api_sta_block_awake(sta->local, pubsta, block); | 1472 | trace_api_sta_block_awake(sta->local, pubsta, block); |
1112 | 1473 | ||
1113 | if (block) | 1474 | if (block) |
1114 | set_sta_flags(sta, WLAN_STA_PS_DRIVER); | 1475 | set_sta_flag(sta, WLAN_STA_PS_DRIVER); |
1115 | else if (test_sta_flags(sta, WLAN_STA_PS_DRIVER)) | 1476 | else if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) |
1116 | ieee80211_queue_work(hw, &sta->drv_unblock_wk); | 1477 | ieee80211_queue_work(hw, &sta->drv_unblock_wk); |
1117 | } | 1478 | } |
1118 | EXPORT_SYMBOL(ieee80211_sta_block_awake); | 1479 | EXPORT_SYMBOL(ieee80211_sta_block_awake); |
1119 | 1480 | ||
1120 | void ieee80211_sta_set_tim(struct ieee80211_sta *pubsta) | 1481 | void ieee80211_sta_eosp_irqsafe(struct ieee80211_sta *pubsta) |
1482 | { | ||
1483 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); | ||
1484 | struct ieee80211_local *local = sta->local; | ||
1485 | struct sk_buff *skb; | ||
1486 | struct skb_eosp_msg_data *data; | ||
1487 | |||
1488 | trace_api_eosp(local, pubsta); | ||
1489 | |||
1490 | skb = alloc_skb(0, GFP_ATOMIC); | ||
1491 | if (!skb) { | ||
1492 | /* too bad ... but race is better than loss */ | ||
1493 | clear_sta_flag(sta, WLAN_STA_SP); | ||
1494 | return; | ||
1495 | } | ||
1496 | |||
1497 | data = (void *)skb->cb; | ||
1498 | memcpy(data->sta, pubsta->addr, ETH_ALEN); | ||
1499 | memcpy(data->iface, sta->sdata->vif.addr, ETH_ALEN); | ||
1500 | skb->pkt_type = IEEE80211_EOSP_MSG; | ||
1501 | skb_queue_tail(&local->skb_queue, skb); | ||
1502 | tasklet_schedule(&local->tasklet); | ||
1503 | } | ||
1504 | EXPORT_SYMBOL(ieee80211_sta_eosp_irqsafe); | ||
1505 | |||
1506 | void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta, | ||
1507 | u8 tid, bool buffered) | ||
1121 | { | 1508 | { |
1122 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); | 1509 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
1123 | 1510 | ||
1124 | set_sta_flags(sta, WLAN_STA_PS_DRIVER_BUF); | 1511 | if (WARN_ON(tid >= STA_TID_NUM)) |
1125 | sta_info_set_tim_bit(sta); | 1512 | return; |
1513 | |||
1514 | if (buffered) | ||
1515 | set_bit(tid, &sta->driver_buffered_tids); | ||
1516 | else | ||
1517 | clear_bit(tid, &sta->driver_buffered_tids); | ||
1518 | |||
1519 | sta_info_recalc_tim(sta); | ||
1126 | } | 1520 | } |
1127 | EXPORT_SYMBOL(ieee80211_sta_set_tim); | 1521 | EXPORT_SYMBOL(ieee80211_sta_set_buffered); |