+static unsigned int wlan_rx_filter(struct dma_desc *desc)
+{
+ struct ieee80211_hdr *hdr;
+ unsigned int data_len;
+ unsigned int rx_filter;
+ unsigned int mac_err;
+
+ data_len = ar9170_get_rx_mpdu_len(desc);
+ mac_err = ar9170_get_rx_macstatus_error(desc);
+
+#define AR9170_RX_ERROR_BAD (AR9170_RX_ERROR_FCS | AR9170_RX_ERROR_PLCP)
+
+ if (unlikely(data_len < (4 + 6 + FCS_LEN) ||
+ desc->totalLen > CONFIG_CARL9170FW_RX_FRAME_LEN) ||
+ mac_err & AR9170_RX_ERROR_BAD) {
+ /*
+ * This frame is too damaged to do anything
+ * useful with it.
+ */
+
+ return CARL9170_RX_FILTER_BAD;
+ }
+
+ rx_filter = 0;
+ if (mac_err & AR9170_RX_ERROR_WRONG_RA)
+ rx_filter |= CARL9170_RX_FILTER_OTHER_RA;
+
+ if (mac_err & AR9170_RX_ERROR_DECRYPT)
+ rx_filter |= CARL9170_RX_FILTER_DECRY_FAIL;
+
+ hdr = ar9170_get_rx_i3e(desc);
+ if (likely(ieee80211_is_data(hdr->frame_control))) {
+ rx_filter |= CARL9170_RX_FILTER_DATA;
+ } else if (ieee80211_is_ctl(hdr->frame_control)) {
+ switch (le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_STYPE) {
+ case IEEE80211_STYPE_BACK_REQ:
+ handle_bar(desc, hdr, data_len, mac_err);
+ /* fallthrough */
+ rx_filter |= CARL9170_RX_FILTER_CTL_BACKR;
+ break;
+ case IEEE80211_STYPE_PSPOLL:
+ rx_filter |= CARL9170_RX_FILTER_CTL_PSPOLL;
+ break;
+ default:
+ rx_filter |= CARL9170_RX_FILTER_CTL_OTHER;
+ break;
+ }
+ } else {
+ /* ieee80211_is_mgmt */
+ rx_filter |= CARL9170_RX_FILTER_MGMT;
+ }
+
+ if (unlikely(fw.suspend_mode == CARL9170_HOST_SUSPENDED)) {
+ wol_rx(rx_filter, hdr, min(data_len,
+ (unsigned int)AR9170_BLOCK_SIZE));
+ }
+
+#undef AR9170_RX_ERROR_BAD
+
+ return rx_filter;
+}
+