18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/****************************************************************************** 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved. 58c2ecf20Sopenharmony_ci * Copyright(c) 2015 Intel Deutschland GmbH 68c2ecf20Sopenharmony_ci * Copyright(c) 2018 Intel Corporation 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Portions of this file are derived from the ipw3945 project, as well 98c2ecf20Sopenharmony_ci * as portionhelp of the ieee80211 subsystem header files. 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * Contact Information: 128c2ecf20Sopenharmony_ci * Intel Linux Wireless <linuxwifi@intel.com> 138c2ecf20Sopenharmony_ci * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci *****************************************************************************/ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 188c2ecf20Sopenharmony_ci#include <linux/slab.h> 198c2ecf20Sopenharmony_ci#include <linux/sched.h> 208c2ecf20Sopenharmony_ci#include <net/mac80211.h> 218c2ecf20Sopenharmony_ci#include <asm/unaligned.h> 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#include "iwl-trans.h" 248c2ecf20Sopenharmony_ci#include "iwl-io.h" 258c2ecf20Sopenharmony_ci#include "dev.h" 268c2ecf20Sopenharmony_ci#include "calib.h" 278c2ecf20Sopenharmony_ci#include "agn.h" 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci/****************************************************************************** 308c2ecf20Sopenharmony_ci * 318c2ecf20Sopenharmony_ci * Generic RX handler implementations 328c2ecf20Sopenharmony_ci * 338c2ecf20Sopenharmony_ci ******************************************************************************/ 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistatic void iwlagn_rx_reply_error(struct iwl_priv *priv, 368c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 398c2ecf20Sopenharmony_ci struct iwl_error_resp *err_resp = (void *)pkt->data; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci IWL_ERR(priv, "Error Reply type 0x%08X cmd REPLY_ERROR (0x%02X) " 428c2ecf20Sopenharmony_ci "seq 0x%04X ser 0x%08X\n", 438c2ecf20Sopenharmony_ci le32_to_cpu(err_resp->error_type), 448c2ecf20Sopenharmony_ci err_resp->cmd_id, 458c2ecf20Sopenharmony_ci le16_to_cpu(err_resp->bad_cmd_seq_num), 468c2ecf20Sopenharmony_ci le32_to_cpu(err_resp->error_info)); 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistatic void iwlagn_rx_csa(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 528c2ecf20Sopenharmony_ci struct iwl_csa_notification *csa = (void *)pkt->data; 538c2ecf20Sopenharmony_ci /* 548c2ecf20Sopenharmony_ci * MULTI-FIXME 558c2ecf20Sopenharmony_ci * See iwlagn_mac_channel_switch. 568c2ecf20Sopenharmony_ci */ 578c2ecf20Sopenharmony_ci struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; 588c2ecf20Sopenharmony_ci struct iwl_rxon_cmd *rxon = (void *)&ctx->active; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status)) 618c2ecf20Sopenharmony_ci return; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) { 648c2ecf20Sopenharmony_ci rxon->channel = csa->channel; 658c2ecf20Sopenharmony_ci ctx->staging.channel = csa->channel; 668c2ecf20Sopenharmony_ci IWL_DEBUG_11H(priv, "CSA notif: channel %d\n", 678c2ecf20Sopenharmony_ci le16_to_cpu(csa->channel)); 688c2ecf20Sopenharmony_ci iwl_chswitch_done(priv, true); 698c2ecf20Sopenharmony_ci } else { 708c2ecf20Sopenharmony_ci IWL_ERR(priv, "CSA notif (fail) : channel %d\n", 718c2ecf20Sopenharmony_ci le16_to_cpu(csa->channel)); 728c2ecf20Sopenharmony_ci iwl_chswitch_done(priv, false); 738c2ecf20Sopenharmony_ci } 748c2ecf20Sopenharmony_ci} 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic void iwlagn_rx_spectrum_measure_notif(struct iwl_priv *priv, 788c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 818c2ecf20Sopenharmony_ci struct iwl_spectrum_notification *report = (void *)pkt->data; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci if (!report->state) { 848c2ecf20Sopenharmony_ci IWL_DEBUG_11H(priv, 858c2ecf20Sopenharmony_ci "Spectrum Measure Notification: Start\n"); 868c2ecf20Sopenharmony_ci return; 878c2ecf20Sopenharmony_ci } 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci memcpy(&priv->measure_report, report, sizeof(*report)); 908c2ecf20Sopenharmony_ci priv->measurement_status |= MEASUREMENT_READY; 918c2ecf20Sopenharmony_ci} 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic void iwlagn_rx_pm_sleep_notif(struct iwl_priv *priv, 948c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 958c2ecf20Sopenharmony_ci{ 968c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG 978c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 988c2ecf20Sopenharmony_ci struct iwl_sleep_notification *sleep = (void *)pkt->data; 998c2ecf20Sopenharmony_ci IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n", 1008c2ecf20Sopenharmony_ci sleep->pm_sleep_mode, sleep->pm_wakeup_src); 1018c2ecf20Sopenharmony_ci#endif 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistatic void iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv *priv, 1058c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 1068c2ecf20Sopenharmony_ci{ 1078c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 1088c2ecf20Sopenharmony_ci u32 __maybe_unused len = iwl_rx_packet_len(pkt); 1098c2ecf20Sopenharmony_ci IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled " 1108c2ecf20Sopenharmony_ci "notification for PM_DEBUG_STATISTIC_NOTIFIC:\n", len); 1118c2ecf20Sopenharmony_ci iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->data, len); 1128c2ecf20Sopenharmony_ci} 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistatic void iwlagn_rx_beacon_notif(struct iwl_priv *priv, 1158c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 1188c2ecf20Sopenharmony_ci struct iwlagn_beacon_notif *beacon = (void *)pkt->data; 1198c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG 1208c2ecf20Sopenharmony_ci u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status); 1218c2ecf20Sopenharmony_ci u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d " 1248c2ecf20Sopenharmony_ci "tsf:0x%.8x%.8x rate:%d\n", 1258c2ecf20Sopenharmony_ci status & TX_STATUS_MSK, 1268c2ecf20Sopenharmony_ci beacon->beacon_notify_hdr.failure_frame, 1278c2ecf20Sopenharmony_ci le32_to_cpu(beacon->ibss_mgr_status), 1288c2ecf20Sopenharmony_ci le32_to_cpu(beacon->high_tsf), 1298c2ecf20Sopenharmony_ci le32_to_cpu(beacon->low_tsf), rate); 1308c2ecf20Sopenharmony_ci#endif 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci/* 1368c2ecf20Sopenharmony_ci * iwl_good_plcp_health - checks for plcp error. 1378c2ecf20Sopenharmony_ci * 1388c2ecf20Sopenharmony_ci * When the plcp error is exceeding the thresholds, reset the radio 1398c2ecf20Sopenharmony_ci * to improve the throughput. 1408c2ecf20Sopenharmony_ci */ 1418c2ecf20Sopenharmony_cistatic bool iwlagn_good_plcp_health(struct iwl_priv *priv, 1428c2ecf20Sopenharmony_ci struct statistics_rx_phy *cur_ofdm, 1438c2ecf20Sopenharmony_ci struct statistics_rx_ht_phy *cur_ofdm_ht, 1448c2ecf20Sopenharmony_ci unsigned int msecs) 1458c2ecf20Sopenharmony_ci{ 1468c2ecf20Sopenharmony_ci int delta; 1478c2ecf20Sopenharmony_ci int threshold = priv->plcp_delta_threshold; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) { 1508c2ecf20Sopenharmony_ci IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n"); 1518c2ecf20Sopenharmony_ci return true; 1528c2ecf20Sopenharmony_ci } 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci delta = le32_to_cpu(cur_ofdm->plcp_err) - 1558c2ecf20Sopenharmony_ci le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) + 1568c2ecf20Sopenharmony_ci le32_to_cpu(cur_ofdm_ht->plcp_err) - 1578c2ecf20Sopenharmony_ci le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err); 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci /* Can be negative if firmware reset statistics */ 1608c2ecf20Sopenharmony_ci if (delta <= 0) 1618c2ecf20Sopenharmony_ci return true; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci if ((delta * 100 / msecs) > threshold) { 1648c2ecf20Sopenharmony_ci IWL_DEBUG_RADIO(priv, 1658c2ecf20Sopenharmony_ci "plcp health threshold %u delta %d msecs %u\n", 1668c2ecf20Sopenharmony_ci threshold, delta, msecs); 1678c2ecf20Sopenharmony_ci return false; 1688c2ecf20Sopenharmony_ci } 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci return true; 1718c2ecf20Sopenharmony_ci} 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_ciint iwl_force_rf_reset(struct iwl_priv *priv, bool external) 1748c2ecf20Sopenharmony_ci{ 1758c2ecf20Sopenharmony_ci struct iwl_rf_reset *rf_reset; 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 1788c2ecf20Sopenharmony_ci return -EAGAIN; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci if (!iwl_is_any_associated(priv)) { 1818c2ecf20Sopenharmony_ci IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n"); 1828c2ecf20Sopenharmony_ci return -ENOLINK; 1838c2ecf20Sopenharmony_ci } 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci rf_reset = &priv->rf_reset; 1868c2ecf20Sopenharmony_ci rf_reset->reset_request_count++; 1878c2ecf20Sopenharmony_ci if (!external && rf_reset->last_reset_jiffies && 1888c2ecf20Sopenharmony_ci time_after(rf_reset->last_reset_jiffies + 1898c2ecf20Sopenharmony_ci IWL_DELAY_NEXT_FORCE_RF_RESET, jiffies)) { 1908c2ecf20Sopenharmony_ci IWL_DEBUG_INFO(priv, "RF reset rejected\n"); 1918c2ecf20Sopenharmony_ci rf_reset->reset_reject_count++; 1928c2ecf20Sopenharmony_ci return -EAGAIN; 1938c2ecf20Sopenharmony_ci } 1948c2ecf20Sopenharmony_ci rf_reset->reset_success_count++; 1958c2ecf20Sopenharmony_ci rf_reset->last_reset_jiffies = jiffies; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci /* 1988c2ecf20Sopenharmony_ci * There is no easy and better way to force reset the radio, 1998c2ecf20Sopenharmony_ci * the only known method is switching channel which will force to 2008c2ecf20Sopenharmony_ci * reset and tune the radio. 2018c2ecf20Sopenharmony_ci * Use internal short scan (single channel) operation to should 2028c2ecf20Sopenharmony_ci * achieve this objective. 2038c2ecf20Sopenharmony_ci * Driver should reset the radio when number of consecutive missed 2048c2ecf20Sopenharmony_ci * beacon, or any other uCode error condition detected. 2058c2ecf20Sopenharmony_ci */ 2068c2ecf20Sopenharmony_ci IWL_DEBUG_INFO(priv, "perform radio reset.\n"); 2078c2ecf20Sopenharmony_ci iwl_internal_short_hw_scan(priv); 2088c2ecf20Sopenharmony_ci return 0; 2098c2ecf20Sopenharmony_ci} 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_cistatic void iwlagn_recover_from_statistics(struct iwl_priv *priv, 2138c2ecf20Sopenharmony_ci struct statistics_rx_phy *cur_ofdm, 2148c2ecf20Sopenharmony_ci struct statistics_rx_ht_phy *cur_ofdm_ht, 2158c2ecf20Sopenharmony_ci struct statistics_tx *tx, 2168c2ecf20Sopenharmony_ci unsigned long stamp) 2178c2ecf20Sopenharmony_ci{ 2188c2ecf20Sopenharmony_ci unsigned int msecs; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 2218c2ecf20Sopenharmony_ci return; 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies); 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci /* Only gather statistics and update time stamp when not associated */ 2268c2ecf20Sopenharmony_ci if (!iwl_is_any_associated(priv)) 2278c2ecf20Sopenharmony_ci return; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci /* Do not check/recover when do not have enough statistics data */ 2308c2ecf20Sopenharmony_ci if (msecs < 99) 2318c2ecf20Sopenharmony_ci return; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci if (!iwlagn_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs)) 2348c2ecf20Sopenharmony_ci iwl_force_rf_reset(priv, false); 2358c2ecf20Sopenharmony_ci} 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci/* Calculate noise level, based on measurements during network silence just 2388c2ecf20Sopenharmony_ci * before arriving beacon. This measurement can be done only if we know 2398c2ecf20Sopenharmony_ci * exactly when to expect beacons, therefore only when we're associated. */ 2408c2ecf20Sopenharmony_cistatic void iwlagn_rx_calc_noise(struct iwl_priv *priv) 2418c2ecf20Sopenharmony_ci{ 2428c2ecf20Sopenharmony_ci struct statistics_rx_non_phy *rx_info; 2438c2ecf20Sopenharmony_ci int num_active_rx = 0; 2448c2ecf20Sopenharmony_ci int total_silence = 0; 2458c2ecf20Sopenharmony_ci int bcn_silence_a, bcn_silence_b, bcn_silence_c; 2468c2ecf20Sopenharmony_ci int last_rx_noise; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci rx_info = &priv->statistics.rx_non_phy; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci bcn_silence_a = 2518c2ecf20Sopenharmony_ci le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; 2528c2ecf20Sopenharmony_ci bcn_silence_b = 2538c2ecf20Sopenharmony_ci le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; 2548c2ecf20Sopenharmony_ci bcn_silence_c = 2558c2ecf20Sopenharmony_ci le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci if (bcn_silence_a) { 2588c2ecf20Sopenharmony_ci total_silence += bcn_silence_a; 2598c2ecf20Sopenharmony_ci num_active_rx++; 2608c2ecf20Sopenharmony_ci } 2618c2ecf20Sopenharmony_ci if (bcn_silence_b) { 2628c2ecf20Sopenharmony_ci total_silence += bcn_silence_b; 2638c2ecf20Sopenharmony_ci num_active_rx++; 2648c2ecf20Sopenharmony_ci } 2658c2ecf20Sopenharmony_ci if (bcn_silence_c) { 2668c2ecf20Sopenharmony_ci total_silence += bcn_silence_c; 2678c2ecf20Sopenharmony_ci num_active_rx++; 2688c2ecf20Sopenharmony_ci } 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci /* Average among active antennas */ 2718c2ecf20Sopenharmony_ci if (num_active_rx) 2728c2ecf20Sopenharmony_ci last_rx_noise = (total_silence / num_active_rx) - 107; 2738c2ecf20Sopenharmony_ci else 2748c2ecf20Sopenharmony_ci last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n", 2778c2ecf20Sopenharmony_ci bcn_silence_a, bcn_silence_b, bcn_silence_c, 2788c2ecf20Sopenharmony_ci last_rx_noise); 2798c2ecf20Sopenharmony_ci} 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUGFS 2828c2ecf20Sopenharmony_ci/* 2838c2ecf20Sopenharmony_ci * based on the assumption of all statistics counter are in DWORD 2848c2ecf20Sopenharmony_ci * FIXME: This function is for debugging, do not deal with 2858c2ecf20Sopenharmony_ci * the case of counters roll-over. 2868c2ecf20Sopenharmony_ci */ 2878c2ecf20Sopenharmony_cistatic void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta, 2888c2ecf20Sopenharmony_ci __le32 *max_delta, __le32 *accum, int size) 2898c2ecf20Sopenharmony_ci{ 2908c2ecf20Sopenharmony_ci int i; 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ci for (i = 0; 2938c2ecf20Sopenharmony_ci i < size / sizeof(__le32); 2948c2ecf20Sopenharmony_ci i++, prev++, cur++, delta++, max_delta++, accum++) { 2958c2ecf20Sopenharmony_ci if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) { 2968c2ecf20Sopenharmony_ci *delta = cpu_to_le32( 2978c2ecf20Sopenharmony_ci le32_to_cpu(*cur) - le32_to_cpu(*prev)); 2988c2ecf20Sopenharmony_ci le32_add_cpu(accum, le32_to_cpu(*delta)); 2998c2ecf20Sopenharmony_ci if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta)) 3008c2ecf20Sopenharmony_ci *max_delta = *delta; 3018c2ecf20Sopenharmony_ci } 3028c2ecf20Sopenharmony_ci } 3038c2ecf20Sopenharmony_ci} 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_cistatic void 3068c2ecf20Sopenharmony_ciiwlagn_accumulative_statistics(struct iwl_priv *priv, 3078c2ecf20Sopenharmony_ci struct statistics_general_common *common, 3088c2ecf20Sopenharmony_ci struct statistics_rx_non_phy *rx_non_phy, 3098c2ecf20Sopenharmony_ci struct statistics_rx_phy *rx_ofdm, 3108c2ecf20Sopenharmony_ci struct statistics_rx_ht_phy *rx_ofdm_ht, 3118c2ecf20Sopenharmony_ci struct statistics_rx_phy *rx_cck, 3128c2ecf20Sopenharmony_ci struct statistics_tx *tx, 3138c2ecf20Sopenharmony_ci struct statistics_bt_activity *bt_activity) 3148c2ecf20Sopenharmony_ci{ 3158c2ecf20Sopenharmony_ci#define ACCUM(_name) \ 3168c2ecf20Sopenharmony_ci accum_stats((__le32 *)&priv->statistics._name, \ 3178c2ecf20Sopenharmony_ci (__le32 *)_name, \ 3188c2ecf20Sopenharmony_ci (__le32 *)&priv->delta_stats._name, \ 3198c2ecf20Sopenharmony_ci (__le32 *)&priv->max_delta_stats._name, \ 3208c2ecf20Sopenharmony_ci (__le32 *)&priv->accum_stats._name, \ 3218c2ecf20Sopenharmony_ci sizeof(*_name)); 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci ACCUM(common); 3248c2ecf20Sopenharmony_ci ACCUM(rx_non_phy); 3258c2ecf20Sopenharmony_ci ACCUM(rx_ofdm); 3268c2ecf20Sopenharmony_ci ACCUM(rx_ofdm_ht); 3278c2ecf20Sopenharmony_ci ACCUM(rx_cck); 3288c2ecf20Sopenharmony_ci ACCUM(tx); 3298c2ecf20Sopenharmony_ci if (bt_activity) 3308c2ecf20Sopenharmony_ci ACCUM(bt_activity); 3318c2ecf20Sopenharmony_ci#undef ACCUM 3328c2ecf20Sopenharmony_ci} 3338c2ecf20Sopenharmony_ci#else 3348c2ecf20Sopenharmony_cistatic inline void 3358c2ecf20Sopenharmony_ciiwlagn_accumulative_statistics(struct iwl_priv *priv, 3368c2ecf20Sopenharmony_ci struct statistics_general_common *common, 3378c2ecf20Sopenharmony_ci struct statistics_rx_non_phy *rx_non_phy, 3388c2ecf20Sopenharmony_ci struct statistics_rx_phy *rx_ofdm, 3398c2ecf20Sopenharmony_ci struct statistics_rx_ht_phy *rx_ofdm_ht, 3408c2ecf20Sopenharmony_ci struct statistics_rx_phy *rx_cck, 3418c2ecf20Sopenharmony_ci struct statistics_tx *tx, 3428c2ecf20Sopenharmony_ci struct statistics_bt_activity *bt_activity) 3438c2ecf20Sopenharmony_ci{ 3448c2ecf20Sopenharmony_ci} 3458c2ecf20Sopenharmony_ci#endif 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_cistatic void iwlagn_rx_statistics(struct iwl_priv *priv, 3488c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 3498c2ecf20Sopenharmony_ci{ 3508c2ecf20Sopenharmony_ci unsigned long stamp = jiffies; 3518c2ecf20Sopenharmony_ci const int reg_recalib_period = 60; 3528c2ecf20Sopenharmony_ci int change; 3538c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 3548c2ecf20Sopenharmony_ci u32 len = iwl_rx_packet_payload_len(pkt); 3558c2ecf20Sopenharmony_ci __le32 *flag; 3568c2ecf20Sopenharmony_ci struct statistics_general_common *common; 3578c2ecf20Sopenharmony_ci struct statistics_rx_non_phy *rx_non_phy; 3588c2ecf20Sopenharmony_ci struct statistics_rx_phy *rx_ofdm; 3598c2ecf20Sopenharmony_ci struct statistics_rx_ht_phy *rx_ofdm_ht; 3608c2ecf20Sopenharmony_ci struct statistics_rx_phy *rx_cck; 3618c2ecf20Sopenharmony_ci struct statistics_tx *tx; 3628c2ecf20Sopenharmony_ci struct statistics_bt_activity *bt_activity; 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n", 3658c2ecf20Sopenharmony_ci len); 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci spin_lock(&priv->statistics.lock); 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci if (len == sizeof(struct iwl_bt_notif_statistics)) { 3708c2ecf20Sopenharmony_ci struct iwl_bt_notif_statistics *stats; 3718c2ecf20Sopenharmony_ci stats = (void *)&pkt->data; 3728c2ecf20Sopenharmony_ci flag = &stats->flag; 3738c2ecf20Sopenharmony_ci common = &stats->general.common; 3748c2ecf20Sopenharmony_ci rx_non_phy = &stats->rx.general.common; 3758c2ecf20Sopenharmony_ci rx_ofdm = &stats->rx.ofdm; 3768c2ecf20Sopenharmony_ci rx_ofdm_ht = &stats->rx.ofdm_ht; 3778c2ecf20Sopenharmony_ci rx_cck = &stats->rx.cck; 3788c2ecf20Sopenharmony_ci tx = &stats->tx; 3798c2ecf20Sopenharmony_ci bt_activity = &stats->general.activity; 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUGFS 3828c2ecf20Sopenharmony_ci /* handle this exception directly */ 3838c2ecf20Sopenharmony_ci priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills; 3848c2ecf20Sopenharmony_ci le32_add_cpu(&priv->statistics.accum_num_bt_kills, 3858c2ecf20Sopenharmony_ci le32_to_cpu(stats->rx.general.num_bt_kills)); 3868c2ecf20Sopenharmony_ci#endif 3878c2ecf20Sopenharmony_ci } else if (len == sizeof(struct iwl_notif_statistics)) { 3888c2ecf20Sopenharmony_ci struct iwl_notif_statistics *stats; 3898c2ecf20Sopenharmony_ci stats = (void *)&pkt->data; 3908c2ecf20Sopenharmony_ci flag = &stats->flag; 3918c2ecf20Sopenharmony_ci common = &stats->general.common; 3928c2ecf20Sopenharmony_ci rx_non_phy = &stats->rx.general; 3938c2ecf20Sopenharmony_ci rx_ofdm = &stats->rx.ofdm; 3948c2ecf20Sopenharmony_ci rx_ofdm_ht = &stats->rx.ofdm_ht; 3958c2ecf20Sopenharmony_ci rx_cck = &stats->rx.cck; 3968c2ecf20Sopenharmony_ci tx = &stats->tx; 3978c2ecf20Sopenharmony_ci bt_activity = NULL; 3988c2ecf20Sopenharmony_ci } else { 3998c2ecf20Sopenharmony_ci WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n", 4008c2ecf20Sopenharmony_ci len, sizeof(struct iwl_bt_notif_statistics), 4018c2ecf20Sopenharmony_ci sizeof(struct iwl_notif_statistics)); 4028c2ecf20Sopenharmony_ci spin_unlock(&priv->statistics.lock); 4038c2ecf20Sopenharmony_ci return; 4048c2ecf20Sopenharmony_ci } 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci change = common->temperature != priv->statistics.common.temperature || 4078c2ecf20Sopenharmony_ci (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) != 4088c2ecf20Sopenharmony_ci (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK); 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci iwlagn_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm, 4118c2ecf20Sopenharmony_ci rx_ofdm_ht, rx_cck, tx, bt_activity); 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci iwlagn_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp); 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci priv->statistics.flag = *flag; 4168c2ecf20Sopenharmony_ci memcpy(&priv->statistics.common, common, sizeof(*common)); 4178c2ecf20Sopenharmony_ci memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy)); 4188c2ecf20Sopenharmony_ci memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm)); 4198c2ecf20Sopenharmony_ci memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht)); 4208c2ecf20Sopenharmony_ci memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck)); 4218c2ecf20Sopenharmony_ci memcpy(&priv->statistics.tx, tx, sizeof(*tx)); 4228c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUGFS 4238c2ecf20Sopenharmony_ci if (bt_activity) 4248c2ecf20Sopenharmony_ci memcpy(&priv->statistics.bt_activity, bt_activity, 4258c2ecf20Sopenharmony_ci sizeof(*bt_activity)); 4268c2ecf20Sopenharmony_ci#endif 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci priv->rx_statistics_jiffies = stamp; 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci set_bit(STATUS_STATISTICS, &priv->status); 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci /* Reschedule the statistics timer to occur in 4338c2ecf20Sopenharmony_ci * reg_recalib_period seconds to ensure we get a 4348c2ecf20Sopenharmony_ci * thermal update even if the uCode doesn't give 4358c2ecf20Sopenharmony_ci * us one */ 4368c2ecf20Sopenharmony_ci mod_timer(&priv->statistics_periodic, jiffies + 4378c2ecf20Sopenharmony_ci msecs_to_jiffies(reg_recalib_period * 1000)); 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && 4408c2ecf20Sopenharmony_ci (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { 4418c2ecf20Sopenharmony_ci iwlagn_rx_calc_noise(priv); 4428c2ecf20Sopenharmony_ci queue_work(priv->workqueue, &priv->run_time_calib_work); 4438c2ecf20Sopenharmony_ci } 4448c2ecf20Sopenharmony_ci if (priv->lib->temperature && change) 4458c2ecf20Sopenharmony_ci priv->lib->temperature(priv); 4468c2ecf20Sopenharmony_ci 4478c2ecf20Sopenharmony_ci spin_unlock(&priv->statistics.lock); 4488c2ecf20Sopenharmony_ci} 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_cistatic void iwlagn_rx_reply_statistics(struct iwl_priv *priv, 4518c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 4528c2ecf20Sopenharmony_ci{ 4538c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 4548c2ecf20Sopenharmony_ci struct iwl_notif_statistics *stats = (void *)pkt->data; 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci if (le32_to_cpu(stats->flag) & UCODE_STATISTICS_CLEAR_MSK) { 4578c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUGFS 4588c2ecf20Sopenharmony_ci memset(&priv->accum_stats, 0, 4598c2ecf20Sopenharmony_ci sizeof(priv->accum_stats)); 4608c2ecf20Sopenharmony_ci memset(&priv->delta_stats, 0, 4618c2ecf20Sopenharmony_ci sizeof(priv->delta_stats)); 4628c2ecf20Sopenharmony_ci memset(&priv->max_delta_stats, 0, 4638c2ecf20Sopenharmony_ci sizeof(priv->max_delta_stats)); 4648c2ecf20Sopenharmony_ci#endif 4658c2ecf20Sopenharmony_ci IWL_DEBUG_RX(priv, "Statistics have been cleared\n"); 4668c2ecf20Sopenharmony_ci } 4678c2ecf20Sopenharmony_ci 4688c2ecf20Sopenharmony_ci iwlagn_rx_statistics(priv, rxb); 4698c2ecf20Sopenharmony_ci} 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_ci/* Handle notification from uCode that card's power state is changing 4728c2ecf20Sopenharmony_ci * due to software, hardware, or critical temperature RFKILL */ 4738c2ecf20Sopenharmony_cistatic void iwlagn_rx_card_state_notif(struct iwl_priv *priv, 4748c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 4758c2ecf20Sopenharmony_ci{ 4768c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 4778c2ecf20Sopenharmony_ci struct iwl_card_state_notif *card_state_notif = (void *)pkt->data; 4788c2ecf20Sopenharmony_ci u32 flags = le32_to_cpu(card_state_notif->flags); 4798c2ecf20Sopenharmony_ci unsigned long status = priv->status; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n", 4828c2ecf20Sopenharmony_ci (flags & HW_CARD_DISABLED) ? "Kill" : "On", 4838c2ecf20Sopenharmony_ci (flags & SW_CARD_DISABLED) ? "Kill" : "On", 4848c2ecf20Sopenharmony_ci (flags & CT_CARD_DISABLED) ? 4858c2ecf20Sopenharmony_ci "Reached" : "Not reached"); 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | 4888c2ecf20Sopenharmony_ci CT_CARD_DISABLED)) { 4898c2ecf20Sopenharmony_ci 4908c2ecf20Sopenharmony_ci iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, 4918c2ecf20Sopenharmony_ci CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C, 4948c2ecf20Sopenharmony_ci HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); 4958c2ecf20Sopenharmony_ci 4968c2ecf20Sopenharmony_ci if (!(flags & RXON_CARD_DISABLED)) { 4978c2ecf20Sopenharmony_ci iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, 4988c2ecf20Sopenharmony_ci CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); 4998c2ecf20Sopenharmony_ci iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C, 5008c2ecf20Sopenharmony_ci HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); 5018c2ecf20Sopenharmony_ci } 5028c2ecf20Sopenharmony_ci if (flags & CT_CARD_DISABLED) 5038c2ecf20Sopenharmony_ci iwl_tt_enter_ct_kill(priv); 5048c2ecf20Sopenharmony_ci } 5058c2ecf20Sopenharmony_ci if (!(flags & CT_CARD_DISABLED)) 5068c2ecf20Sopenharmony_ci iwl_tt_exit_ct_kill(priv); 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_ci if (flags & HW_CARD_DISABLED) 5098c2ecf20Sopenharmony_ci set_bit(STATUS_RF_KILL_HW, &priv->status); 5108c2ecf20Sopenharmony_ci else 5118c2ecf20Sopenharmony_ci clear_bit(STATUS_RF_KILL_HW, &priv->status); 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci if (!(flags & RXON_CARD_DISABLED)) 5158c2ecf20Sopenharmony_ci iwl_scan_cancel(priv); 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_ci if ((test_bit(STATUS_RF_KILL_HW, &status) != 5188c2ecf20Sopenharmony_ci test_bit(STATUS_RF_KILL_HW, &priv->status))) 5198c2ecf20Sopenharmony_ci wiphy_rfkill_set_hw_state(priv->hw->wiphy, 5208c2ecf20Sopenharmony_ci test_bit(STATUS_RF_KILL_HW, &priv->status)); 5218c2ecf20Sopenharmony_ci} 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_cistatic void iwlagn_rx_missed_beacon_notif(struct iwl_priv *priv, 5248c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_ci{ 5278c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 5288c2ecf20Sopenharmony_ci struct iwl_missed_beacon_notif *missed_beacon = (void *)pkt->data; 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) > 5318c2ecf20Sopenharmony_ci priv->missed_beacon_threshold) { 5328c2ecf20Sopenharmony_ci IWL_DEBUG_CALIB(priv, 5338c2ecf20Sopenharmony_ci "missed bcn cnsq %d totl %d rcd %d expctd %d\n", 5348c2ecf20Sopenharmony_ci le32_to_cpu(missed_beacon->consecutive_missed_beacons), 5358c2ecf20Sopenharmony_ci le32_to_cpu(missed_beacon->total_missed_becons), 5368c2ecf20Sopenharmony_ci le32_to_cpu(missed_beacon->num_recvd_beacons), 5378c2ecf20Sopenharmony_ci le32_to_cpu(missed_beacon->num_expected_beacons)); 5388c2ecf20Sopenharmony_ci if (!test_bit(STATUS_SCANNING, &priv->status)) 5398c2ecf20Sopenharmony_ci iwl_init_sensitivity(priv); 5408c2ecf20Sopenharmony_ci } 5418c2ecf20Sopenharmony_ci} 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ci/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD). 5448c2ecf20Sopenharmony_ci * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */ 5458c2ecf20Sopenharmony_cistatic void iwlagn_rx_reply_rx_phy(struct iwl_priv *priv, 5468c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 5478c2ecf20Sopenharmony_ci{ 5488c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci priv->last_phy_res_valid = true; 5518c2ecf20Sopenharmony_ci priv->ampdu_ref++; 5528c2ecf20Sopenharmony_ci memcpy(&priv->last_phy_res, pkt->data, 5538c2ecf20Sopenharmony_ci sizeof(struct iwl_rx_phy_res)); 5548c2ecf20Sopenharmony_ci} 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci/* 5578c2ecf20Sopenharmony_ci * returns non-zero if packet should be dropped 5588c2ecf20Sopenharmony_ci */ 5598c2ecf20Sopenharmony_cistatic int iwlagn_set_decrypted_flag(struct iwl_priv *priv, 5608c2ecf20Sopenharmony_ci struct ieee80211_hdr *hdr, 5618c2ecf20Sopenharmony_ci u32 decrypt_res, 5628c2ecf20Sopenharmony_ci struct ieee80211_rx_status *stats) 5638c2ecf20Sopenharmony_ci{ 5648c2ecf20Sopenharmony_ci u16 fc = le16_to_cpu(hdr->frame_control); 5658c2ecf20Sopenharmony_ci 5668c2ecf20Sopenharmony_ci /* 5678c2ecf20Sopenharmony_ci * All contexts have the same setting here due to it being 5688c2ecf20Sopenharmony_ci * a module parameter, so OK to check any context. 5698c2ecf20Sopenharmony_ci */ 5708c2ecf20Sopenharmony_ci if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags & 5718c2ecf20Sopenharmony_ci RXON_FILTER_DIS_DECRYPT_MSK) 5728c2ecf20Sopenharmony_ci return 0; 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci if (!(fc & IEEE80211_FCTL_PROTECTED)) 5758c2ecf20Sopenharmony_ci return 0; 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res); 5788c2ecf20Sopenharmony_ci switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { 5798c2ecf20Sopenharmony_ci case RX_RES_STATUS_SEC_TYPE_TKIP: 5808c2ecf20Sopenharmony_ci /* The uCode has got a bad phase 1 Key, pushes the packet. 5818c2ecf20Sopenharmony_ci * Decryption will be done in SW. */ 5828c2ecf20Sopenharmony_ci if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == 5838c2ecf20Sopenharmony_ci RX_RES_STATUS_BAD_KEY_TTAK) 5848c2ecf20Sopenharmony_ci break; 5858c2ecf20Sopenharmony_ci /* fall through */ 5868c2ecf20Sopenharmony_ci case RX_RES_STATUS_SEC_TYPE_WEP: 5878c2ecf20Sopenharmony_ci if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == 5888c2ecf20Sopenharmony_ci RX_RES_STATUS_BAD_ICV_MIC) { 5898c2ecf20Sopenharmony_ci /* bad ICV, the packet is destroyed since the 5908c2ecf20Sopenharmony_ci * decryption is inplace, drop it */ 5918c2ecf20Sopenharmony_ci IWL_DEBUG_RX(priv, "Packet destroyed\n"); 5928c2ecf20Sopenharmony_ci return -1; 5938c2ecf20Sopenharmony_ci } 5948c2ecf20Sopenharmony_ci /* fall through */ 5958c2ecf20Sopenharmony_ci case RX_RES_STATUS_SEC_TYPE_CCMP: 5968c2ecf20Sopenharmony_ci if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == 5978c2ecf20Sopenharmony_ci RX_RES_STATUS_DECRYPT_OK) { 5988c2ecf20Sopenharmony_ci IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n"); 5998c2ecf20Sopenharmony_ci stats->flag |= RX_FLAG_DECRYPTED; 6008c2ecf20Sopenharmony_ci } 6018c2ecf20Sopenharmony_ci break; 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci default: 6048c2ecf20Sopenharmony_ci break; 6058c2ecf20Sopenharmony_ci } 6068c2ecf20Sopenharmony_ci return 0; 6078c2ecf20Sopenharmony_ci} 6088c2ecf20Sopenharmony_ci 6098c2ecf20Sopenharmony_cistatic void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv, 6108c2ecf20Sopenharmony_ci struct ieee80211_hdr *hdr, 6118c2ecf20Sopenharmony_ci u16 len, 6128c2ecf20Sopenharmony_ci u32 ampdu_status, 6138c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb, 6148c2ecf20Sopenharmony_ci struct ieee80211_rx_status *stats) 6158c2ecf20Sopenharmony_ci{ 6168c2ecf20Sopenharmony_ci struct sk_buff *skb; 6178c2ecf20Sopenharmony_ci __le16 fc = hdr->frame_control; 6188c2ecf20Sopenharmony_ci struct iwl_rxon_context *ctx; 6198c2ecf20Sopenharmony_ci unsigned int hdrlen, fraglen; 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci /* We only process data packets if the interface is open */ 6228c2ecf20Sopenharmony_ci if (unlikely(!priv->is_open)) { 6238c2ecf20Sopenharmony_ci IWL_DEBUG_DROP_LIMIT(priv, 6248c2ecf20Sopenharmony_ci "Dropping packet while interface is not open.\n"); 6258c2ecf20Sopenharmony_ci return; 6268c2ecf20Sopenharmony_ci } 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci /* In case of HW accelerated crypto and bad decryption, drop */ 6298c2ecf20Sopenharmony_ci if (!iwlwifi_mod_params.swcrypto && 6308c2ecf20Sopenharmony_ci iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats)) 6318c2ecf20Sopenharmony_ci return; 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci /* Dont use dev_alloc_skb(), we'll have enough headroom once 6348c2ecf20Sopenharmony_ci * ieee80211_hdr pulled. 6358c2ecf20Sopenharmony_ci */ 6368c2ecf20Sopenharmony_ci skb = alloc_skb(128, GFP_ATOMIC); 6378c2ecf20Sopenharmony_ci if (!skb) { 6388c2ecf20Sopenharmony_ci IWL_ERR(priv, "alloc_skb failed\n"); 6398c2ecf20Sopenharmony_ci return; 6408c2ecf20Sopenharmony_ci } 6418c2ecf20Sopenharmony_ci /* If frame is small enough to fit in skb->head, pull it completely. 6428c2ecf20Sopenharmony_ci * If not, only pull ieee80211_hdr so that splice() or TCP coalesce 6438c2ecf20Sopenharmony_ci * are more efficient. 6448c2ecf20Sopenharmony_ci */ 6458c2ecf20Sopenharmony_ci hdrlen = (len <= skb_tailroom(skb)) ? len : sizeof(*hdr); 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci skb_put_data(skb, hdr, hdrlen); 6488c2ecf20Sopenharmony_ci fraglen = len - hdrlen; 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci if (fraglen) { 6518c2ecf20Sopenharmony_ci int offset = (void *)hdr + hdrlen - 6528c2ecf20Sopenharmony_ci rxb_addr(rxb) + rxb_offset(rxb); 6538c2ecf20Sopenharmony_ci 6548c2ecf20Sopenharmony_ci skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset, 6558c2ecf20Sopenharmony_ci fraglen, rxb->truesize); 6568c2ecf20Sopenharmony_ci } 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci /* 6598c2ecf20Sopenharmony_ci * Wake any queues that were stopped due to a passive channel tx 6608c2ecf20Sopenharmony_ci * failure. This can happen because the regulatory enforcement in 6618c2ecf20Sopenharmony_ci * the device waits for a beacon before allowing transmission, 6628c2ecf20Sopenharmony_ci * sometimes even after already having transmitted frames for the 6638c2ecf20Sopenharmony_ci * association because the new RXON may reset the information. 6648c2ecf20Sopenharmony_ci */ 6658c2ecf20Sopenharmony_ci if (unlikely(ieee80211_is_beacon(fc) && priv->passive_no_rx)) { 6668c2ecf20Sopenharmony_ci for_each_context(priv, ctx) { 6678c2ecf20Sopenharmony_ci if (!ether_addr_equal(hdr->addr3, 6688c2ecf20Sopenharmony_ci ctx->active.bssid_addr)) 6698c2ecf20Sopenharmony_ci continue; 6708c2ecf20Sopenharmony_ci iwlagn_lift_passive_no_rx(priv); 6718c2ecf20Sopenharmony_ci } 6728c2ecf20Sopenharmony_ci } 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats)); 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci ieee80211_rx_napi(priv->hw, NULL, skb, priv->napi); 6778c2ecf20Sopenharmony_ci} 6788c2ecf20Sopenharmony_ci 6798c2ecf20Sopenharmony_cistatic u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in) 6808c2ecf20Sopenharmony_ci{ 6818c2ecf20Sopenharmony_ci u32 decrypt_out = 0; 6828c2ecf20Sopenharmony_ci 6838c2ecf20Sopenharmony_ci if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) == 6848c2ecf20Sopenharmony_ci RX_RES_STATUS_STATION_FOUND) 6858c2ecf20Sopenharmony_ci decrypt_out |= (RX_RES_STATUS_STATION_FOUND | 6868c2ecf20Sopenharmony_ci RX_RES_STATUS_NO_STATION_INFO_MISMATCH); 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK); 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ci /* packet was not encrypted */ 6918c2ecf20Sopenharmony_ci if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == 6928c2ecf20Sopenharmony_ci RX_RES_STATUS_SEC_TYPE_NONE) 6938c2ecf20Sopenharmony_ci return decrypt_out; 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci /* packet was encrypted with unknown alg */ 6968c2ecf20Sopenharmony_ci if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == 6978c2ecf20Sopenharmony_ci RX_RES_STATUS_SEC_TYPE_ERR) 6988c2ecf20Sopenharmony_ci return decrypt_out; 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci /* decryption was not done in HW */ 7018c2ecf20Sopenharmony_ci if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) != 7028c2ecf20Sopenharmony_ci RX_MPDU_RES_STATUS_DEC_DONE_MSK) 7038c2ecf20Sopenharmony_ci return decrypt_out; 7048c2ecf20Sopenharmony_ci 7058c2ecf20Sopenharmony_ci switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) { 7068c2ecf20Sopenharmony_ci 7078c2ecf20Sopenharmony_ci case RX_RES_STATUS_SEC_TYPE_CCMP: 7088c2ecf20Sopenharmony_ci /* alg is CCM: check MIC only */ 7098c2ecf20Sopenharmony_ci if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK)) 7108c2ecf20Sopenharmony_ci /* Bad MIC */ 7118c2ecf20Sopenharmony_ci decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; 7128c2ecf20Sopenharmony_ci else 7138c2ecf20Sopenharmony_ci decrypt_out |= RX_RES_STATUS_DECRYPT_OK; 7148c2ecf20Sopenharmony_ci 7158c2ecf20Sopenharmony_ci break; 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci case RX_RES_STATUS_SEC_TYPE_TKIP: 7188c2ecf20Sopenharmony_ci if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) { 7198c2ecf20Sopenharmony_ci /* Bad TTAK */ 7208c2ecf20Sopenharmony_ci decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK; 7218c2ecf20Sopenharmony_ci break; 7228c2ecf20Sopenharmony_ci } 7238c2ecf20Sopenharmony_ci /* fall through */ 7248c2ecf20Sopenharmony_ci default: 7258c2ecf20Sopenharmony_ci if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK)) 7268c2ecf20Sopenharmony_ci decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; 7278c2ecf20Sopenharmony_ci else 7288c2ecf20Sopenharmony_ci decrypt_out |= RX_RES_STATUS_DECRYPT_OK; 7298c2ecf20Sopenharmony_ci break; 7308c2ecf20Sopenharmony_ci } 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n", 7338c2ecf20Sopenharmony_ci decrypt_in, decrypt_out); 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci return decrypt_out; 7368c2ecf20Sopenharmony_ci} 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci/* Calc max signal level (dBm) among 3 possible receivers */ 7398c2ecf20Sopenharmony_cistatic int iwlagn_calc_rssi(struct iwl_priv *priv, 7408c2ecf20Sopenharmony_ci struct iwl_rx_phy_res *rx_resp) 7418c2ecf20Sopenharmony_ci{ 7428c2ecf20Sopenharmony_ci /* data from PHY/DSP regarding signal strength, etc., 7438c2ecf20Sopenharmony_ci * contents are always there, not configurable by host 7448c2ecf20Sopenharmony_ci */ 7458c2ecf20Sopenharmony_ci struct iwlagn_non_cfg_phy *ncphy = 7468c2ecf20Sopenharmony_ci (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf; 7478c2ecf20Sopenharmony_ci u32 val, rssi_a, rssi_b, rssi_c, max_rssi; 7488c2ecf20Sopenharmony_ci u8 agc; 7498c2ecf20Sopenharmony_ci 7508c2ecf20Sopenharmony_ci val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]); 7518c2ecf20Sopenharmony_ci agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS; 7528c2ecf20Sopenharmony_ci 7538c2ecf20Sopenharmony_ci /* Find max rssi among 3 possible receivers. 7548c2ecf20Sopenharmony_ci * These values are measured by the digital signal processor (DSP). 7558c2ecf20Sopenharmony_ci * They should stay fairly constant even as the signal strength varies, 7568c2ecf20Sopenharmony_ci * if the radio's automatic gain control (AGC) is working right. 7578c2ecf20Sopenharmony_ci * AGC value (see below) will provide the "interesting" info. 7588c2ecf20Sopenharmony_ci */ 7598c2ecf20Sopenharmony_ci val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]); 7608c2ecf20Sopenharmony_ci rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >> 7618c2ecf20Sopenharmony_ci IWLAGN_OFDM_RSSI_A_BIT_POS; 7628c2ecf20Sopenharmony_ci rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >> 7638c2ecf20Sopenharmony_ci IWLAGN_OFDM_RSSI_B_BIT_POS; 7648c2ecf20Sopenharmony_ci val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]); 7658c2ecf20Sopenharmony_ci rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >> 7668c2ecf20Sopenharmony_ci IWLAGN_OFDM_RSSI_C_BIT_POS; 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci max_rssi = max_t(u32, rssi_a, rssi_b); 7698c2ecf20Sopenharmony_ci max_rssi = max_t(u32, max_rssi, rssi_c); 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n", 7728c2ecf20Sopenharmony_ci rssi_a, rssi_b, rssi_c, max_rssi, agc); 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_ci /* dBm = max_rssi dB - agc dB - constant. 7758c2ecf20Sopenharmony_ci * Higher AGC (higher radio gain) means lower signal. */ 7768c2ecf20Sopenharmony_ci return max_rssi - agc - IWLAGN_RSSI_OFFSET; 7778c2ecf20Sopenharmony_ci} 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci/* Called for REPLY_RX_MPDU_CMD */ 7808c2ecf20Sopenharmony_cistatic void iwlagn_rx_reply_rx(struct iwl_priv *priv, 7818c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 7828c2ecf20Sopenharmony_ci{ 7838c2ecf20Sopenharmony_ci struct ieee80211_hdr *header; 7848c2ecf20Sopenharmony_ci struct ieee80211_rx_status rx_status = {}; 7858c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 7868c2ecf20Sopenharmony_ci struct iwl_rx_phy_res *phy_res; 7878c2ecf20Sopenharmony_ci __le32 rx_pkt_status; 7888c2ecf20Sopenharmony_ci struct iwl_rx_mpdu_res_start *amsdu; 7898c2ecf20Sopenharmony_ci u32 len; 7908c2ecf20Sopenharmony_ci u32 ampdu_status; 7918c2ecf20Sopenharmony_ci u32 rate_n_flags; 7928c2ecf20Sopenharmony_ci 7938c2ecf20Sopenharmony_ci if (!priv->last_phy_res_valid) { 7948c2ecf20Sopenharmony_ci IWL_ERR(priv, "MPDU frame without cached PHY data\n"); 7958c2ecf20Sopenharmony_ci return; 7968c2ecf20Sopenharmony_ci } 7978c2ecf20Sopenharmony_ci phy_res = &priv->last_phy_res; 7988c2ecf20Sopenharmony_ci amsdu = (struct iwl_rx_mpdu_res_start *)pkt->data; 7998c2ecf20Sopenharmony_ci header = (struct ieee80211_hdr *)(pkt->data + sizeof(*amsdu)); 8008c2ecf20Sopenharmony_ci len = le16_to_cpu(amsdu->byte_count); 8018c2ecf20Sopenharmony_ci rx_pkt_status = *(__le32 *)(pkt->data + sizeof(*amsdu) + len); 8028c2ecf20Sopenharmony_ci ampdu_status = iwlagn_translate_rx_status(priv, 8038c2ecf20Sopenharmony_ci le32_to_cpu(rx_pkt_status)); 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci if ((unlikely(phy_res->cfg_phy_cnt > 20))) { 8068c2ecf20Sopenharmony_ci IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d\n", 8078c2ecf20Sopenharmony_ci phy_res->cfg_phy_cnt); 8088c2ecf20Sopenharmony_ci return; 8098c2ecf20Sopenharmony_ci } 8108c2ecf20Sopenharmony_ci 8118c2ecf20Sopenharmony_ci if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) || 8128c2ecf20Sopenharmony_ci !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) { 8138c2ecf20Sopenharmony_ci IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n", 8148c2ecf20Sopenharmony_ci le32_to_cpu(rx_pkt_status)); 8158c2ecf20Sopenharmony_ci return; 8168c2ecf20Sopenharmony_ci } 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci /* This will be used in several places later */ 8198c2ecf20Sopenharmony_ci rate_n_flags = le32_to_cpu(phy_res->rate_n_flags); 8208c2ecf20Sopenharmony_ci 8218c2ecf20Sopenharmony_ci /* rx_status carries information about the packet to mac80211 */ 8228c2ecf20Sopenharmony_ci rx_status.mactime = le64_to_cpu(phy_res->timestamp); 8238c2ecf20Sopenharmony_ci rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? 8248c2ecf20Sopenharmony_ci NL80211_BAND_2GHZ : NL80211_BAND_5GHZ; 8258c2ecf20Sopenharmony_ci rx_status.freq = 8268c2ecf20Sopenharmony_ci ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel), 8278c2ecf20Sopenharmony_ci rx_status.band); 8288c2ecf20Sopenharmony_ci rx_status.rate_idx = 8298c2ecf20Sopenharmony_ci iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band); 8308c2ecf20Sopenharmony_ci rx_status.flag = 0; 8318c2ecf20Sopenharmony_ci 8328c2ecf20Sopenharmony_ci /* TSF isn't reliable. In order to allow smooth user experience, 8338c2ecf20Sopenharmony_ci * this W/A doesn't propagate it to the mac80211 */ 8348c2ecf20Sopenharmony_ci /*rx_status.flag |= RX_FLAG_MACTIME_START;*/ 8358c2ecf20Sopenharmony_ci 8368c2ecf20Sopenharmony_ci priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp); 8378c2ecf20Sopenharmony_ci 8388c2ecf20Sopenharmony_ci /* Find max signal strength (dBm) among 3 antenna/receiver chains */ 8398c2ecf20Sopenharmony_ci rx_status.signal = iwlagn_calc_rssi(priv, phy_res); 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_ci IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n", 8428c2ecf20Sopenharmony_ci rx_status.signal, (unsigned long long)rx_status.mactime); 8438c2ecf20Sopenharmony_ci 8448c2ecf20Sopenharmony_ci /* 8458c2ecf20Sopenharmony_ci * "antenna number" 8468c2ecf20Sopenharmony_ci * 8478c2ecf20Sopenharmony_ci * It seems that the antenna field in the phy flags value 8488c2ecf20Sopenharmony_ci * is actually a bit field. This is undefined by radiotap, 8498c2ecf20Sopenharmony_ci * it wants an actual antenna number but I always get "7" 8508c2ecf20Sopenharmony_ci * for most legacy frames I receive indicating that the 8518c2ecf20Sopenharmony_ci * same frame was received on all three RX chains. 8528c2ecf20Sopenharmony_ci * 8538c2ecf20Sopenharmony_ci * I think this field should be removed in favor of a 8548c2ecf20Sopenharmony_ci * new 802.11n radiotap field "RX chains" that is defined 8558c2ecf20Sopenharmony_ci * as a bitmask. 8568c2ecf20Sopenharmony_ci */ 8578c2ecf20Sopenharmony_ci rx_status.antenna = 8588c2ecf20Sopenharmony_ci (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK) 8598c2ecf20Sopenharmony_ci >> RX_RES_PHY_FLAGS_ANTENNA_POS; 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci /* set the preamble flag if appropriate */ 8628c2ecf20Sopenharmony_ci if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) 8638c2ecf20Sopenharmony_ci rx_status.enc_flags |= RX_ENC_FLAG_SHORTPRE; 8648c2ecf20Sopenharmony_ci 8658c2ecf20Sopenharmony_ci if (phy_res->phy_flags & RX_RES_PHY_FLAGS_AGG_MSK) { 8668c2ecf20Sopenharmony_ci /* 8678c2ecf20Sopenharmony_ci * We know which subframes of an A-MPDU belong 8688c2ecf20Sopenharmony_ci * together since we get a single PHY response 8698c2ecf20Sopenharmony_ci * from the firmware for all of them 8708c2ecf20Sopenharmony_ci */ 8718c2ecf20Sopenharmony_ci rx_status.flag |= RX_FLAG_AMPDU_DETAILS; 8728c2ecf20Sopenharmony_ci rx_status.ampdu_reference = priv->ampdu_ref; 8738c2ecf20Sopenharmony_ci } 8748c2ecf20Sopenharmony_ci 8758c2ecf20Sopenharmony_ci /* Set up the HT phy flags */ 8768c2ecf20Sopenharmony_ci if (rate_n_flags & RATE_MCS_HT_MSK) 8778c2ecf20Sopenharmony_ci rx_status.encoding = RX_ENC_HT; 8788c2ecf20Sopenharmony_ci if (rate_n_flags & RATE_MCS_HT40_MSK) 8798c2ecf20Sopenharmony_ci rx_status.bw = RATE_INFO_BW_40; 8808c2ecf20Sopenharmony_ci else 8818c2ecf20Sopenharmony_ci rx_status.bw = RATE_INFO_BW_20; 8828c2ecf20Sopenharmony_ci if (rate_n_flags & RATE_MCS_SGI_MSK) 8838c2ecf20Sopenharmony_ci rx_status.enc_flags |= RX_ENC_FLAG_SHORT_GI; 8848c2ecf20Sopenharmony_ci if (rate_n_flags & RATE_MCS_GF_MSK) 8858c2ecf20Sopenharmony_ci rx_status.enc_flags |= RX_ENC_FLAG_HT_GF; 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status, 8888c2ecf20Sopenharmony_ci rxb, &rx_status); 8898c2ecf20Sopenharmony_ci} 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_cistatic void iwlagn_rx_noa_notification(struct iwl_priv *priv, 8928c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 8938c2ecf20Sopenharmony_ci{ 8948c2ecf20Sopenharmony_ci struct iwl_wipan_noa_data *new_data, *old_data; 8958c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 8968c2ecf20Sopenharmony_ci struct iwl_wipan_noa_notification *noa_notif = (void *)pkt->data; 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_ci /* no condition -- we're in softirq */ 8998c2ecf20Sopenharmony_ci old_data = rcu_dereference_protected(priv->noa_data, true); 9008c2ecf20Sopenharmony_ci 9018c2ecf20Sopenharmony_ci if (noa_notif->noa_active) { 9028c2ecf20Sopenharmony_ci u32 len = le16_to_cpu(noa_notif->noa_attribute.length); 9038c2ecf20Sopenharmony_ci u32 copylen = len; 9048c2ecf20Sopenharmony_ci 9058c2ecf20Sopenharmony_ci /* EID, len, OUI, subtype */ 9068c2ecf20Sopenharmony_ci len += 1 + 1 + 3 + 1; 9078c2ecf20Sopenharmony_ci /* P2P id, P2P length */ 9088c2ecf20Sopenharmony_ci len += 1 + 2; 9098c2ecf20Sopenharmony_ci copylen += 1 + 2; 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_ci new_data = kmalloc(sizeof(*new_data) + len, GFP_ATOMIC); 9128c2ecf20Sopenharmony_ci if (new_data) { 9138c2ecf20Sopenharmony_ci new_data->length = len; 9148c2ecf20Sopenharmony_ci new_data->data[0] = WLAN_EID_VENDOR_SPECIFIC; 9158c2ecf20Sopenharmony_ci new_data->data[1] = len - 2; /* not counting EID, len */ 9168c2ecf20Sopenharmony_ci new_data->data[2] = (WLAN_OUI_WFA >> 16) & 0xff; 9178c2ecf20Sopenharmony_ci new_data->data[3] = (WLAN_OUI_WFA >> 8) & 0xff; 9188c2ecf20Sopenharmony_ci new_data->data[4] = (WLAN_OUI_WFA >> 0) & 0xff; 9198c2ecf20Sopenharmony_ci new_data->data[5] = WLAN_OUI_TYPE_WFA_P2P; 9208c2ecf20Sopenharmony_ci memcpy(&new_data->data[6], &noa_notif->noa_attribute, 9218c2ecf20Sopenharmony_ci copylen); 9228c2ecf20Sopenharmony_ci } 9238c2ecf20Sopenharmony_ci } else 9248c2ecf20Sopenharmony_ci new_data = NULL; 9258c2ecf20Sopenharmony_ci 9268c2ecf20Sopenharmony_ci rcu_assign_pointer(priv->noa_data, new_data); 9278c2ecf20Sopenharmony_ci 9288c2ecf20Sopenharmony_ci if (old_data) 9298c2ecf20Sopenharmony_ci kfree_rcu(old_data, rcu_head); 9308c2ecf20Sopenharmony_ci} 9318c2ecf20Sopenharmony_ci 9328c2ecf20Sopenharmony_ci/* 9338c2ecf20Sopenharmony_ci * iwl_setup_rx_handlers - Initialize Rx handler callbacks 9348c2ecf20Sopenharmony_ci * 9358c2ecf20Sopenharmony_ci * Setup the RX handlers for each of the reply types sent from the uCode 9368c2ecf20Sopenharmony_ci * to the host. 9378c2ecf20Sopenharmony_ci */ 9388c2ecf20Sopenharmony_civoid iwl_setup_rx_handlers(struct iwl_priv *priv) 9398c2ecf20Sopenharmony_ci{ 9408c2ecf20Sopenharmony_ci void (**handlers)(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb); 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_ci handlers = priv->rx_handlers; 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci handlers[REPLY_ERROR] = iwlagn_rx_reply_error; 9458c2ecf20Sopenharmony_ci handlers[CHANNEL_SWITCH_NOTIFICATION] = iwlagn_rx_csa; 9468c2ecf20Sopenharmony_ci handlers[SPECTRUM_MEASURE_NOTIFICATION] = 9478c2ecf20Sopenharmony_ci iwlagn_rx_spectrum_measure_notif; 9488c2ecf20Sopenharmony_ci handlers[PM_SLEEP_NOTIFICATION] = iwlagn_rx_pm_sleep_notif; 9498c2ecf20Sopenharmony_ci handlers[PM_DEBUG_STATISTIC_NOTIFIC] = 9508c2ecf20Sopenharmony_ci iwlagn_rx_pm_debug_statistics_notif; 9518c2ecf20Sopenharmony_ci handlers[BEACON_NOTIFICATION] = iwlagn_rx_beacon_notif; 9528c2ecf20Sopenharmony_ci handlers[REPLY_ADD_STA] = iwl_add_sta_callback; 9538c2ecf20Sopenharmony_ci 9548c2ecf20Sopenharmony_ci handlers[REPLY_WIPAN_NOA_NOTIFICATION] = iwlagn_rx_noa_notification; 9558c2ecf20Sopenharmony_ci 9568c2ecf20Sopenharmony_ci /* 9578c2ecf20Sopenharmony_ci * The same handler is used for both the REPLY to a discrete 9588c2ecf20Sopenharmony_ci * statistics request from the host as well as for the periodic 9598c2ecf20Sopenharmony_ci * statistics notifications (after received beacons) from the uCode. 9608c2ecf20Sopenharmony_ci */ 9618c2ecf20Sopenharmony_ci handlers[REPLY_STATISTICS_CMD] = iwlagn_rx_reply_statistics; 9628c2ecf20Sopenharmony_ci handlers[STATISTICS_NOTIFICATION] = iwlagn_rx_statistics; 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ci iwl_setup_rx_scan_handlers(priv); 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci handlers[CARD_STATE_NOTIFICATION] = iwlagn_rx_card_state_notif; 9678c2ecf20Sopenharmony_ci handlers[MISSED_BEACONS_NOTIFICATION] = 9688c2ecf20Sopenharmony_ci iwlagn_rx_missed_beacon_notif; 9698c2ecf20Sopenharmony_ci 9708c2ecf20Sopenharmony_ci /* Rx handlers */ 9718c2ecf20Sopenharmony_ci handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy; 9728c2ecf20Sopenharmony_ci handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx; 9738c2ecf20Sopenharmony_ci 9748c2ecf20Sopenharmony_ci /* block ack */ 9758c2ecf20Sopenharmony_ci handlers[REPLY_COMPRESSED_BA] = 9768c2ecf20Sopenharmony_ci iwlagn_rx_reply_compressed_ba; 9778c2ecf20Sopenharmony_ci 9788c2ecf20Sopenharmony_ci priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx; 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_ci /* set up notification wait support */ 9818c2ecf20Sopenharmony_ci iwl_notification_wait_init(&priv->notif_wait); 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci /* Set up BT Rx handlers */ 9848c2ecf20Sopenharmony_ci if (priv->lib->bt_params) 9858c2ecf20Sopenharmony_ci iwlagn_bt_rx_handler_setup(priv); 9868c2ecf20Sopenharmony_ci} 9878c2ecf20Sopenharmony_ci 9888c2ecf20Sopenharmony_civoid iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct napi_struct *napi, 9898c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 9908c2ecf20Sopenharmony_ci{ 9918c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 9928c2ecf20Sopenharmony_ci struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); 9938c2ecf20Sopenharmony_ci 9948c2ecf20Sopenharmony_ci /* 9958c2ecf20Sopenharmony_ci * Do the notification wait before RX handlers so 9968c2ecf20Sopenharmony_ci * even if the RX handler consumes the RXB we have 9978c2ecf20Sopenharmony_ci * access to it in the notification wait entry. 9988c2ecf20Sopenharmony_ci */ 9998c2ecf20Sopenharmony_ci iwl_notification_wait_notify(&priv->notif_wait, pkt); 10008c2ecf20Sopenharmony_ci 10018c2ecf20Sopenharmony_ci /* Based on type of command response or notification, 10028c2ecf20Sopenharmony_ci * handle those that need handling via function in 10038c2ecf20Sopenharmony_ci * rx_handlers table. See iwl_setup_rx_handlers() */ 10048c2ecf20Sopenharmony_ci if (priv->rx_handlers[pkt->hdr.cmd]) { 10058c2ecf20Sopenharmony_ci priv->rx_handlers_stats[pkt->hdr.cmd]++; 10068c2ecf20Sopenharmony_ci priv->rx_handlers[pkt->hdr.cmd](priv, rxb); 10078c2ecf20Sopenharmony_ci } else { 10088c2ecf20Sopenharmony_ci /* No handling needed */ 10098c2ecf20Sopenharmony_ci IWL_DEBUG_RX(priv, "No handler needed for %s, 0x%02x\n", 10108c2ecf20Sopenharmony_ci iwl_get_cmd_string(priv->trans, 10118c2ecf20Sopenharmony_ci iwl_cmd_id(pkt->hdr.cmd, 10128c2ecf20Sopenharmony_ci 0, 0)), 10138c2ecf20Sopenharmony_ci pkt->hdr.cmd); 10148c2ecf20Sopenharmony_ci } 10158c2ecf20Sopenharmony_ci} 1016