aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/ath/ath9k/recv.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/ath/ath9k/recv.c')
-rw-r--r--drivers/net/wireless/ath/ath9k/recv.c296
1 files changed, 281 insertions, 15 deletions
diff --git a/drivers/net/wireless/ath/ath9k/recv.c b/drivers/net/wireless/ath/ath9k/recv.c
index ca6065b71b46..da0cfe90c38a 100644
--- a/drivers/net/wireless/ath/ath9k/recv.c
+++ b/drivers/net/wireless/ath/ath9k/recv.c
@@ -116,9 +116,6 @@ static void ath_opmode_init(struct ath_softc *sc)
116 /* configure operational mode */ 116 /* configure operational mode */
117 ath9k_hw_setopmode(ah); 117 ath9k_hw_setopmode(ah);
118 118
119 /* Handle any link-level address change. */
120 ath9k_hw_setmac(ah, common->macaddr);
121
122 /* calculate and install multicast filter */ 119 /* calculate and install multicast filter */
123 mfilt[0] = mfilt[1] = ~0; 120 mfilt[0] = mfilt[1] = ~0;
124 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]); 121 ath9k_hw_setmcastfilter(ah, mfilt[0], mfilt[1]);
@@ -295,7 +292,7 @@ static void ath_edma_start_recv(struct ath_softc *sc)
295 292
296 ath_opmode_init(sc); 293 ath_opmode_init(sc);
297 294
298 ath9k_hw_startpcureceive(sc->sc_ah); 295 ath9k_hw_startpcureceive(sc->sc_ah, (sc->sc_flags & SC_OP_SCANNING));
299} 296}
300 297
301static void ath_edma_stop_recv(struct ath_softc *sc) 298static void ath_edma_stop_recv(struct ath_softc *sc)
@@ -501,7 +498,7 @@ int ath_startrecv(struct ath_softc *sc)
501start_recv: 498start_recv:
502 spin_unlock_bh(&sc->rx.rxbuflock); 499 spin_unlock_bh(&sc->rx.rxbuflock);
503 ath_opmode_init(sc); 500 ath_opmode_init(sc);
504 ath9k_hw_startpcureceive(ah); 501 ath9k_hw_startpcureceive(ah, (sc->sc_flags & SC_OP_SCANNING));
505 502
506 return 0; 503 return 0;
507} 504}
@@ -700,12 +697,16 @@ static bool ath_edma_get_buffers(struct ath_softc *sc,
700 bf = SKB_CB_ATHBUF(skb); 697 bf = SKB_CB_ATHBUF(skb);
701 BUG_ON(!bf); 698 BUG_ON(!bf);
702 699
703 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, 700 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
704 common->rx_bufsize, DMA_FROM_DEVICE); 701 common->rx_bufsize, DMA_FROM_DEVICE);
705 702
706 ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data); 703 ret = ath9k_hw_process_rxdesc_edma(ah, NULL, skb->data);
707 if (ret == -EINPROGRESS) 704 if (ret == -EINPROGRESS) {
705 /*let device gain the buffer again*/
706 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
707 common->rx_bufsize, DMA_FROM_DEVICE);
708 return false; 708 return false;
709 }
709 710
710 __skb_unlink(skb, &rx_edma->rx_fifo); 711 __skb_unlink(skb, &rx_edma->rx_fifo);
711 if (ret == -EINVAL) { 712 if (ret == -EINVAL) {
@@ -814,13 +815,263 @@ static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,
814 * 1. accessing the frame 815 * 1. accessing the frame
815 * 2. requeueing the same buffer to h/w 816 * 2. requeueing the same buffer to h/w
816 */ 817 */
817 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr, 818 dma_sync_single_for_cpu(sc->dev, bf->bf_buf_addr,
818 common->rx_bufsize, 819 common->rx_bufsize,
819 DMA_FROM_DEVICE); 820 DMA_FROM_DEVICE);
820 821
821 return bf; 822 return bf;
822} 823}
823 824
825/* Assumes you've already done the endian to CPU conversion */
826static bool ath9k_rx_accept(struct ath_common *common,
827 struct ieee80211_hdr *hdr,
828 struct ieee80211_rx_status *rxs,
829 struct ath_rx_status *rx_stats,
830 bool *decrypt_error)
831{
832 struct ath_hw *ah = common->ah;
833 __le16 fc;
834 u8 rx_status_len = ah->caps.rx_status_len;
835
836 fc = hdr->frame_control;
837
838 if (!rx_stats->rs_datalen)
839 return false;
840 /*
841 * rs_status follows rs_datalen so if rs_datalen is too large
842 * we can take a hint that hardware corrupted it, so ignore
843 * those frames.
844 */
845 if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len))
846 return false;
847
848 /*
849 * rs_more indicates chained descriptors which can be used
850 * to link buffers together for a sort of scatter-gather
851 * operation.
852 * reject the frame, we don't support scatter-gather yet and
853 * the frame is probably corrupt anyway
854 */
855 if (rx_stats->rs_more)
856 return false;
857
858 /*
859 * The rx_stats->rs_status will not be set until the end of the
860 * chained descriptors so it can be ignored if rs_more is set. The
861 * rs_more will be false at the last element of the chained
862 * descriptors.
863 */
864 if (rx_stats->rs_status != 0) {
865 if (rx_stats->rs_status & ATH9K_RXERR_CRC)
866 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
867 if (rx_stats->rs_status & ATH9K_RXERR_PHY)
868 return false;
869
870 if (rx_stats->rs_status & ATH9K_RXERR_DECRYPT) {
871 *decrypt_error = true;
872 } else if (rx_stats->rs_status & ATH9K_RXERR_MIC) {
873 if (ieee80211_is_ctl(fc))
874 /*
875 * Sometimes, we get invalid
876 * MIC failures on valid control frames.
877 * Remove these mic errors.
878 */
879 rx_stats->rs_status &= ~ATH9K_RXERR_MIC;
880 else
881 rxs->flag |= RX_FLAG_MMIC_ERROR;
882 }
883 /*
884 * Reject error frames with the exception of
885 * decryption and MIC failures. For monitor mode,
886 * we also ignore the CRC error.
887 */
888 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
889 if (rx_stats->rs_status &
890 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC |
891 ATH9K_RXERR_CRC))
892 return false;
893 } else {
894 if (rx_stats->rs_status &
895 ~(ATH9K_RXERR_DECRYPT | ATH9K_RXERR_MIC)) {
896 return false;
897 }
898 }
899 }
900 return true;
901}
902
903static int ath9k_process_rate(struct ath_common *common,
904 struct ieee80211_hw *hw,
905 struct ath_rx_status *rx_stats,
906 struct ieee80211_rx_status *rxs)
907{
908 struct ieee80211_supported_band *sband;
909 enum ieee80211_band band;
910 unsigned int i = 0;
911
912 band = hw->conf.channel->band;
913 sband = hw->wiphy->bands[band];
914
915 if (rx_stats->rs_rate & 0x80) {
916 /* HT rate */
917 rxs->flag |= RX_FLAG_HT;
918 if (rx_stats->rs_flags & ATH9K_RX_2040)
919 rxs->flag |= RX_FLAG_40MHZ;
920 if (rx_stats->rs_flags & ATH9K_RX_GI)
921 rxs->flag |= RX_FLAG_SHORT_GI;
922 rxs->rate_idx = rx_stats->rs_rate & 0x7f;
923 return 0;
924 }
925
926 for (i = 0; i < sband->n_bitrates; i++) {
927 if (sband->bitrates[i].hw_value == rx_stats->rs_rate) {
928 rxs->rate_idx = i;
929 return 0;
930 }
931 if (sband->bitrates[i].hw_value_short == rx_stats->rs_rate) {
932 rxs->flag |= RX_FLAG_SHORTPRE;
933 rxs->rate_idx = i;
934 return 0;
935 }
936 }
937
938 /*
939 * No valid hardware bitrate found -- we should not get here
940 * because hardware has already validated this frame as OK.
941 */
942 ath_print(common, ATH_DBG_XMIT, "unsupported hw bitrate detected "
943 "0x%02x using 1 Mbit\n", rx_stats->rs_rate);
944
945 return -EINVAL;
946}
947
948static void ath9k_process_rssi(struct ath_common *common,
949 struct ieee80211_hw *hw,
950 struct ieee80211_hdr *hdr,
951 struct ath_rx_status *rx_stats)
952{
953 struct ath_hw *ah = common->ah;
954 struct ieee80211_sta *sta;
955 struct ath_node *an;
956 int last_rssi = ATH_RSSI_DUMMY_MARKER;
957 __le16 fc;
958
959 fc = hdr->frame_control;
960
961 rcu_read_lock();
962 /*
963 * XXX: use ieee80211_find_sta! This requires quite a bit of work
964 * under the current ath9k virtual wiphy implementation as we have
965 * no way of tying a vif to wiphy. Typically vifs are attached to
966 * at least one sdata of a wiphy on mac80211 but with ath9k virtual
967 * wiphy you'd have to iterate over every wiphy and each sdata.
968 */
969 sta = ieee80211_find_sta_by_hw(hw, hdr->addr2);
970 if (sta) {
971 an = (struct ath_node *) sta->drv_priv;
972 if (rx_stats->rs_rssi != ATH9K_RSSI_BAD &&
973 !rx_stats->rs_moreaggr)
974 ATH_RSSI_LPF(an->last_rssi, rx_stats->rs_rssi);
975 last_rssi = an->last_rssi;
976 }
977 rcu_read_unlock();
978
979 if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
980 rx_stats->rs_rssi = ATH_EP_RND(last_rssi,
981 ATH_RSSI_EP_MULTIPLIER);
982 if (rx_stats->rs_rssi < 0)
983 rx_stats->rs_rssi = 0;
984
985 /* Update Beacon RSSI, this is used by ANI. */
986 if (ieee80211_is_beacon(fc))
987 ah->stats.avgbrssi = rx_stats->rs_rssi;
988}
989
990/*
991 * For Decrypt or Demic errors, we only mark packet status here and always push
992 * up the frame up to let mac80211 handle the actual error case, be it no
993 * decryption key or real decryption error. This let us keep statistics there.
994 */
995static int ath9k_rx_skb_preprocess(struct ath_common *common,
996 struct ieee80211_hw *hw,
997 struct ieee80211_hdr *hdr,
998 struct ath_rx_status *rx_stats,
999 struct ieee80211_rx_status *rx_status,
1000 bool *decrypt_error)
1001{
1002 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
1003
1004 /*
1005 * everything but the rate is checked here, the rate check is done
1006 * separately to avoid doing two lookups for a rate for each frame.
1007 */
1008 if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
1009 return -EINVAL;
1010
1011 ath9k_process_rssi(common, hw, hdr, rx_stats);
1012
1013 if (ath9k_process_rate(common, hw, rx_stats, rx_status))
1014 return -EINVAL;
1015
1016 rx_status->band = hw->conf.channel->band;
1017 rx_status->freq = hw->conf.channel->center_freq;
1018 rx_status->signal = ATH_DEFAULT_NOISE_FLOOR + rx_stats->rs_rssi;
1019 rx_status->antenna = rx_stats->rs_antenna;
1020 rx_status->flag |= RX_FLAG_TSFT;
1021
1022 return 0;
1023}
1024
1025static void ath9k_rx_skb_postprocess(struct ath_common *common,
1026 struct sk_buff *skb,
1027 struct ath_rx_status *rx_stats,
1028 struct ieee80211_rx_status *rxs,
1029 bool decrypt_error)
1030{
1031 struct ath_hw *ah = common->ah;
1032 struct ieee80211_hdr *hdr;
1033 int hdrlen, padpos, padsize;
1034 u8 keyix;
1035 __le16 fc;
1036
1037 /* see if any padding is done by the hw and remove it */
1038 hdr = (struct ieee80211_hdr *) skb->data;
1039 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1040 fc = hdr->frame_control;
1041 padpos = ath9k_cmn_padpos(hdr->frame_control);
1042
1043 /* The MAC header is padded to have 32-bit boundary if the
1044 * packet payload is non-zero. The general calculation for
1045 * padsize would take into account odd header lengths:
1046 * padsize = (4 - padpos % 4) % 4; However, since only
1047 * even-length headers are used, padding can only be 0 or 2
1048 * bytes and we can optimize this a bit. In addition, we must
1049 * not try to remove padding from short control frames that do
1050 * not have payload. */
1051 padsize = padpos & 3;
1052 if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
1053 memmove(skb->data + padsize, skb->data, padpos);
1054 skb_pull(skb, padsize);
1055 }
1056
1057 keyix = rx_stats->rs_keyix;
1058
1059 if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
1060 ieee80211_has_protected(fc)) {
1061 rxs->flag |= RX_FLAG_DECRYPTED;
1062 } else if (ieee80211_has_protected(fc)
1063 && !decrypt_error && skb->len >= hdrlen + 4) {
1064 keyix = skb->data[hdrlen + 3] >> 6;
1065
1066 if (test_bit(keyix, common->keymap))
1067 rxs->flag |= RX_FLAG_DECRYPTED;
1068 }
1069 if (ah->sw_mgmt_crypto &&
1070 (rxs->flag & RX_FLAG_DECRYPTED) &&
1071 ieee80211_is_mgmt(fc))
1072 /* Use software decrypt for management frames. */
1073 rxs->flag &= ~RX_FLAG_DECRYPTED;
1074}
824 1075
825int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) 1076int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
826{ 1077{
@@ -842,15 +1093,21 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
842 enum ath9k_rx_qtype qtype; 1093 enum ath9k_rx_qtype qtype;
843 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA); 1094 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
844 int dma_type; 1095 int dma_type;
1096 u8 rx_status_len = ah->caps.rx_status_len;
1097 u64 tsf = 0;
1098 u32 tsf_lower = 0;
845 1099
846 if (edma) 1100 if (edma)
847 dma_type = DMA_FROM_DEVICE;
848 else
849 dma_type = DMA_BIDIRECTIONAL; 1101 dma_type = DMA_BIDIRECTIONAL;
1102 else
1103 dma_type = DMA_FROM_DEVICE;
850 1104
851 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP; 1105 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
852 spin_lock_bh(&sc->rx.rxbuflock); 1106 spin_lock_bh(&sc->rx.rxbuflock);
853 1107
1108 tsf = ath9k_hw_gettsf64(ah);
1109 tsf_lower = tsf & 0xffffffff;
1110
854 do { 1111 do {
855 /* If handling rx interrupt and flush is in progress => exit */ 1112 /* If handling rx interrupt and flush is in progress => exit */
856 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0)) 1113 if ((sc->sc_flags & SC_OP_RXFLUSH) && (flush == 0))
@@ -869,7 +1126,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
869 if (!skb) 1126 if (!skb)
870 continue; 1127 continue;
871 1128
872 hdr = (struct ieee80211_hdr *) skb->data; 1129 hdr = (struct ieee80211_hdr *) (skb->data + rx_status_len);
873 rxs = IEEE80211_SKB_RXCB(skb); 1130 rxs = IEEE80211_SKB_RXCB(skb);
874 1131
875 hw = ath_get_virt_hw(sc, hdr); 1132 hw = ath_get_virt_hw(sc, hdr);
@@ -883,8 +1140,17 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
883 if (flush) 1140 if (flush)
884 goto requeue; 1141 goto requeue;
885 1142
886 retval = ath9k_cmn_rx_skb_preprocess(common, hw, skb, &rs, 1143 rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
887 rxs, &decrypt_error); 1144 if (rs.rs_tstamp > tsf_lower &&
1145 unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
1146 rxs->mactime -= 0x100000000ULL;
1147
1148 if (rs.rs_tstamp < tsf_lower &&
1149 unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
1150 rxs->mactime += 0x100000000ULL;
1151
1152 retval = ath9k_rx_skb_preprocess(common, hw, hdr, &rs,
1153 rxs, &decrypt_error);
888 if (retval) 1154 if (retval)
889 goto requeue; 1155 goto requeue;
890 1156
@@ -908,8 +1174,8 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
908 if (ah->caps.rx_status_len) 1174 if (ah->caps.rx_status_len)
909 skb_pull(skb, ah->caps.rx_status_len); 1175 skb_pull(skb, ah->caps.rx_status_len);
910 1176
911 ath9k_cmn_rx_skb_postprocess(common, skb, &rs, 1177 ath9k_rx_skb_postprocess(common, skb, &rs,
912 rxs, decrypt_error); 1178 rxs, decrypt_error);
913 1179
914 /* We will now give hardware our shiny new allocated skb */ 1180 /* We will now give hardware our shiny new allocated skb */
915 bf->bf_mpdu = requeue_skb; 1181 bf->bf_mpdu = requeue_skb;