diff options
Diffstat (limited to 'drivers/net/wireless/ath/ath9k/recv.c')
-rw-r--r-- | drivers/net/wireless/ath/ath9k/recv.c | 267 |
1 files changed, 13 insertions, 254 deletions
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c index 82e340d3ec60..6c9accdb52e4 100644 --- a/drivers/net/wireless/ath/ath9k/recv.c +++ b/drivers/net/wireless/ath/ath9k/recv.c | |||
@@ -762,204 +762,6 @@ static struct ath_rxbuf *ath_get_next_rx_buf(struct ath_softc *sc, | |||
762 | return bf; | 762 | return bf; |
763 | } | 763 | } |
764 | 764 | ||
765 | /* Assumes you've already done the endian to CPU conversion */ | ||
766 | static bool ath9k_rx_accept(struct ath_common *common, | ||
767 | struct ieee80211_hdr *hdr, | ||
768 | struct ieee80211_rx_status *rxs, | ||
769 | struct ath_rx_status *rx_stats, | ||
770 | bool *decrypt_error) | ||
771 | { | ||
772 | struct ath_softc *sc = (struct ath_softc *) common->priv; | ||
773 | bool is_mc, is_valid_tkip, strip_mic, mic_error; | ||
774 | struct ath_hw *ah = common->ah; | ||
775 | __le16 fc; | ||
776 | |||
777 | fc = hdr->frame_control; | ||
778 | |||
779 | is_mc = !!is_multicast_ether_addr(hdr->addr1); | ||
780 | is_valid_tkip = rx_stats->rs_keyix != ATH9K_RXKEYIX_INVALID && | ||
781 | test_bit(rx_stats->rs_keyix, common->tkip_keymap); | ||
782 | strip_mic = is_valid_tkip && ieee80211_is_data(fc) && | ||
783 | ieee80211_has_protected(fc) && | ||
784 | !(rx_stats->rs_status & | ||
785 | (ATH9K_RXERR_DECRYPT | ATH9K_RXERR_CRC | ATH9K_RXERR_MIC | | ||
786 | ATH9K_RXERR_KEYMISS)); | ||
787 | |||
788 | /* | ||
789 | * Key miss events are only relevant for pairwise keys where the | ||
790 | * descriptor does contain a valid key index. This has been observed | ||
791 | * mostly with CCMP encryption. | ||
792 | */ | ||
793 | if (rx_stats->rs_keyix == ATH9K_RXKEYIX_INVALID || | ||
794 | !test_bit(rx_stats->rs_keyix, common->ccmp_keymap)) | ||
795 | rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS; | ||
796 | |||
797 | mic_error = is_valid_tkip && !ieee80211_is_ctl(fc) && | ||
798 | !ieee80211_has_morefrags(fc) && | ||
799 | !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) && | ||
800 | (rx_stats->rs_status & ATH9K_RXERR_MIC); | ||
801 | |||
802 | /* | ||
803 | * The rx_stats->rs_status will not be set until the end of the | ||
804 | * chained descriptors so it can be ignored if rs_more is set. The | ||
805 | * rs_more will be false at the last element of the chained | ||
806 | * descriptors. | ||
807 | */ | ||
808 | if (rx_stats->rs_status != 0) { | ||
809 | u8 status_mask; | ||
810 | |||
811 | if (rx_stats->rs_status & ATH9K_RXERR_CRC) { | ||
812 | rxs->flag |= RX_FLAG_FAILED_FCS_CRC; | ||
813 | mic_error = false; | ||
814 | } | ||
815 | |||
816 | if ((rx_stats->rs_status & ATH9K_RXERR_DECRYPT) || | ||
817 | (!is_mc && (rx_stats->rs_status & ATH9K_RXERR_KEYMISS))) { | ||
818 | *decrypt_error = true; | ||
819 | mic_error = false; | ||
820 | } | ||
821 | |||
822 | /* | ||
823 | * Reject error frames with the exception of | ||
824 | * decryption and MIC failures. For monitor mode, | ||
825 | * we also ignore the CRC error. | ||
826 | */ | ||
827 | status_mask = ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC | | ||
828 | ATH9K_RXERR_KEYMISS; | ||
829 | |||
830 | if (ah->is_monitoring && (sc->rx.rxfilter & FIF_FCSFAIL)) | ||
831 | status_mask |= ATH9K_RXERR_CRC; | ||
832 | |||
833 | if (rx_stats->rs_status & ~status_mask) | ||
834 | return false; | ||
835 | } | ||
836 | |||
837 | /* | ||
838 | * For unicast frames the MIC error bit can have false positives, | ||
839 | * so all MIC error reports need to be validated in software. | ||
840 | * False negatives are not common, so skip software verification | ||
841 | * if the hardware considers the MIC valid. | ||
842 | */ | ||
843 | if (strip_mic) | ||
844 | rxs->flag |= RX_FLAG_MMIC_STRIPPED; | ||
845 | else if (is_mc && mic_error) | ||
846 | rxs->flag |= RX_FLAG_MMIC_ERROR; | ||
847 | |||
848 | return true; | ||
849 | } | ||
850 | |||
851 | static int ath9k_process_rate(struct ath_common *common, | ||
852 | struct ieee80211_hw *hw, | ||
853 | struct ath_rx_status *rx_stats, | ||
854 | struct ieee80211_rx_status *rxs) | ||
855 | { | ||
856 | struct ieee80211_supported_band *sband; | ||
857 | enum ieee80211_band band; | ||
858 | unsigned int i = 0; | ||
859 | struct ath_softc __maybe_unused *sc = common->priv; | ||
860 | struct ath_hw *ah = sc->sc_ah; | ||
861 | |||
862 | band = ah->curchan->chan->band; | ||
863 | sband = hw->wiphy->bands[band]; | ||
864 | |||
865 | if (IS_CHAN_QUARTER_RATE(ah->curchan)) | ||
866 | rxs->flag |= RX_FLAG_5MHZ; | ||
867 | else if (IS_CHAN_HALF_RATE(ah->curchan)) | ||
868 | rxs->flag |= RX_FLAG_10MHZ; | ||
869 | |||
870 | if (rx_stats->rs_rate & 0x80) { | ||
871 | /* HT rate */ | ||
872 | rxs->flag |= RX_FLAG_HT; | ||
873 | rxs->flag |= rx_stats->flag; | ||
874 | rxs->rate_idx = rx_stats->rs_rate & 0x7f; | ||
875 | return 0; | ||
876 | } | ||
877 | |||
878 | for (i = 0; i < sband->n_bitrates; i++) { | ||
879 | if (sband->bitrates[i].hw_value == rx_stats->rs_rate) { | ||
880 | rxs->rate_idx = i; | ||
881 | return 0; | ||
882 | } | ||
883 | if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) { | ||
884 | rxs->flag |= RX_FLAG_SHORTPRE; | ||
885 | rxs->rate_idx = i; | ||
886 | return 0; | ||
887 | } | ||
888 | } | ||
889 | |||
890 | /* | ||
891 | * No valid hardware bitrate found -- we should not get here | ||
892 | * because hardware has already validated this frame as OK. | ||
893 | */ | ||
894 | ath_dbg(common, ANY, | ||
895 | "unsupported hw bitrate detected 0x%02x using 1 Mbit\n", | ||
896 | rx_stats->rs_rate); | ||
897 | RX_STAT_INC(rx_rate_err); | ||
898 | return -EINVAL; | ||
899 | } | ||
900 | |||
901 | static void ath9k_process_rssi(struct ath_common *common, | ||
902 | struct ieee80211_hw *hw, | ||
903 | struct ath_rx_status *rx_stats, | ||
904 | struct ieee80211_rx_status *rxs) | ||
905 | { | ||
906 | struct ath_softc *sc = hw->priv; | ||
907 | struct ath_hw *ah = common->ah; | ||
908 | int last_rssi; | ||
909 | int rssi = rx_stats->rs_rssi; | ||
910 | int i, j; | ||
911 | |||
912 | /* | ||
913 | * RSSI is not available for subframes in an A-MPDU. | ||
914 | */ | ||
915 | if (rx_stats->rs_moreaggr) { | ||
916 | rxs->flag |= RX_FLAG_NO_SIGNAL_VAL; | ||
917 | return; | ||
918 | } | ||
919 | |||
920 | /* | ||
921 | * Check if the RSSI for the last subframe in an A-MPDU | ||
922 | * or an unaggregated frame is valid. | ||
923 | */ | ||
924 | if (rx_stats->rs_rssi == ATH9K_RSSI_BAD) { | ||
925 | rxs->flag |= RX_FLAG_NO_SIGNAL_VAL; | ||
926 | return; | ||
927 | } | ||
928 | |||
929 | for (i = 0, j = 0; i < ARRAY_SIZE(rx_stats->rs_rssi_ctl); i++) { | ||
930 | s8 rssi; | ||
931 | |||
932 | if (!(ah->rxchainmask & BIT(i))) | ||
933 | continue; | ||
934 | |||
935 | rssi = rx_stats->rs_rssi_ctl[i]; | ||
936 | if (rssi != ATH9K_RSSI_BAD) { | ||
937 | rxs->chains |= BIT(j); | ||
938 | rxs->chain_signal[j] = ah->noise + rssi; | ||
939 | } | ||
940 | j++; | ||
941 | } | ||
942 | |||
943 | /* | ||
944 | * Update Beacon RSSI, this is used by ANI. | ||
945 | */ | ||
946 | if (rx_stats->is_mybeacon && | ||
947 | ((ah->opmode == NL80211_IFTYPE_STATION) || | ||
948 | (ah->opmode == NL80211_IFTYPE_ADHOC))) { | ||
949 | ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi); | ||
950 | last_rssi = sc->last_rssi; | ||
951 | |||
952 | if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER)) | ||
953 | rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER); | ||
954 | if (rssi < 0) | ||
955 | rssi = 0; | ||
956 | |||
957 | ah->stats.avgbrssi = rssi; | ||
958 | } | ||
959 | |||
960 | rxs->signal = ah->noise + rx_stats->rs_rssi; | ||
961 | } | ||
962 | |||
963 | static void ath9k_process_tsf(struct ath_rx_status *rs, | 765 | static void ath9k_process_tsf(struct ath_rx_status *rs, |
964 | struct ieee80211_rx_status *rxs, | 766 | struct ieee80211_rx_status *rxs, |
965 | u64 tsf) | 767 | u64 tsf) |
@@ -1055,7 +857,7 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc, | |||
1055 | * everything but the rate is checked here, the rate check is done | 857 | * everything but the rate is checked here, the rate check is done |
1056 | * separately to avoid doing two lookups for a rate for each frame. | 858 | * separately to avoid doing two lookups for a rate for each frame. |
1057 | */ | 859 | */ |
1058 | if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error)) | 860 | if (!ath9k_cmn_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error, sc->rx.rxfilter)) |
1059 | return -EINVAL; | 861 | return -EINVAL; |
1060 | 862 | ||
1061 | if (ath_is_mybeacon(common, hdr)) { | 863 | if (ath_is_mybeacon(common, hdr)) { |
@@ -1069,10 +871,18 @@ static int ath9k_rx_skb_preprocess(struct ath_softc *sc, | |||
1069 | if (WARN_ON(!ah->curchan)) | 871 | if (WARN_ON(!ah->curchan)) |
1070 | return -EINVAL; | 872 | return -EINVAL; |
1071 | 873 | ||
1072 | if (ath9k_process_rate(common, hw, rx_stats, rx_status)) | 874 | if (ath9k_cmn_process_rate(common, hw, rx_stats, rx_status)) { |
875 | /* | ||
876 | * No valid hardware bitrate found -- we should not get here | ||
877 | * because hardware has already validated this frame as OK. | ||
878 | */ | ||
879 | ath_dbg(common, ANY, "unsupported hw bitrate detected 0x%02x using 1 Mbit\n", | ||
880 | rx_stats->rs_rate); | ||
881 | RX_STAT_INC(rx_rate_err); | ||
1073 | return -EINVAL; | 882 | return -EINVAL; |
883 | } | ||
1074 | 884 | ||
1075 | ath9k_process_rssi(common, hw, rx_stats, rx_status); | 885 | ath9k_cmn_process_rssi(common, hw, rx_stats, rx_status); |
1076 | 886 | ||
1077 | rx_status->band = ah->curchan->chan->band; | 887 | rx_status->band = ah->curchan->chan->band; |
1078 | rx_status->freq = ah->curchan->chan->center_freq; | 888 | rx_status->freq = ah->curchan->chan->center_freq; |
@@ -1092,57 +902,6 @@ corrupt: | |||
1092 | return -EINVAL; | 902 | return -EINVAL; |
1093 | } | 903 | } |
1094 | 904 | ||
1095 | static void ath9k_rx_skb_postprocess(struct ath_common *common, | ||
1096 | struct sk_buff *skb, | ||
1097 | struct ath_rx_status *rx_stats, | ||
1098 | struct ieee80211_rx_status *rxs, | ||
1099 | bool decrypt_error) | ||
1100 | { | ||
1101 | struct ath_hw *ah = common->ah; | ||
1102 | struct ieee80211_hdr *hdr; | ||
1103 | int hdrlen, padpos, padsize; | ||
1104 | u8 keyix; | ||
1105 | __le16 fc; | ||
1106 | |||
1107 | /* see if any padding is done by the hw and remove it */ | ||
1108 | hdr = (struct ieee80211_hdr *) skb->data; | ||
1109 | hdrlen = ieee80211_get_hdrlen_from_skb(skb); | ||
1110 | fc = hdr->frame_control; | ||
1111 | padpos = ieee80211_hdrlen(fc); | ||
1112 | |||
1113 | /* The MAC header is padded to have 32-bit boundary if the | ||
1114 | * packet payload is non-zero. The general calculation for | ||
1115 | * padsize would take into account odd header lengths: | ||
1116 | * padsize = (4 - padpos % 4) % 4; However, since only | ||
1117 | * even-length headers are used, padding can only be 0 or 2 | ||
1118 | * bytes and we can optimize this a bit. In addition, we must | ||
1119 | * not try to remove padding from short control frames that do | ||
1120 | * not have payload. */ | ||
1121 | padsize = padpos & 3; | ||
1122 | if (padsize && skb->len>=padpos+padsize+FCS_LEN) { | ||
1123 | memmove(skb->data + padsize, skb->data, padpos); | ||
1124 | skb_pull(skb, padsize); | ||
1125 | } | ||
1126 | |||
1127 | keyix = rx_stats->rs_keyix; | ||
1128 | |||
1129 | if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error && | ||
1130 | ieee80211_has_protected(fc)) { | ||
1131 | rxs->flag |= RX_FLAG_DECRYPTED; | ||
1132 | } else if (ieee80211_has_protected(fc) | ||
1133 | && !decrypt_error && skb->len >= hdrlen + 4) { | ||
1134 | keyix = skb->data[hdrlen + 3] >> 6; | ||
1135 | |||
1136 | if (test_bit(keyix, common->keymap)) | ||
1137 | rxs->flag |= RX_FLAG_DECRYPTED; | ||
1138 | } | ||
1139 | if (ah->sw_mgmt_crypto && | ||
1140 | (rxs->flag & RX_FLAG_DECRYPTED) && | ||
1141 | ieee80211_is_mgmt(fc)) | ||
1142 | /* Use software decrypt for management frames. */ | ||
1143 | rxs->flag &= ~RX_FLAG_DECRYPTED; | ||
1144 | } | ||
1145 | |||
1146 | /* | 905 | /* |
1147 | * Run the LNA combining algorithm only in these cases: | 906 | * Run the LNA combining algorithm only in these cases: |
1148 | * | 907 | * |
@@ -1292,8 +1051,8 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) | |||
1292 | skb_pull(skb, ah->caps.rx_status_len); | 1051 | skb_pull(skb, ah->caps.rx_status_len); |
1293 | 1052 | ||
1294 | if (!rs.rs_more) | 1053 | if (!rs.rs_more) |
1295 | ath9k_rx_skb_postprocess(common, hdr_skb, &rs, | 1054 | ath9k_cmn_rx_skb_postprocess(common, hdr_skb, &rs, |
1296 | rxs, decrypt_error); | 1055 | rxs, decrypt_error); |
1297 | 1056 | ||
1298 | if (rs.rs_more) { | 1057 | if (rs.rs_more) { |
1299 | RX_STAT_INC(rx_frags); | 1058 | RX_STAT_INC(rx_frags); |