From d1af787dc992741bffa1a1ce0b4ca7eacb1f7227 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 12 Jul 2013 08:19:04 +0000 Subject: mac80211: backport latest version from trunk (as of r37265) Signed-off-by: Felix Fietkau git-svn-id: svn://svn.openwrt.org/openwrt/branches/attitude_adjustment@37266 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/mac80211/patches/300-pending_work.patch | 2002 ++++++----------------- 1 file changed, 508 insertions(+), 1494 deletions(-) (limited to 'package/mac80211/patches/300-pending_work.patch') diff --git a/package/mac80211/patches/300-pending_work.patch b/package/mac80211/patches/300-pending_work.patch index d3867c409b..b35f5c6036 100644 --- a/package/mac80211/patches/300-pending_work.patch +++ b/package/mac80211/patches/300-pending_work.patch @@ -1,114 +1,3 @@ ---- a/drivers/net/wireless/ath/ath9k/common.h -+++ b/drivers/net/wireless/ath/ath9k/common.h -@@ -27,7 +27,7 @@ - #define WME_MAX_BA WME_BA_BMP_SIZE - #define ATH_TID_MAX_BUFS (2 * WME_MAX_BA) - --#define ATH_RSSI_DUMMY_MARKER 0x127 -+#define ATH_RSSI_DUMMY_MARKER 127 - #define ATH_RSSI_LPF_LEN 10 - #define RSSI_LPF_THRESHOLD -20 - #define ATH_RSSI_EP_MULTIPLIER (1<<7) ---- a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c -+++ b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c -@@ -1067,15 +1067,19 @@ static bool ath9k_rx_prepare(struct ath9 - - last_rssi = priv->rx.last_rssi; - -- if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER)) -- rxbuf->rxstatus.rs_rssi = ATH_EP_RND(last_rssi, -- ATH_RSSI_EP_MULTIPLIER); -+ if (ieee80211_is_beacon(hdr->frame_control) && -+ !is_zero_ether_addr(common->curbssid) && -+ ether_addr_equal(hdr->addr3, common->curbssid)) { -+ s8 rssi = rxbuf->rxstatus.rs_rssi; - -- if (rxbuf->rxstatus.rs_rssi < 0) -- rxbuf->rxstatus.rs_rssi = 0; -+ if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER)) -+ rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER); - -- if (ieee80211_is_beacon(fc)) -- priv->ah->stats.avgbrssi = rxbuf->rxstatus.rs_rssi; -+ if (rssi < 0) -+ rssi = 0; -+ -+ priv->ah->stats.avgbrssi = rssi; -+ } - - rx_status->mactime = be64_to_cpu(rxbuf->rxstatus.rs_tstamp); - rx_status->band = hw->conf.channel->band; ---- a/include/linux/ieee80211.h -+++ b/include/linux/ieee80211.h -@@ -185,7 +185,7 @@ struct ieee80211_hdr { - u8 addr3[6]; - __le16 seq_ctrl; - u8 addr4[6]; --} __packed; -+} __packed __aligned(2); - - struct ieee80211_hdr_3addr { - __le16 frame_control; -@@ -194,7 +194,7 @@ struct ieee80211_hdr_3addr { - u8 addr2[6]; - u8 addr3[6]; - __le16 seq_ctrl; --} __packed; -+} __packed __aligned(2); - - struct ieee80211_qos_hdr { - __le16 frame_control; -@@ -204,7 +204,7 @@ struct ieee80211_qos_hdr { - u8 addr3[6]; - __le16 seq_ctrl; - __le16 qos_ctrl; --} __packed; -+} __packed __aligned(2); - - /** - * ieee80211_has_tods - check if IEEE80211_FCTL_TODS is set -@@ -581,7 +581,7 @@ struct ieee80211s_hdr { - __le32 seqnum; - u8 eaddr1[6]; - u8 eaddr2[6]; --} __packed; -+} __packed __aligned(2); - - /* Mesh flags */ - #define MESH_FLAGS_AE_A4 0x1 -@@ -875,7 +875,7 @@ struct ieee80211_mgmt { - } u; - } __packed action; - } u; --} __packed; -+} __packed __aligned(2); - - /* Supported Rates value encodings in 802.11n-2009 7.3.2.2 */ - #define BSS_MEMBERSHIP_SELECTOR_HT_PHY 127 -@@ -906,20 +906,20 @@ struct ieee80211_rts { - __le16 duration; - u8 ra[6]; - u8 ta[6]; --} __packed; -+} __packed __aligned(2); - - struct ieee80211_cts { - __le16 frame_control; - __le16 duration; - u8 ra[6]; --} __packed; -+} __packed __aligned(2); - - struct ieee80211_pspoll { - __le16 frame_control; - __le16 aid; - u8 bssid[6]; - u8 ta[6]; --} __packed; -+} __packed __aligned(2); - - /* TDLS */ - --- a/net/mac80211/agg-rx.c +++ b/net/mac80211/agg-rx.c @@ -204,6 +204,8 @@ static void ieee80211_send_addba_resp(st @@ -142,7 +31,7 @@ --- a/net/mac80211/debugfs_sta.c +++ b/net/mac80211/debugfs_sta.c -@@ -65,11 +65,11 @@ static ssize_t sta_flags_read(struct fil +@@ -66,11 +66,11 @@ static ssize_t sta_flags_read(struct fil test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : "" int res = scnprintf(buf, sizeof(buf), @@ -158,25 +47,7 @@ TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT), --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c -@@ -78,7 +78,7 @@ void ieee80211_recalc_txpower(struct iee - ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_TXPOWER); - } - --static u32 ieee80211_idle_off(struct ieee80211_local *local) -+u32 ieee80211_idle_off(struct ieee80211_local *local) - { - if (!(local->hw.conf.flags & IEEE80211_CONF_IDLE)) - return 0; -@@ -107,7 +107,7 @@ void ieee80211_recalc_idle(struct ieee80 - - lockdep_assert_held(&local->mtx); - -- active = !list_empty(&local->chanctx_list); -+ active = !list_empty(&local->chanctx_list) || local->monitors; - - if (!local->ops->remain_on_channel) { - list_for_each_entry(roc, &local->roc_list, list) { -@@ -436,7 +436,6 @@ int ieee80211_do_open(struct wireless_de +@@ -463,7 +463,6 @@ int ieee80211_do_open(struct wireless_de struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); struct net_device *dev = wdev->netdev; struct ieee80211_local *local = sdata->local; @@ -184,17 +55,7 @@ u32 changed = 0; int res; u32 hw_reconf_flags = 0; -@@ -541,6 +540,9 @@ int ieee80211_do_open(struct wireless_de - - ieee80211_adjust_monitor_flags(sdata, 1); - ieee80211_configure_filter(local); -+ mutex_lock(&local->mtx); -+ ieee80211_recalc_idle(local); -+ mutex_unlock(&local->mtx); - - netif_carrier_on(dev); - break; -@@ -595,30 +597,8 @@ int ieee80211_do_open(struct wireless_de +@@ -629,30 +628,8 @@ int ieee80211_do_open(struct wireless_de set_bit(SDATA_STATE_RUNNING, &sdata->state); @@ -226,17 +87,7 @@ /* * set_multicast_list will be invoked by the networking core -@@ -817,6 +797,9 @@ static void ieee80211_do_stop(struct iee - - ieee80211_adjust_monitor_flags(sdata, -1); - ieee80211_configure_filter(local); -+ mutex_lock(&local->mtx); -+ ieee80211_recalc_idle(local); -+ mutex_unlock(&local->mtx); - break; - case NL80211_IFTYPE_P2P_DEVICE: - /* relies on synchronize_rcu() below */ -@@ -1022,6 +1005,72 @@ static void ieee80211_if_setup(struct ne +@@ -1116,6 +1093,74 @@ static void ieee80211_if_setup(struct ne dev->destructor = free_netdev; } @@ -252,10 +103,12 @@ + u32 rates = 0; + u16 stype; + bool new = false; -+ enum ieee80211_band band = local->hw.conf.channel->band; -+ struct ieee80211_supported_band *sband = local->hw.wiphy->bands[band]; ++ enum ieee80211_band band; ++ struct ieee80211_supported_band *sband; + + rx_status = IEEE80211_SKB_RXCB(skb); ++ band = rx_status->band; ++ sband = local->hw.wiphy->bands[band]; + mgmt = (struct ieee80211_mgmt *) skb->data; + stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; + @@ -267,7 +120,7 @@ + return; + + ieee802_11_parse_elems(mgmt->u.probe_resp.variable, -+ skb->len - baselen, &elems); ++ skb->len - baselen, false, &elems); + + rates = ieee80211_sta_get_rates(local, &elems, band, NULL); + @@ -286,7 +139,7 @@ + } + + sta->last_rx = jiffies; -+ sta->sta.supp_rates[local->hw.conf.channel->band] = rates; ++ sta->sta.supp_rates[band] = rates; + + if (elems.ht_cap_elem) + ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, @@ -309,7 +162,7 @@ static void ieee80211_iface_work(struct work_struct *work) { struct ieee80211_sub_if_data *sdata = -@@ -1126,6 +1175,9 @@ static void ieee80211_iface_work(struct +@@ -1220,6 +1265,9 @@ static void ieee80211_iface_work(struct break; ieee80211_mesh_rx_queued_mgmt(sdata, skb); break; @@ -319,9 +172,48 @@ default: WARN(1, "frame for unexpected interface type"); break; +--- a/net/mac80211/rc80211_minstrel_ht.c ++++ b/net/mac80211/rc80211_minstrel_ht.c +@@ -804,10 +804,18 @@ minstrel_ht_get_rate(void *priv, struct + + sample_group = &minstrel_mcs_groups[sample_idx / MCS_GROUP_RATES]; + info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE; ++ rate->count = 1; ++ ++ if (sample_idx / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) { ++ int idx = sample_idx % ARRAY_SIZE(mp->cck_rates); ++ rate->idx = mp->cck_rates[idx]; ++ rate->flags = 0; ++ return; ++ } ++ + rate->idx = sample_idx % MCS_GROUP_RATES + + (sample_group->streams - 1) * MCS_GROUP_RATES; + rate->flags = IEEE80211_TX_RC_MCS | sample_group->flags; +- rate->count = 1; + } + + static void --- a/net/mac80211/rx.c +++ b/net/mac80211/rx.c -@@ -2365,6 +2365,7 @@ ieee80211_rx_h_action(struct ieee80211_r +@@ -936,8 +936,14 @@ ieee80211_rx_h_check(struct ieee80211_rx + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data; + struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb); + +- /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */ +- if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) { ++ /* ++ * Drop duplicate 802.11 retransmissions ++ * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery") ++ */ ++ if (rx->skb->len >= 24 && rx->sta && ++ !ieee80211_is_ctl(hdr->frame_control) && ++ !ieee80211_is_qos_nullfunc(hdr->frame_control) && ++ !is_multicast_ether_addr(hdr->addr1)) { + if (unlikely(ieee80211_has_retry(hdr->frame_control) && + rx->sta->last_seq_ctrl[rx->seqno_idx] == + hdr->seq_ctrl)) { +@@ -2369,6 +2375,7 @@ ieee80211_rx_h_action(struct ieee80211_r sdata->vif.type != NL80211_IFTYPE_MESH_POINT && sdata->vif.type != NL80211_IFTYPE_AP_VLAN && sdata->vif.type != NL80211_IFTYPE_AP && @@ -329,7 +221,7 @@ sdata->vif.type != NL80211_IFTYPE_ADHOC) break; -@@ -2692,14 +2693,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_ +@@ -2720,14 +2727,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_ if (!ieee80211_vif_is_mesh(&sdata->vif) && sdata->vif.type != NL80211_IFTYPE_ADHOC && @@ -347,7 +239,7 @@ break; case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP): case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP): -@@ -3028,10 +3030,16 @@ static int prepare_for_handlers(struct i +@@ -3059,10 +3067,16 @@ static int prepare_for_handlers(struct i } break; case NL80211_IFTYPE_WDS: @@ -384,1384 +276,506 @@ WLAN_STA_CLEAR_PS_FILT, WLAN_STA_MFP, WLAN_STA_BLOCK_BA, ---- a/net/mac80211/tx.c -+++ b/net/mac80211/tx.c -@@ -1231,34 +1231,40 @@ static bool ieee80211_tx_frags(struct ie - if (local->queue_stop_reasons[q] || - (!txpending && !skb_queue_empty(&local->pending[q]))) { - if (unlikely(info->flags & -- IEEE80211_TX_INTFL_OFFCHAN_TX_OK && -- local->queue_stop_reasons[q] & -- ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL))) { -+ IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) { -+ if (local->queue_stop_reasons[q] & -+ ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL)) { -+ /* -+ * Drop off-channel frames if queues -+ * are stopped for any reason other -+ * than off-channel operation. Never -+ * queue them. -+ */ -+ spin_unlock_irqrestore( -+ &local->queue_stop_reason_lock, -+ flags); -+ ieee80211_purge_tx_queue(&local->hw, -+ skbs); -+ return true; -+ } -+ } else { +--- a/drivers/net/wireless/ath/ath9k/xmit.c ++++ b/drivers/net/wireless/ath/ath9k/xmit.c +@@ -146,6 +146,28 @@ static void ath_set_rates(struct ieee802 + ARRAY_SIZE(bf->rates)); + } + ++static void ath_txq_skb_done(struct ath_softc *sc, struct ath_txq *txq, ++ struct sk_buff *skb) ++{ ++ int q; + - /* -- * Drop off-channel frames if queues are stopped -- * for any reason other than off-channel -- * operation. Never queue them. -+ * Since queue is stopped, queue up frames for -+ * later transmission from the tx-pending -+ * tasklet when the queue is woken again. - */ -- spin_unlock_irqrestore( -- &local->queue_stop_reason_lock, flags); -- ieee80211_purge_tx_queue(&local->hw, skbs); -- return true; -+ if (txpending) -+ skb_queue_splice_init(skbs, -+ &local->pending[q]); -+ else -+ skb_queue_splice_tail_init(skbs, -+ &local->pending[q]); ++ q = skb_get_queue_mapping(skb); ++ if (txq == sc->tx.uapsdq) ++ txq = sc->tx.txq_map[q]; + -+ spin_unlock_irqrestore(&local->queue_stop_reason_lock, -+ flags); -+ return false; - } -- -- /* -- * Since queue is stopped, queue up frames for later -- * transmission from the tx-pending tasklet when the -- * queue is woken again. -- */ -- if (txpending) -- skb_queue_splice_init(skbs, &local->pending[q]); -- else -- skb_queue_splice_tail_init(skbs, -- &local->pending[q]); -- -- spin_unlock_irqrestore(&local->queue_stop_reason_lock, -- flags); -- return false; - } - spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); - -@@ -1848,9 +1854,24 @@ netdev_tx_t ieee80211_subif_start_xmit(s - } - - if (!is_multicast_ether_addr(skb->data)) { -+ struct sta_info *next_hop; -+ bool mpp_lookup = true; ++ if (txq != sc->tx.txq_map[q]) ++ return; + - mpath = mesh_path_lookup(sdata, skb->data); -- if (!mpath) -+ if (mpath) { -+ mpp_lookup = false; -+ next_hop = rcu_dereference(mpath->next_hop); -+ if (!next_hop || -+ !(mpath->flags & (MESH_PATH_ACTIVE | -+ MESH_PATH_RESOLVING))) -+ mpp_lookup = true; -+ } ++ if (WARN_ON(--txq->pending_frames < 0)) ++ txq->pending_frames = 0; + -+ if (mpp_lookup) - mppath = mpp_path_lookup(sdata, skb->data); ++ if (txq->stopped && ++ txq->pending_frames < sc->tx.txq_max_pending[q]) { ++ ieee80211_wake_queue(sc->hw, q); ++ txq->stopped = false; ++ } ++} + -+ if (mppath && mpath) -+ mesh_path_del(mpath->sdata, mpath->dst); - } - - /* ---- a/net/wireless/nl80211.c -+++ b/net/wireless/nl80211.c -@@ -554,16 +554,9 @@ static int nl80211_msg_put_channel(struc - if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && - nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) - goto nla_put_failure; -- if (chan->flags & IEEE80211_CHAN_RADAR) { -- u32 time = elapsed_jiffies_msecs(chan->dfs_state_entered); -- if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) -- goto nla_put_failure; -- if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, -- chan->dfs_state)) -- goto nla_put_failure; -- if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, time)) -- goto nla_put_failure; -- } -+ if ((chan->flags & IEEE80211_CHAN_RADAR) && -+ nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) -+ goto nla_put_failure; - if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && - nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) - goto nla_put_failure; -@@ -900,9 +893,6 @@ static int nl80211_put_iface_combination - nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, - c->max_interfaces)) - goto nla_put_failure; -- if (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, -- c->radar_detect_widths)) -- goto nla_put_failure; - - nla_nest_end(msg, nl_combi); - } -@@ -914,48 +904,6 @@ nla_put_failure: - return -ENOBUFS; - } - --#ifdef CONFIG_PM --static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, -- struct sk_buff *msg) --{ -- const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan.tcp; -- struct nlattr *nl_tcp; -- -- if (!tcp) -- return 0; -- -- nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); -- if (!nl_tcp) -- return -ENOBUFS; -- -- if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, -- tcp->data_payload_max)) -- return -ENOBUFS; -- -- if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, -- tcp->data_payload_max)) -- return -ENOBUFS; -- -- if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) -- return -ENOBUFS; -- -- if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, -- sizeof(*tcp->tok), tcp->tok)) -- return -ENOBUFS; -- -- if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, -- tcp->data_interval_max)) -- return -ENOBUFS; -- -- if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, -- tcp->wake_payload_max)) -- return -ENOBUFS; -- -- nla_nest_end(msg, nl_tcp); -- return 0; --} --#endif -- - static int nl80211_send_wiphy(struct sk_buff *msg, u32 portid, u32 seq, int flags, - struct cfg80211_registered_device *dev) + static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid) { -@@ -1330,9 +1278,6 @@ static int nl80211_send_wiphy(struct sk_ - goto nla_put_failure; + struct ath_txq *txq = tid->ac->txq; +@@ -167,6 +189,7 @@ static void ath_tx_flush_tid(struct ath_ + if (!bf) { + bf = ath_tx_setup_buffer(sc, txq, tid, skb); + if (!bf) { ++ ath_txq_skb_done(sc, txq, skb); + ieee80211_free_txskb(sc->hw, skb); + continue; + } +@@ -811,6 +834,7 @@ ath_tx_get_tid_subframe(struct ath_softc + + if (!bf) { + __skb_unlink(skb, &tid->buf_q); ++ ath_txq_skb_done(sc, txq, skb); + ieee80211_free_txskb(sc->hw, skb); + continue; } +@@ -1824,6 +1848,7 @@ static void ath_tx_send_ampdu(struct ath -- if (nl80211_send_wowlan_tcp_caps(dev, msg)) -- goto nla_put_failure; -- - nla_nest_end(msg, nl_wowlan); + bf = ath_tx_setup_buffer(sc, txq, tid, skb); + if (!bf) { ++ ath_txq_skb_done(sc, txq, skb); + ieee80211_free_txskb(sc->hw, skb); + return; } - #endif ---- a/net/mac80211/cfg.c -+++ b/net/mac80211/cfg.c -@@ -3285,13 +3285,19 @@ static int ieee80211_cfg_get_channel(str - struct cfg80211_chan_def *chandef) - { - struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); -+ struct ieee80211_local *local = wiphy_priv(wiphy); - struct ieee80211_chanctx_conf *chanctx_conf; - int ret = -ENODATA; +@@ -2090,6 +2115,7 @@ int ath_tx_start(struct ieee80211_hw *hw - rcu_read_lock(); -- chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); -- if (chanctx_conf) { -- *chandef = chanctx_conf->def; -+ if (local->use_chanctx) { -+ chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); -+ if (chanctx_conf) { -+ *chandef = chanctx_conf->def; -+ ret = 0; -+ } -+ } else if (local->open_count == local->monitors) { -+ *chandef = local->monitor_chandef; - ret = 0; - } - rcu_read_unlock(); ---- a/drivers/net/wireless/ath/ath9k/hw.c -+++ b/drivers/net/wireless/ath/ath9k/hw.c -@@ -1463,7 +1463,9 @@ static bool ath9k_hw_chip_reset(struct a - reset_type = ATH9K_RESET_POWER_ON; + bf = ath_tx_setup_buffer(sc, txq, tid, skb); + if (!bf) { ++ ath_txq_skb_done(sc, txq, skb); + if (txctl->paprd) + dev_kfree_skb_any(skb); else - reset_type = ATH9K_RESET_COLD; -- } -+ } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) || -+ (REG_READ(ah, AR_CR) & AR_CR_RXE)) -+ reset_type = ATH9K_RESET_COLD; - - if (!ath9k_hw_set_reset_reg(ah, reset_type)) - return false; -@@ -1876,13 +1878,12 @@ int ath9k_hw_reset(struct ath_hw *ah, st - - ENABLE_REGWRITE_BUFFER(ah); - -- REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr)); -- REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4) -- | macStaId1 -+ REG_RMW(ah, AR_STA_ID1, macStaId1 - | AR_STA_ID1_RTS_USE_DEF - | (ah->config. - ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0) -- | ah->sta_id1_defaults); -+ | ah->sta_id1_defaults, -+ ~AR_STA_ID1_SADH_MASK); - ath_hw_setbssidmask(common); - REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna); - ath9k_hw_write_associd(ah); ---- a/drivers/net/wireless/rt2x00/rt2x00dev.c -+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c -@@ -1236,8 +1236,10 @@ static inline void rt2x00lib_set_if_comb - */ - if_limit = &rt2x00dev->if_limits_ap; - if_limit->max = rt2x00dev->ops->max_ap_intf; -- if_limit->types = BIT(NL80211_IFTYPE_AP) | -- BIT(NL80211_IFTYPE_MESH_POINT); -+ if_limit->types = BIT(NL80211_IFTYPE_AP); -+#ifdef CONFIG_MAC80211_MESH -+ if_limit->types |= BIT(NL80211_IFTYPE_MESH_POINT); -+#endif - - /* - * Build up AP interface combinations structure. -@@ -1309,7 +1311,9 @@ int rt2x00lib_probe_dev(struct rt2x00_de - rt2x00dev->hw->wiphy->interface_modes |= - BIT(NL80211_IFTYPE_ADHOC) | - BIT(NL80211_IFTYPE_AP) | -+#ifdef CONFIG_MAC80211_MESH - BIT(NL80211_IFTYPE_MESH_POINT) | -+#endif - BIT(NL80211_IFTYPE_WDS); - - rt2x00dev->hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; ---- a/net/mac80211/rc80211_minstrel_ht.c -+++ b/net/mac80211/rc80211_minstrel_ht.c -@@ -17,8 +17,6 @@ - #include "rc80211_minstrel_ht.h" - - #define AVG_PKT_SIZE 1200 --#define SAMPLE_COLUMNS 10 --#define EWMA_LEVEL 75 - - /* Number of bits for an average sized packet */ - #define MCS_NBITS (AVG_PKT_SIZE << 3) -@@ -26,11 +24,11 @@ - /* Number of symbols for a packet with (bps) bits per symbol */ - #define MCS_NSYMS(bps) ((MCS_NBITS + (bps) - 1) / (bps)) +@@ -2189,7 +2215,7 @@ static void ath_tx_complete(struct ath_s + struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); + struct ath_common *common = ath9k_hw_common(sc->sc_ah); + struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data; +- int q, padpos, padsize; ++ int padpos, padsize; + unsigned long flags; --/* Transmission time for a packet containing (syms) symbols */ -+/* Transmission time (nanoseconds) for a packet containing (syms) symbols */ - #define MCS_SYMBOL_TIME(sgi, syms) \ - (sgi ? \ -- ((syms) * 18 + 4) / 5 : /* syms * 3.6 us */ \ -- (syms) << 2 /* syms * 4 us */ \ -+ ((syms) * 18000 + 4000) / 5 : /* syms * 3.6 us */ \ -+ ((syms) * 1000) << 2 /* syms * 4 us */ \ - ) + ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb); +@@ -2225,21 +2251,7 @@ static void ath_tx_complete(struct ath_s + spin_unlock_irqrestore(&sc->sc_pm_lock, flags); - /* Transmit duration for the raw data part of an average sized packet */ -@@ -64,9 +62,9 @@ + __skb_queue_tail(&txq->complete_q, skb); +- +- q = skb_get_queue_mapping(skb); +- if (txq == sc->tx.uapsdq) +- txq = sc->tx.txq_map[q]; +- +- if (txq == sc->tx.txq_map[q]) { +- if (WARN_ON(--txq->pending_frames < 0)) +- txq->pending_frames = 0; +- +- if (txq->stopped && +- txq->pending_frames < sc->tx.txq_max_pending[q]) { +- ieee80211_wake_queue(sc->hw, q); +- txq->stopped = false; +- } +- } ++ ath_txq_skb_done(sc, txq, skb); } - #define CCK_DURATION(_bitrate, _short, _len) \ -- (10 /* SIFS */ + \ -+ (1000 * (10 /* SIFS */ + \ - (_short ? 72 + 24 : 144 + 48 ) + \ -- (8 * (_len + 4) * 10) / (_bitrate)) -+ (8 * (_len + 4) * 10) / (_bitrate))) - - #define CCK_ACK_DURATION(_bitrate, _short) \ - (CCK_DURATION((_bitrate > 10 ? 20 : 10), false, 60) + \ -@@ -129,15 +127,6 @@ const struct mcs_group minstrel_mcs_grou - static u8 sample_table[SAMPLE_COLUMNS][MCS_GROUP_RATES]; + static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf, +--- a/drivers/net/wireless/ath/ath9k/main.c ++++ b/drivers/net/wireless/ath/ath9k/main.c +@@ -2094,7 +2094,7 @@ static void ath9k_wow_add_pattern(struct + { + struct ath_hw *ah = sc->sc_ah; + struct ath9k_wow_pattern *wow_pattern = NULL; +- struct cfg80211_wowlan_trig_pkt_pattern *patterns = wowlan->patterns; ++ struct cfg80211_pkt_pattern *patterns = wowlan->patterns; + int mask_len; + s8 i = 0; + +--- a/drivers/net/wireless/mwifiex/cfg80211.c ++++ b/drivers/net/wireless/mwifiex/cfg80211.c +@@ -2298,8 +2298,7 @@ EXPORT_SYMBOL_GPL(mwifiex_del_virtual_in + + #ifdef CONFIG_PM + static bool +-mwifiex_is_pattern_supported(struct cfg80211_wowlan_trig_pkt_pattern *pat, +- s8 *byte_seq) ++mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq) + { + int j, k, valid_byte_cnt = 0; + bool dont_care_byte = false; +--- a/drivers/net/wireless/ti/wlcore/main.c ++++ b/drivers/net/wireless/ti/wlcore/main.c +@@ -1315,7 +1315,7 @@ static struct sk_buff *wl12xx_alloc_dumm - /* -- * Perform EWMA (Exponentially Weighted Moving Average) calculation -- */ --static int --minstrel_ewma(int old, int new, int weight) --{ -- return (new * (100 - weight) + old * weight) / 100; --} -- --/* - * Look up an MCS group index based on mac80211 rate information - */ + #ifdef CONFIG_PM static int -@@ -211,20 +200,32 @@ static void - minstrel_ht_calc_tp(struct minstrel_ht_sta *mi, int group, int rate) +-wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern *p) ++wl1271_validate_wowlan_pattern(struct cfg80211_pkt_pattern *p) + { + int num_fields = 0, in_field = 0, fields_size = 0; + int i, pattern_len = 0; +@@ -1458,9 +1458,9 @@ void wl1271_rx_filter_flatten_fields(str + * Allocates an RX filter returned through f + * which needs to be freed using rx_filter_free() + */ +-static int wl1271_convert_wowlan_pattern_to_rx_filter( +- struct cfg80211_wowlan_trig_pkt_pattern *p, +- struct wl12xx_rx_filter **f) ++static int ++wl1271_convert_wowlan_pattern_to_rx_filter(struct cfg80211_pkt_pattern *p, ++ struct wl12xx_rx_filter **f) { - struct minstrel_rate_stats *mr; -- unsigned int usecs = 0; -+ unsigned int nsecs = 0; -+ unsigned int tp; -+ unsigned int prob; + int i, j, ret = 0; + struct wl12xx_rx_filter *filter; +@@ -1562,7 +1562,7 @@ static int wl1271_configure_wowlan(struc + + /* Translate WoWLAN patterns into filters */ + for (i = 0; i < wow->n_patterns; i++) { +- struct cfg80211_wowlan_trig_pkt_pattern *p; ++ struct cfg80211_pkt_pattern *p; + struct wl12xx_rx_filter *filter = NULL; + + p = &wow->patterns[i]; +--- a/include/net/cfg80211.h ++++ b/include/net/cfg80211.h +@@ -1698,7 +1698,7 @@ struct cfg80211_pmksa { + }; - mr = &mi->groups[group].rates[rate]; -+ prob = mr->probability; + /** +- * struct cfg80211_wowlan_trig_pkt_pattern - packet pattern ++ * struct cfg80211_pkt_pattern - packet pattern + * @mask: bitmask where to match pattern and where to ignore bytes, + * one bit per byte, in same format as nl80211 + * @pattern: bytes to match where bitmask is 1 +@@ -1708,7 +1708,7 @@ struct cfg80211_pmksa { + * Internal note: @mask and @pattern are allocated in one chunk of + * memory, free @mask only! + */ +-struct cfg80211_wowlan_trig_pkt_pattern { ++struct cfg80211_pkt_pattern { + u8 *mask, *pattern; + int pattern_len; + int pkt_offset; +@@ -1770,7 +1770,7 @@ struct cfg80211_wowlan { + bool any, disconnect, magic_pkt, gtk_rekey_failure, + eap_identity_req, four_way_handshake, + rfkill_release; +- struct cfg80211_wowlan_trig_pkt_pattern *patterns; ++ struct cfg80211_pkt_pattern *patterns; + struct cfg80211_wowlan_tcp *tcp; + int n_patterns; + }; +--- a/include/uapi/linux/nl80211.h ++++ b/include/uapi/linux/nl80211.h +@@ -3060,11 +3060,11 @@ enum nl80211_tx_power_setting { + }; -- if (mr->probability < MINSTREL_FRAC(1, 10)) { -+ if (prob < MINSTREL_FRAC(1, 10)) { - mr->cur_tp = 0; - return; - } + /** +- * enum nl80211_wowlan_packet_pattern_attr - WoWLAN packet pattern attribute +- * @__NL80211_WOWLAN_PKTPAT_INVALID: invalid number for nested attribute +- * @NL80211_WOWLAN_PKTPAT_PATTERN: the pattern, values where the mask has ++ * enum nl80211_packet_pattern_attr - packet pattern attribute ++ * @__NL80211_PKTPAT_INVALID: invalid number for nested attribute ++ * @NL80211_PKTPAT_PATTERN: the pattern, values where the mask has + * a zero bit are ignored +- * @NL80211_WOWLAN_PKTPAT_MASK: pattern mask, must be long enough to have ++ * @NL80211_PKTPAT_MASK: pattern mask, must be long enough to have + * a bit for each byte in the pattern. The lowest-order bit corresponds + * to the first byte of the pattern, but the bytes of the pattern are + * in a little-endian-like format, i.e. the 9th byte of the pattern +@@ -3075,23 +3075,23 @@ enum nl80211_tx_power_setting { + * Note that the pattern matching is done as though frames were not + * 802.11 frames but 802.3 frames, i.e. the frame is fully unpacked + * first (including SNAP header unpacking) and then matched. +- * @NL80211_WOWLAN_PKTPAT_OFFSET: packet offset, pattern is matched after ++ * @NL80211_PKTPAT_OFFSET: packet offset, pattern is matched after + * these fixed number of bytes of received packet +- * @NUM_NL80211_WOWLAN_PKTPAT: number of attributes +- * @MAX_NL80211_WOWLAN_PKTPAT: max attribute number ++ * @NUM_NL80211_PKTPAT: number of attributes ++ * @MAX_NL80211_PKTPAT: max attribute number + */ +-enum nl80211_wowlan_packet_pattern_attr { +- __NL80211_WOWLAN_PKTPAT_INVALID, +- NL80211_WOWLAN_PKTPAT_MASK, +- NL80211_WOWLAN_PKTPAT_PATTERN, +- NL80211_WOWLAN_PKTPAT_OFFSET, ++enum nl80211_packet_pattern_attr { ++ __NL80211_PKTPAT_INVALID, ++ NL80211_PKTPAT_MASK, ++ NL80211_PKTPAT_PATTERN, ++ NL80211_PKTPAT_OFFSET, + +- NUM_NL80211_WOWLAN_PKTPAT, +- MAX_NL80211_WOWLAN_PKTPAT = NUM_NL80211_WOWLAN_PKTPAT - 1, ++ NUM_NL80211_PKTPAT, ++ MAX_NL80211_PKTPAT = NUM_NL80211_PKTPAT - 1, + }; -+ /* -+ * For the throughput calculation, limit the probability value to 90% to -+ * account for collision related packet error rate fluctuation -+ */ -+ if (prob > MINSTREL_FRAC(9, 10)) -+ prob = MINSTREL_FRAC(9, 10); -+ - if (group != MINSTREL_CCK_GROUP) -- usecs = mi->overhead / MINSTREL_TRUNC(mi->avg_ampdu_len); -+ nsecs = 1000 * mi->overhead / MINSTREL_TRUNC(mi->avg_ampdu_len); + /** +- * struct nl80211_wowlan_pattern_support - pattern support information ++ * struct nl80211_pattern_support - packet pattern support information + * @max_patterns: maximum number of patterns supported + * @min_pattern_len: minimum length of each pattern + * @max_pattern_len: maximum length of each pattern +@@ -3101,13 +3101,22 @@ enum nl80211_wowlan_packet_pattern_attr + * that is part of %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED in the + * capability information given by the kernel to userspace. + */ +-struct nl80211_wowlan_pattern_support { ++struct nl80211_pattern_support { + __u32 max_patterns; + __u32 min_pattern_len; + __u32 max_pattern_len; + __u32 max_pkt_offset; + } __attribute__((packed)); + ++/* only for backward compatibility */ ++#define __NL80211_WOWLAN_PKTPAT_INVALID __NL80211_PKTPAT_INVALID ++#define NL80211_WOWLAN_PKTPAT_MASK NL80211_PKTPAT_MASK ++#define NL80211_WOWLAN_PKTPAT_PATTERN NL80211_PKTPAT_PATTERN ++#define NL80211_WOWLAN_PKTPAT_OFFSET NL80211_PKTPAT_OFFSET ++#define NUM_NL80211_WOWLAN_PKTPAT NUM_NL80211_PKTPAT ++#define MAX_NL80211_WOWLAN_PKTPAT MAX_NL80211_PKTPAT ++#define nl80211_wowlan_pattern_support nl80211_pattern_support + -+ nsecs += minstrel_mcs_groups[group].duration[rate]; -+ tp = 1000000 * ((mr->probability * 1000) / nsecs); - -- usecs += minstrel_mcs_groups[group].duration[rate]; -- mr->cur_tp = MINSTREL_TRUNC((1000000 / usecs) * mr->probability); -+ mr->cur_tp = MINSTREL_TRUNC(tp); - } - - /* -@@ -308,8 +309,8 @@ minstrel_ht_update_stats(struct minstrel - } - } - -- /* try to sample up to half of the available rates during each interval */ -- mi->sample_count *= 4; -+ /* try to sample all available rates during each interval */ -+ mi->sample_count *= 8; - - cur_prob = 0; - cur_prob_tp = 0; -@@ -320,20 +321,13 @@ minstrel_ht_update_stats(struct minstrel - if (!mg->supported) - continue; - -- mr = minstrel_get_ratestats(mi, mg->max_prob_rate); -- if (cur_prob_tp < mr->cur_tp && -- minstrel_mcs_groups[group].streams == 1) { -- mi->max_prob_rate = mg->max_prob_rate; -- cur_prob = mr->cur_prob; -- cur_prob_tp = mr->cur_tp; -- } -- - mr = minstrel_get_ratestats(mi, mg->max_tp_rate); - if (cur_tp < mr->cur_tp) { - mi->max_tp_rate2 = mi->max_tp_rate; - cur_tp2 = cur_tp; - mi->max_tp_rate = mg->max_tp_rate; - cur_tp = mr->cur_tp; -+ mi->max_prob_streams = minstrel_mcs_groups[group].streams - 1; - } - - mr = minstrel_get_ratestats(mi, mg->max_tp_rate2); -@@ -343,6 +337,23 @@ minstrel_ht_update_stats(struct minstrel - } - } - -+ if (mi->max_prob_streams < 1) -+ mi->max_prob_streams = 1; + /** + * enum nl80211_wowlan_triggers - WoWLAN trigger definitions + * @__NL80211_WOWLAN_TRIG_INVALID: invalid number for nested attributes +@@ -3127,7 +3136,7 @@ struct nl80211_wowlan_pattern_support { + * pattern matching is done after the packet is converted to the MSDU. + * + * In %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED, it is a binary attribute +- * carrying a &struct nl80211_wowlan_pattern_support. ++ * carrying a &struct nl80211_pattern_support. + * + * When reporting wakeup. it is a u32 attribute containing the 0-based + * index of the pattern that caused the wakeup, in the patterns passed +@@ -3284,7 +3293,7 @@ struct nl80211_wowlan_tcp_data_token_fea + * @NL80211_WOWLAN_TCP_WAKE_PAYLOAD: wake packet payload, for advertising a + * u32 attribute holding the maximum length + * @NL80211_WOWLAN_TCP_WAKE_MASK: Wake packet payload mask, not used for +- * feature advertising. The mask works like @NL80211_WOWLAN_PKTPAT_MASK ++ * feature advertising. The mask works like @NL80211_PKTPAT_MASK + * but on the TCP payload only. + * @NUM_NL80211_WOWLAN_TCP: number of TCP attributes + * @MAX_NL80211_WOWLAN_TCP: highest attribute number +--- a/net/mac80211/mesh_ps.c ++++ b/net/mac80211/mesh_ps.c +@@ -229,6 +229,10 @@ void ieee80211_mps_sta_status_update(str + enum nl80211_mesh_power_mode pm; + bool do_buffer; + ++ /* For non-assoc STA, prevent buffering or frame transmission */ ++ if (sta->sta_state < IEEE80211_STA_ASSOC) ++ return; + -+ for (group = 0; group < ARRAY_SIZE(minstrel_mcs_groups); group++) { -+ mg = &mi->groups[group]; -+ if (!mg->supported) -+ continue; -+ mr = minstrel_get_ratestats(mi, mg->max_prob_rate); -+ if (cur_prob_tp < mr->cur_tp && -+ minstrel_mcs_groups[group].streams <= mi->max_prob_streams) { -+ mi->max_prob_rate = mg->max_prob_rate; -+ cur_prob = mr->cur_prob; -+ cur_prob_tp = mr->cur_tp; + /* + * use peer-specific power mode if peering is established and the + * peer's power mode is known +--- a/net/wireless/nl80211.c ++++ b/net/wireless/nl80211.c +@@ -974,7 +974,7 @@ static int nl80211_send_wowlan(struct sk + return -ENOBUFS; + + if (dev->wiphy.wowlan->n_patterns) { +- struct nl80211_wowlan_pattern_support pat = { ++ struct nl80211_pattern_support pat = { + .max_patterns = dev->wiphy.wowlan->n_patterns, + .min_pattern_len = dev->wiphy.wowlan->pattern_min_len, + .max_pattern_len = dev->wiphy.wowlan->pattern_max_len, +@@ -1568,8 +1568,10 @@ static int nl80211_dump_wiphy(struct sk_ + rtnl_lock(); + if (!state) { + state = kzalloc(sizeof(*state), GFP_KERNEL); +- if (!state) ++ if (!state) { ++ rtnl_unlock(); + return -ENOMEM; + } -+ } -+ -+ - mi->stats_update = jiffies; - } - -@@ -467,7 +478,7 @@ minstrel_ht_tx_status(void *priv, struct - - if (!mi->sample_wait && !mi->sample_tries && mi->sample_count > 0) { - mi->sample_wait = 16 + 2 * MINSTREL_TRUNC(mi->avg_ampdu_len); -- mi->sample_tries = 2; -+ mi->sample_tries = 1; - mi->sample_count--; - } + state->filter_wiphy = -1; + ret = nl80211_dump_wiphy_parse(skb, cb, state); + if (ret) { +@@ -6615,12 +6617,14 @@ EXPORT_SYMBOL(cfg80211_testmode_alloc_ev -@@ -536,7 +547,7 @@ minstrel_calc_retransmit(struct minstrel - mr->retry_updated = true; - - group = &minstrel_mcs_groups[index / MCS_GROUP_RATES]; -- tx_time_data = group->duration[index % MCS_GROUP_RATES] * ampdu_len; -+ tx_time_data = group->duration[index % MCS_GROUP_RATES] * ampdu_len / 1000; - - /* Contention time for first 2 tries */ - ctime = (t_slot * cw) >> 1; -@@ -616,6 +627,7 @@ minstrel_get_sample_rate(struct minstrel + void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) { - struct minstrel_rate_stats *mr; - struct minstrel_mcs_group_data *mg; -+ unsigned int sample_dur, sample_group; - int sample_idx = 0; - - if (mi->sample_wait > 0) { -@@ -626,39 +638,46 @@ minstrel_get_sample_rate(struct minstrel - if (!mi->sample_tries) - return -1; - -- mi->sample_tries--; - mg = &mi->groups[mi->sample_group]; - sample_idx = sample_table[mg->column][mg->index]; - mr = &mg->rates[sample_idx]; -- sample_idx += mi->sample_group * MCS_GROUP_RATES; -+ sample_group = mi->sample_group; -+ sample_idx += sample_group * MCS_GROUP_RATES; - minstrel_next_sample_idx(mi); - - /* - * Sampling might add some overhead (RTS, no aggregation) - * to the frame. Hence, don't use sampling for the currently -- * used max TP rate. -+ * used rates. - */ -- if (sample_idx == mi->max_tp_rate) -+ if (sample_idx == mi->max_tp_rate || -+ sample_idx == mi->max_tp_rate2 || -+ sample_idx == mi->max_prob_rate) - return -1; -+ - /* -- * When not using MRR, do not sample if the probability is already -- * higher than 95% to avoid wasting airtime -+ * Do not sample if the probability is already higher than 95% -+ * to avoid wasting airtime. - */ -- if (!mp->has_mrr && (mr->probability > MINSTREL_FRAC(95, 100))) -+ if (mr->probability > MINSTREL_FRAC(95, 100)) - return -1; - - /* - * Make sure that lower rates get sampled only occasionally, - * if the link is working perfectly. - */ -- if (minstrel_get_duration(sample_idx) > -- minstrel_get_duration(mi->max_tp_rate)) { -+ sample_dur = minstrel_get_duration(sample_idx); -+ if (sample_dur >= minstrel_get_duration(mi->max_tp_rate2) && -+ (mi->max_prob_streams < -+ minstrel_mcs_groups[sample_group].streams || -+ sample_dur >= minstrel_get_duration(mi->max_prob_rate))) { - if (mr->sample_skipped < 20) - return -1; - - if (mi->sample_slow++ > 2) - return -1; - } -+ mi->sample_tries--; - - return sample_idx; ++ struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; + void *hdr = ((void **)skb->cb)[1]; + struct nlattr *data = ((void **)skb->cb)[2]; + + nla_nest_end(skb, data); + genlmsg_end(skb, hdr); +- genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); ++ genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0, ++ nl80211_testmode_mcgrp.id, gfp); } ---- a/net/mac80211/rc80211_minstrel_ht.h -+++ b/net/mac80211/rc80211_minstrel_ht.h -@@ -16,11 +16,6 @@ - #define MINSTREL_MAX_STREAMS 3 - #define MINSTREL_STREAM_GROUPS 4 - --/* scaled fraction values */ --#define MINSTREL_SCALE 16 --#define MINSTREL_FRAC(val, div) (((val) << MINSTREL_SCALE) / div) --#define MINSTREL_TRUNC(val) ((val) >> MINSTREL_SCALE) -- - #define MCS_GROUP_RATES 8 - - struct mcs_group { -@@ -85,6 +80,7 @@ struct minstrel_ht_sta { - - /* best probability rate */ - unsigned int max_prob_rate; -+ unsigned int max_prob_streams; - - /* time of last status update */ - unsigned long stats_update; ---- a/drivers/net/wireless/ath/ath9k/ar9003_calib.c -+++ b/drivers/net/wireless/ath/ath9k/ar9003_calib.c -@@ -1023,6 +1023,7 @@ static bool ar9003_hw_init_cal(struct at - AR_PHY_AGC_CONTROL_FLTR_CAL | - AR_PHY_AGC_CONTROL_PKDET_CAL; - -+ /* Use chip chainmask only for calibration */ - ar9003_hw_set_chain_masks(ah, ah->caps.rx_chainmask, ah->caps.tx_chainmask); - - if (rtt) { -@@ -1150,6 +1151,9 @@ skip_tx_iqcal: - ar9003_hw_rtt_disable(ah); - } - -+ /* Revert chainmask to runtime parameters */ -+ ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask); -+ - /* Initialize list pointers */ - ah->cal_list = ah->cal_list_last = ah->cal_list_curr = NULL; - ---- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c -+++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c -@@ -3606,6 +3606,12 @@ static void ar9003_hw_ant_ctrl_apply(str - value = ar9003_hw_ant_ctrl_common_2_get(ah, is2ghz); - REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2, AR_SWITCH_TABLE_COM2_ALL, value); - -+ if ((AR_SREV_9462(ah)) && (ah->rxchainmask == 0x2)) { -+ value = ar9003_hw_ant_ctrl_chain_get(ah, 1, is2ghz); -+ REG_RMW_FIELD(ah, switch_chain_reg[0], -+ AR_SWITCH_TABLE_ALL, value); -+ } -+ - for (chain = 0; chain < AR9300_MAX_CHAINS; chain++) { - if ((ah->rxchainmask & BIT(chain)) || - (ah->txchainmask & BIT(chain))) { -@@ -3772,6 +3778,17 @@ static void ar9003_hw_atten_apply(struct - AR_PHY_EXT_ATTEN_CTL_2, - }; - -+ if ((AR_SREV_9462(ah)) && (ah->rxchainmask == 0x2)) { -+ value = ar9003_hw_atten_chain_get(ah, 1, chan); -+ REG_RMW_FIELD(ah, ext_atten_reg[0], -+ AR_PHY_EXT_ATTEN_CTL_XATTEN1_DB, value); -+ -+ value = ar9003_hw_atten_chain_get_margin(ah, 1, chan); -+ REG_RMW_FIELD(ah, ext_atten_reg[0], -+ AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN, -+ value); -+ } -+ - /* Test value. if 0 then attenuation is unused. Don't load anything. */ - for (i = 0; i < 3; i++) { - if (ah->txchainmask & BIT(i)) { ---- a/drivers/net/wireless/ath/ath9k/link.c -+++ b/drivers/net/wireless/ath/ath9k/link.c -@@ -28,21 +28,21 @@ void ath_tx_complete_poll_work(struct wo - int i; - bool needreset = false; - -- for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) -- if (ATH_TXQ_SETUP(sc, i)) { -- txq = &sc->tx.txq[i]; -- ath_txq_lock(sc, txq); -- if (txq->axq_depth) { -- if (txq->axq_tx_inprogress) { -- needreset = true; -- ath_txq_unlock(sc, txq); -- break; -- } else { -- txq->axq_tx_inprogress = true; -- } -+ for (i = 0; i < IEEE80211_NUM_ACS; i++) { -+ txq = sc->tx.txq_map[i]; -+ -+ ath_txq_lock(sc, txq); -+ if (txq->axq_depth) { -+ if (txq->axq_tx_inprogress) { -+ needreset = true; -+ ath_txq_unlock(sc, txq); -+ break; -+ } else { -+ txq->axq_tx_inprogress = true; - } -- ath_txq_unlock_complete(sc, txq); + EXPORT_SYMBOL(cfg80211_testmode_event); + #endif +@@ -7593,12 +7597,11 @@ static int nl80211_send_wowlan_patterns( + if (!nl_pat) + return -ENOBUFS; + pat_len = wowlan->patterns[i].pattern_len; +- if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, +- DIV_ROUND_UP(pat_len, 8), ++ if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), + wowlan->patterns[i].mask) || +- nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, +- pat_len, wowlan->patterns[i].pattern) || +- nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET, ++ nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, ++ wowlan->patterns[i].pattern) || ++ nla_put_u32(msg, NL80211_PKTPAT_OFFSET, + wowlan->patterns[i].pkt_offset)) + return -ENOBUFS; + nla_nest_end(msg, nl_pat); +@@ -7939,7 +7942,7 @@ static int nl80211_set_wowlan(struct sk_ + struct nlattr *pat; + int n_patterns = 0; + int rem, pat_len, mask_len, pkt_offset; +- struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; ++ struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; + + nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], + rem) +@@ -7958,26 +7961,25 @@ static int nl80211_set_wowlan(struct sk_ + + nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], + rem) { +- nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, +- nla_data(pat), nla_len(pat), NULL); ++ nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), ++ nla_len(pat), NULL); + err = -EINVAL; +- if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || +- !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) ++ if (!pat_tb[NL80211_PKTPAT_MASK] || ++ !pat_tb[NL80211_PKTPAT_PATTERN]) + goto error; +- pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); ++ pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); + mask_len = DIV_ROUND_UP(pat_len, 8); +- if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != +- mask_len) ++ if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) + goto error; + if (pat_len > wowlan->pattern_max_len || + pat_len < wowlan->pattern_min_len) + goto error; + +- if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]) ++ if (!pat_tb[NL80211_PKTPAT_OFFSET]) + pkt_offset = 0; + else + pkt_offset = nla_get_u32( +- pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]); ++ pat_tb[NL80211_PKTPAT_OFFSET]); + if (pkt_offset > wowlan->max_pkt_offset) + goto error; + new_triggers.patterns[i].pkt_offset = pkt_offset; +@@ -7991,11 +7993,11 @@ static int nl80211_set_wowlan(struct sk_ + new_triggers.patterns[i].pattern = + new_triggers.patterns[i].mask + mask_len; + memcpy(new_triggers.patterns[i].mask, +- nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), ++ nla_data(pat_tb[NL80211_PKTPAT_MASK]), + mask_len); + new_triggers.patterns[i].pattern_len = pat_len; + memcpy(new_triggers.patterns[i].pattern, +- nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), ++ nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), + pat_len); + i++; } -+ ath_txq_unlock_complete(sc, txq); -+ } +@@ -10066,7 +10068,8 @@ void cfg80211_mgmt_tx_status(struct wire - if (needreset) { - ath_dbg(ath9k_hw_common(sc->sc_ah), RESET, ---- a/net/mac80211/sta_info.c -+++ b/net/mac80211/sta_info.c -@@ -766,6 +766,7 @@ int __must_check __sta_info_destroy(stru - struct ieee80211_local *local; - struct ieee80211_sub_if_data *sdata; - int ret, i; -+ bool have_key = false; + genlmsg_end(msg, hdr); - might_sleep(); +- genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); ++ genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, ++ nl80211_mlme_mcgrp.id, gfp); + return; -@@ -793,12 +794,19 @@ int __must_check __sta_info_destroy(stru - list_del_rcu(&sta->list); - - mutex_lock(&local->key_mtx); -- for (i = 0; i < NUM_DEFAULT_KEYS; i++) -+ for (i = 0; i < NUM_DEFAULT_KEYS; i++) { - __ieee80211_key_free(key_mtx_dereference(local, sta->gtk[i])); -- if (sta->ptk) -+ have_key = true; -+ } -+ if (sta->ptk) { - __ieee80211_key_free(key_mtx_dereference(local, sta->ptk)); -+ have_key = true; -+ } - mutex_unlock(&local->key_mtx); - -+ if (!have_key) -+ synchronize_net(); -+ - sta->dead = true; - - local->num_sta--; ---- a/net/mac80211/chan.c -+++ b/net/mac80211/chan.c -@@ -63,6 +63,7 @@ ieee80211_new_chanctx(struct ieee80211_l - enum ieee80211_chanctx_mode mode) + nla_put_failure: +--- a/net/wireless/reg.c ++++ b/net/wireless/reg.c +@@ -2279,7 +2279,9 @@ void wiphy_regulatory_deregister(struct + static void reg_timeout_work(struct work_struct *work) { - struct ieee80211_chanctx *ctx; -+ u32 changed; - int err; - - lockdep_assert_held(&local->chanctx_mtx); -@@ -76,6 +77,13 @@ ieee80211_new_chanctx(struct ieee80211_l - ctx->conf.rx_chains_dynamic = 1; - ctx->mode = mode; - -+ /* acquire mutex to prevent idle from changing */ -+ mutex_lock(&local->mtx); -+ /* turn idle off *before* setting channel -- some drivers need that */ -+ changed = ieee80211_idle_off(local); -+ if (changed) -+ ieee80211_hw_config(local, changed); -+ - if (!local->use_chanctx) { - local->_oper_channel_type = - cfg80211_get_chandef_type(chandef); -@@ -85,14 +93,17 @@ ieee80211_new_chanctx(struct ieee80211_l - err = drv_add_chanctx(local, ctx); - if (err) { - kfree(ctx); -- return ERR_PTR(err); -+ ctx = ERR_PTR(err); -+ -+ ieee80211_recalc_idle(local); -+ goto out; - } - } - -+ /* and keep the mutex held until the new chanctx is on the list */ - list_add_rcu(&ctx->list, &local->chanctx_list); - -- mutex_lock(&local->mtx); -- ieee80211_recalc_idle(local); -+ out: - mutex_unlock(&local->mtx); - - return ctx; ---- a/net/mac80211/ieee80211_i.h -+++ b/net/mac80211/ieee80211_i.h -@@ -1366,6 +1366,7 @@ int ieee80211_if_change_type(struct ieee - enum nl80211_iftype type); - void ieee80211_if_remove(struct ieee80211_sub_if_data *sdata); - void ieee80211_remove_interfaces(struct ieee80211_local *local); -+u32 ieee80211_idle_off(struct ieee80211_local *local); - void ieee80211_recalc_idle(struct ieee80211_local *local); - void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata, - const int offset); ---- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c -+++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c -@@ -799,7 +799,7 @@ static int ath9k_init_firmware_version(s - * required version. - */ - if (priv->fw_version_major != MAJOR_VERSION_REQ || -- priv->fw_version_minor != MINOR_VERSION_REQ) { -+ priv->fw_version_minor < MINOR_VERSION_REQ) { - dev_err(priv->dev, "ath9k_htc: Please upgrade to FW version %d.%d\n", - MAJOR_VERSION_REQ, MINOR_VERSION_REQ); - return -EINVAL; ---- a/drivers/net/wireless/ath/ath9k/xmit.c -+++ b/drivers/net/wireless/ath/ath9k/xmit.c -@@ -516,8 +516,7 @@ static void ath_tx_complete_aggr(struct - * not a holding desc. - */ - INIT_LIST_HEAD(&bf_head); -- if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) || -- bf_next != NULL || !bf_last->bf_stale) -+ if (bf_next != NULL || !bf_last->bf_stale) - list_move_tail(&bf->list, &bf_head); - - if (!txpending || (tid->state & AGGR_CLEANUP)) { -@@ -537,8 +536,7 @@ static void ath_tx_complete_aggr(struct - !txfail); - } else { - /* retry the un-acked ones */ -- if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_EDMA) && -- bf->bf_next == NULL && bf_last->bf_stale) { -+ if (bf->bf_next == NULL && bf_last->bf_stale) { - struct ath_buf *tbf; - - tbf = ath_clone_txbuf(sc, bf_last); -@@ -2264,6 +2262,7 @@ void ath_tx_edma_tasklet(struct ath_soft - struct ath_txq *txq; - struct ath_buf *bf, *lastbf; - struct list_head bf_head; -+ struct list_head *fifo_list; - int status; - - for (;;) { -@@ -2291,20 +2290,24 @@ void ath_tx_edma_tasklet(struct ath_soft - - TX_STAT_INC(txq->axq_qnum, txprocdesc); - -- if (list_empty(&txq->txq_fifo[txq->txq_tailidx])) { -+ fifo_list = &txq->txq_fifo[txq->txq_tailidx]; -+ if (list_empty(fifo_list)) { - ath_txq_unlock(sc, txq); - return; - } - -- bf = list_first_entry(&txq->txq_fifo[txq->txq_tailidx], -- struct ath_buf, list); -+ bf = list_first_entry(fifo_list, struct ath_buf, list); -+ if (bf->bf_stale) { -+ list_del(&bf->list); -+ ath_tx_return_buffer(sc, bf); -+ bf = list_first_entry(fifo_list, struct ath_buf, list); -+ } -+ - lastbf = bf->bf_lastbf; - - INIT_LIST_HEAD(&bf_head); -- list_cut_position(&bf_head, &txq->txq_fifo[txq->txq_tailidx], -- &lastbf->list); -- -- if (list_empty(&txq->txq_fifo[txq->txq_tailidx])) { -+ if (list_is_last(&lastbf->list, fifo_list)) { -+ list_splice_tail_init(fifo_list, &bf_head); - INCR(txq->txq_tailidx, ATH_TXFIFO_DEPTH); - - if (!list_empty(&txq->axq_q)) { -@@ -2315,6 +2318,11 @@ void ath_tx_edma_tasklet(struct ath_soft - list_splice_tail_init(&txq->axq_q, &bf_q); - ath_tx_txqaddbuf(sc, txq, &bf_q, true); - } -+ } else { -+ lastbf->bf_stale = true; -+ if (bf != lastbf) -+ list_cut_position(&bf_head, fifo_list, -+ lastbf->list.prev); - } - - ath_tx_process_buffer(sc, txq, &ts, bf, &bf_head); ---- a/drivers/net/wireless/ath/ath9k/ar9580_1p0_initvals.h -+++ b/drivers/net/wireless/ath/ath9k/ar9580_1p0_initvals.h -@@ -519,7 +519,7 @@ static const u32 ar9580_1p0_mac_core[][2 - {0x00008258, 0x00000000}, - {0x0000825c, 0x40000000}, - {0x00008260, 0x00080922}, -- {0x00008264, 0x9bc00010}, -+ {0x00008264, 0x9d400010}, - {0x00008268, 0xffffffff}, - {0x0000826c, 0x0000ffff}, - {0x00008270, 0x00000000}, ---- a/net/mac80211/mlme.c -+++ b/net/mac80211/mlme.c -@@ -3955,8 +3955,16 @@ int ieee80211_mgd_auth(struct ieee80211_ - /* prep auth_data so we don't go into idle on disassoc */ - ifmgd->auth_data = auth_data; - -- if (ifmgd->associated) -- ieee80211_set_disassoc(sdata, 0, 0, false, NULL); -+ if (ifmgd->associated) { -+ u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; -+ -+ ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, -+ WLAN_REASON_UNSPECIFIED, -+ false, frame_buf); -+ -+ __cfg80211_send_deauth(sdata->dev, frame_buf, -+ sizeof(frame_buf)); -+ } - - sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid); - -@@ -4016,8 +4024,16 @@ int ieee80211_mgd_assoc(struct ieee80211 - - mutex_lock(&ifmgd->mtx); - -- if (ifmgd->associated) -- ieee80211_set_disassoc(sdata, 0, 0, false, NULL); -+ if (ifmgd->associated) { -+ u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; -+ -+ ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, -+ WLAN_REASON_UNSPECIFIED, -+ false, frame_buf); -+ -+ __cfg80211_send_deauth(sdata->dev, frame_buf, -+ sizeof(frame_buf)); -+ } - - if (ifmgd->auth_data && !ifmgd->auth_data->done) { - err = -EBUSY; ---- a/net/mac80211/rc80211_minstrel.c -+++ b/net/mac80211/rc80211_minstrel.c -@@ -55,7 +55,6 @@ - #include "rate.h" - #include "rc80211_minstrel.h" - --#define SAMPLE_COLUMNS 10 - #define SAMPLE_TBL(_mi, _idx, _col) \ - _mi->sample_table[(_idx * SAMPLE_COLUMNS) + _col] - -@@ -70,16 +69,31 @@ rix_to_ndx(struct minstrel_sta_info *mi, - return i; + REG_DBG_PRINT("Timeout while waiting for CRDA to reply, restoring regulatory settings\n"); ++ rtnl_lock(); + restore_regulatory_settings(true); ++ rtnl_unlock(); } -+/* find & sort topmost throughput rates */ -+static inline void -+minstrel_sort_best_tp_rates(struct minstrel_sta_info *mi, int i, u8 *tp_list) -+{ -+ int j = MAX_THR_RATES; -+ -+ while (j > 0 && mi->r[i].cur_tp > mi->r[tp_list[j - 1]].cur_tp) -+ j--; -+ if (j < MAX_THR_RATES - 1) -+ memmove(&tp_list[j + 1], &tp_list[j], MAX_THR_RATES - (j + 1)); -+ if (j < MAX_THR_RATES) -+ tp_list[j] = i; -+} -+ - static void - minstrel_update_stats(struct minstrel_priv *mp, struct minstrel_sta_info *mi) - { -- u32 max_tp = 0, index_max_tp = 0, index_max_tp2 = 0; -- u32 max_prob = 0, index_max_prob = 0; -+ u8 tmp_tp_rate[MAX_THR_RATES]; -+ u8 tmp_prob_rate = 0; - u32 usecs; -- u32 p; - int i; - -- mi->stats_update = jiffies; -+ for (i=0; i < MAX_THR_RATES; i++) -+ tmp_tp_rate[i] = 0; -+ - for (i = 0; i < mi->n_rates; i++) { - struct minstrel_rate *mr = &mi->r[i]; - -@@ -87,27 +101,32 @@ minstrel_update_stats(struct minstrel_pr - if (!usecs) - usecs = 1000000; - -- /* To avoid rounding issues, probabilities scale from 0 (0%) -- * to 18000 (100%) */ -- if (mr->attempts) { -- p = (mr->success * 18000) / mr->attempts; -+ if (unlikely(mr->attempts > 0)) { -+ mr->sample_skipped = 0; -+ mr->cur_prob = MINSTREL_FRAC(mr->success, mr->attempts); - mr->succ_hist += mr->success; - mr->att_hist += mr->attempts; -- mr->cur_prob = p; -- p = ((p * (100 - mp->ewma_level)) + (mr->probability * -- mp->ewma_level)) / 100; -- mr->probability = p; -- mr->cur_tp = p * (1000000 / usecs); -- } -+ mr->probability = minstrel_ewma(mr->probability, -+ mr->cur_prob, -+ EWMA_LEVEL); -+ } else -+ mr->sample_skipped++; - - mr->last_success = mr->success; - mr->last_attempts = mr->attempts; - mr->success = 0; - mr->attempts = 0; - -+ /* Update throughput per rate, reset thr. below 10% success */ -+ if (mr->probability < MINSTREL_FRAC(10, 100)) -+ mr->cur_tp = 0; -+ else -+ mr->cur_tp = mr->probability * (1000000 / usecs); -+ - /* Sample less often below the 10% chance of success. - * Sample less often above the 95% chance of success. */ -- if ((mr->probability > 17100) || (mr->probability < 1800)) { -+ if (mr->probability > MINSTREL_FRAC(95, 100) || -+ mr->probability < MINSTREL_FRAC(10, 100)) { - mr->adjusted_retry_count = mr->retry_count >> 1; - if (mr->adjusted_retry_count > 2) - mr->adjusted_retry_count = 2; -@@ -118,35 +137,30 @@ minstrel_update_stats(struct minstrel_pr - } - if (!mr->adjusted_retry_count) - mr->adjusted_retry_count = 2; -- } - -- for (i = 0; i < mi->n_rates; i++) { -- struct minstrel_rate *mr = &mi->r[i]; -- if (max_tp < mr->cur_tp) { -- index_max_tp = i; -- max_tp = mr->cur_tp; -- } -- if (max_prob < mr->probability) { -- index_max_prob = i; -- max_prob = mr->probability; -+ minstrel_sort_best_tp_rates(mi, i, tmp_tp_rate); -+ -+ /* To determine the most robust rate (max_prob_rate) used at -+ * 3rd mmr stage we distinct between two cases: -+ * (1) if any success probabilitiy >= 95%, out of those rates -+ * choose the maximum throughput rate as max_prob_rate -+ * (2) if all success probabilities < 95%, the rate with -+ * highest success probability is choosen as max_prob_rate */ -+ if (mr->probability >= MINSTREL_FRAC(95,100)) { -+ if (mr->cur_tp >= mi->r[tmp_prob_rate].cur_tp) -+ tmp_prob_rate = i; -+ } else { -+ if (mr->probability >= mi->r[tmp_prob_rate].probability) -+ tmp_prob_rate = i; - } + int __init regulatory_init(void) +--- a/net/wireless/sme.c ++++ b/net/wireless/sme.c +@@ -34,8 +34,10 @@ struct cfg80211_conn { + CFG80211_CONN_SCAN_AGAIN, + CFG80211_CONN_AUTHENTICATE_NEXT, + CFG80211_CONN_AUTHENTICATING, ++ CFG80211_CONN_AUTH_FAILED, + CFG80211_CONN_ASSOCIATE_NEXT, + CFG80211_CONN_ASSOCIATING, ++ CFG80211_CONN_ASSOC_FAILED, + CFG80211_CONN_DEAUTH, + CFG80211_CONN_CONNECTED, + } state; +@@ -164,6 +166,8 @@ static int cfg80211_conn_do_work(struct + NULL, 0, + params->key, params->key_len, + params->key_idx, NULL, 0); ++ case CFG80211_CONN_AUTH_FAILED: ++ return -ENOTCONN; + case CFG80211_CONN_ASSOCIATE_NEXT: + BUG_ON(!rdev->ops->assoc); + wdev->conn->state = CFG80211_CONN_ASSOCIATING; +@@ -188,10 +192,17 @@ static int cfg80211_conn_do_work(struct + WLAN_REASON_DEAUTH_LEAVING, + false); + return err; ++ case CFG80211_CONN_ASSOC_FAILED: ++ cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, ++ NULL, 0, ++ WLAN_REASON_DEAUTH_LEAVING, false); ++ return -ENOTCONN; + case CFG80211_CONN_DEAUTH: + cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid, + NULL, 0, + WLAN_REASON_DEAUTH_LEAVING, false); ++ /* free directly, disconnected event already sent */ ++ cfg80211_sme_free(wdev); + return 0; + default: + return 0; +@@ -371,7 +382,7 @@ bool cfg80211_sme_rx_assoc_resp(struct w + return true; } -- max_tp = 0; -- for (i = 0; i < mi->n_rates; i++) { -- struct minstrel_rate *mr = &mi->r[i]; -- -- if (i == index_max_tp) -- continue; -+ /* Assign the new rate set */ -+ memcpy(mi->max_tp_rate, tmp_tp_rate, sizeof(mi->max_tp_rate)); -+ mi->max_prob_rate = tmp_prob_rate; - -- if (max_tp < mr->cur_tp) { -- index_max_tp2 = i; -- max_tp = mr->cur_tp; -- } -- } -- mi->max_tp_rate = index_max_tp; -- mi->max_tp_rate2 = index_max_tp2; -- mi->max_prob_rate = index_max_prob; -+ /* Reset update timer */ -+ mi->stats_update = jiffies; +- wdev->conn->state = CFG80211_CONN_DEAUTH; ++ wdev->conn->state = CFG80211_CONN_ASSOC_FAILED; + schedule_work(&rdev->conn_work); + return false; } +@@ -383,7 +394,13 @@ void cfg80211_sme_deauth(struct wireless - static void -@@ -207,10 +221,10 @@ static int - minstrel_get_next_sample(struct minstrel_sta_info *mi) + void cfg80211_sme_auth_timeout(struct wireless_dev *wdev) { - unsigned int sample_ndx; -- sample_ndx = SAMPLE_TBL(mi, mi->sample_idx, mi->sample_column); -- mi->sample_idx++; -- if ((int) mi->sample_idx > (mi->n_rates - 2)) { -- mi->sample_idx = 0; -+ sample_ndx = SAMPLE_TBL(mi, mi->sample_row, mi->sample_column); -+ mi->sample_row++; -+ if ((int) mi->sample_row >= mi->n_rates) { -+ mi->sample_row = 0; - mi->sample_column++; - if (mi->sample_column >= SAMPLE_COLUMNS) - mi->sample_column = 0; -@@ -228,31 +242,37 @@ minstrel_get_rate(void *priv, struct iee - struct minstrel_priv *mp = priv; - struct ieee80211_tx_rate *ar = info->control.rates; - unsigned int ndx, sample_ndx = 0; -- bool mrr; -- bool sample_slower = false; -- bool sample = false; -+ bool mrr_capable; -+ bool indirect_rate_sampling = false; -+ bool rate_sampling = false; - int i, delta; - int mrr_ndx[3]; -- int sample_rate; -+ int sampling_ratio; - -+ /* management/no-ack frames do not use rate control */ - if (rate_control_send_low(sta, priv_sta, txrc)) - return; - -- mrr = mp->has_mrr && !txrc->rts && !txrc->bss_conf->use_cts_prot; -- -- ndx = mi->max_tp_rate; -- -- if (mrr) -- sample_rate = mp->lookaround_rate_mrr; -+ /* check multi-rate-retry capabilities & adjust lookaround_rate */ -+ mrr_capable = mp->has_mrr && -+ !txrc->rts && -+ !txrc->bss_conf->use_cts_prot; -+ if (mrr_capable) -+ sampling_ratio = mp->lookaround_rate_mrr; - else -- sample_rate = mp->lookaround_rate; -+ sampling_ratio = mp->lookaround_rate; -+ -+ /* init rateindex [ndx] with max throughput rate */ -+ ndx = mi->max_tp_rate[0]; - -+ /* increase sum packet counter */ - mi->packet_count++; -- delta = (mi->packet_count * sample_rate / 100) - -+ -+ delta = (mi->packet_count * sampling_ratio / 100) - - (mi->sample_count + mi->sample_deferred / 2); - - /* delta > 0: sampling required */ -- if ((delta > 0) && (mrr || !mi->prev_sample)) { -+ if ((delta > 0) && (mrr_capable || !mi->prev_sample)) { - struct minstrel_rate *msr; - if (mi->packet_count >= 10000) { - mi->sample_deferred = 0; -@@ -271,21 +291,28 @@ minstrel_get_rate(void *priv, struct iee - mi->sample_count += (delta - mi->n_rates * 2); - } - -+ /* get next random rate sample */ - sample_ndx = minstrel_get_next_sample(mi); - msr = &mi->r[sample_ndx]; -- sample = true; -- sample_slower = mrr && (msr->perfect_tx_time > -- mi->r[ndx].perfect_tx_time); -+ rate_sampling = true; - -- if (!sample_slower) { -+ /* Decide if direct ( 1st mrr stage) or indirect (2nd mrr stage) -+ * rate sampling method should be used. -+ * Respect such rates that are not sampled for 20 interations. -+ */ -+ if (mrr_capable && -+ msr->perfect_tx_time > mi->r[ndx].perfect_tx_time && -+ msr->sample_skipped < 20) -+ indirect_rate_sampling = true; +- cfg80211_sme_free(wdev); ++ struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); + -+ if (!indirect_rate_sampling) { - if (msr->sample_limit != 0) { - ndx = sample_ndx; - mi->sample_count++; - if (msr->sample_limit > 0) - msr->sample_limit--; -- } else { -- sample = false; -- } -+ } else -+ rate_sampling = false; - } else { - /* Only use IEEE80211_TX_CTL_RATE_CTRL_PROBE to mark - * packets that have the sampling rate deferred to the -@@ -297,34 +324,39 @@ minstrel_get_rate(void *priv, struct iee - mi->sample_deferred++; - } - } -- mi->prev_sample = sample; -+ mi->prev_sample = rate_sampling; - - /* If we're not using MRR and the sampling rate already - * has a probability of >95%, we shouldn't be attempting - * to use it, as this only wastes precious airtime */ -- if (!mrr && sample && (mi->r[ndx].probability > 17100)) -- ndx = mi->max_tp_rate; -+ if (!mrr_capable && rate_sampling && -+ (mi->r[ndx].probability > MINSTREL_FRAC(95, 100))) -+ ndx = mi->max_tp_rate[0]; - -+ /* mrr setup for 1st stage */ - ar[0].idx = mi->r[ndx].rix; - ar[0].count = minstrel_get_retry_count(&mi->r[ndx], info); - -- if (!mrr) { -- if (!sample) -+ /* non mrr setup for 2nd stage */ -+ if (!mrr_capable) { -+ if (!rate_sampling) - ar[0].count = mp->max_retry; - ar[1].idx = mi->lowest_rix; - ar[1].count = mp->max_retry; - return; - } - -- /* MRR setup */ -- if (sample) { -- if (sample_slower) -+ /* mrr setup for 2nd stage */ -+ if (rate_sampling) { -+ if (indirect_rate_sampling) - mrr_ndx[0] = sample_ndx; - else -- mrr_ndx[0] = mi->max_tp_rate; -+ mrr_ndx[0] = mi->max_tp_rate[0]; - } else { -- mrr_ndx[0] = mi->max_tp_rate2; -+ mrr_ndx[0] = mi->max_tp_rate[1]; - } ++ if (!wdev->conn) ++ return; + -+ /* mrr setup for 3rd & 4th stage */ - mrr_ndx[1] = mi->max_prob_rate; - mrr_ndx[2] = 0; - for (i = 1; i < 4; i++) { -@@ -351,26 +383,21 @@ static void - init_sample_table(struct minstrel_sta_info *mi) - { - unsigned int i, col, new_idx; -- unsigned int n_srates = mi->n_rates - 1; - u8 rnd[8]; - - mi->sample_column = 0; -- mi->sample_idx = 0; -- memset(mi->sample_table, 0, SAMPLE_COLUMNS * mi->n_rates); -+ mi->sample_row = 0; -+ memset(mi->sample_table, 0xff, SAMPLE_COLUMNS * mi->n_rates); - - for (col = 0; col < SAMPLE_COLUMNS; col++) { -- for (i = 0; i < n_srates; i++) { -+ for (i = 0; i < mi->n_rates; i++) { - get_random_bytes(rnd, sizeof(rnd)); -- new_idx = (i + rnd[i & 7]) % n_srates; -+ new_idx = (i + rnd[i & 7]) % mi->n_rates; - -- while (SAMPLE_TBL(mi, new_idx, col) != 0) -- new_idx = (new_idx + 1) % n_srates; -+ while (SAMPLE_TBL(mi, new_idx, col) != 0xff) -+ new_idx = (new_idx + 1) % mi->n_rates; - -- /* Don't sample the slowest rate (i.e. slowest base -- * rate). We must presume that the slowest rate works -- * fine, or else other management frames will also be -- * failing and the link will break */ -- SAMPLE_TBL(mi, new_idx, col) = i + 1; -+ SAMPLE_TBL(mi, new_idx, col) = i; - } - } ++ wdev->conn->state = CFG80211_CONN_AUTH_FAILED; ++ schedule_work(&rdev->conn_work); } -@@ -542,9 +569,6 @@ minstrel_alloc(struct ieee80211_hw *hw, - mp->lookaround_rate = 5; - mp->lookaround_rate_mrr = 10; - -- /* moving average weight for EWMA */ -- mp->ewma_level = 75; -- - /* maximum time that the hw is allowed to stay in one MRR segment */ - mp->segment_size = 6000; - ---- a/net/mac80211/rc80211_minstrel.h -+++ b/net/mac80211/rc80211_minstrel.h -@@ -9,6 +9,28 @@ - #ifndef __RC_MINSTREL_H - #define __RC_MINSTREL_H - -+#define EWMA_LEVEL 75 /* ewma weighting factor [%] */ -+#define SAMPLE_COLUMNS 10 /* number of columns in sample table */ -+ -+ -+/* scaled fraction values */ -+#define MINSTREL_SCALE 16 -+#define MINSTREL_FRAC(val, div) (((val) << MINSTREL_SCALE) / div) -+#define MINSTREL_TRUNC(val) ((val) >> MINSTREL_SCALE) -+ -+/* number of highest throughput rates to consider*/ -+#define MAX_THR_RATES 4 -+ -+/* -+ * Perform EWMA (Exponentially Weighted Moving Average) calculation -+ */ -+static inline int -+minstrel_ewma(int old, int new, int weight) -+{ -+ return (new * (100 - weight) + old * weight) / 100; -+} -+ -+ - struct minstrel_rate { - int bitrate; - int rix; -@@ -26,6 +48,7 @@ struct minstrel_rate { - u32 attempts; - u32 last_attempts; - u32 last_success; -+ u8 sample_skipped; - /* parts per thousand */ - u32 cur_prob; -@@ -45,14 +68,13 @@ struct minstrel_sta_info { + void cfg80211_sme_disassoc(struct wireless_dev *wdev) +@@ -399,7 +416,13 @@ void cfg80211_sme_disassoc(struct wirele - unsigned int lowest_rix; - -- unsigned int max_tp_rate; -- unsigned int max_tp_rate2; -- unsigned int max_prob_rate; -+ u8 max_tp_rate[MAX_THR_RATES]; -+ u8 max_prob_rate; - unsigned int packet_count; - unsigned int sample_count; - int sample_deferred; - -- unsigned int sample_idx; -+ unsigned int sample_row; - unsigned int sample_column; - - int n_rates; -@@ -73,7 +95,6 @@ struct minstrel_priv { - unsigned int cw_min; - unsigned int cw_max; - unsigned int max_retry; -- unsigned int ewma_level; - unsigned int segment_size; - unsigned int update_interval; - unsigned int lookaround_rate; ---- a/net/mac80211/rc80211_minstrel_debugfs.c -+++ b/net/mac80211/rc80211_minstrel_debugfs.c -@@ -73,15 +73,17 @@ minstrel_stats_open(struct inode *inode, - for (i = 0; i < mi->n_rates; i++) { - struct minstrel_rate *mr = &mi->r[i]; - -- *(p++) = (i == mi->max_tp_rate) ? 'T' : ' '; -- *(p++) = (i == mi->max_tp_rate2) ? 't' : ' '; -+ *(p++) = (i == mi->max_tp_rate[0]) ? 'A' : ' '; -+ *(p++) = (i == mi->max_tp_rate[1]) ? 'B' : ' '; -+ *(p++) = (i == mi->max_tp_rate[2]) ? 'C' : ' '; -+ *(p++) = (i == mi->max_tp_rate[3]) ? 'D' : ' '; - *(p++) = (i == mi->max_prob_rate) ? 'P' : ' '; - p += sprintf(p, "%3u%s", mr->bitrate / 2, - (mr->bitrate & 1 ? ".5" : " ")); - -- tp = mr->cur_tp / ((18000 << 10) / 96); -- prob = mr->cur_prob / 18; -- eprob = mr->probability / 18; -+ tp = MINSTREL_TRUNC(mr->cur_tp / 10); -+ prob = MINSTREL_TRUNC(mr->cur_prob * 1000); -+ eprob = MINSTREL_TRUNC(mr->probability * 1000); - - p += sprintf(p, " %6u.%1u %6u.%1u %6u.%1u " - "%3u(%3u) %8llu %8llu\n", ---- a/drivers/net/wireless/ath/ath9k/ath9k.h -+++ b/drivers/net/wireless/ath/ath9k/ath9k.h -@@ -657,11 +657,10 @@ enum sc_op_flags { - struct ath_rate_table; - - struct ath9k_vif_iter_data { -- const u8 *hw_macaddr; /* phy's hardware address, set -- * before starting iteration for -- * valid bssid mask. -- */ -+ u8 hw_macaddr[ETH_ALEN]; /* address of the first vif */ - u8 mask[ETH_ALEN]; /* bssid mask */ -+ bool has_hw_macaddr; + void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev) + { +- cfg80211_sme_disassoc(wdev); ++ struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); + - int naps; /* number of AP vifs */ - int nmeshes; /* number of mesh vifs */ - int nstations; /* number of station vifs */ ---- a/drivers/net/wireless/ath/ath9k/main.c -+++ b/drivers/net/wireless/ath/ath9k/main.c -@@ -835,10 +835,14 @@ static void ath9k_vif_iter(void *data, u - struct ath9k_vif_iter_data *iter_data = data; - int i; - -- if (iter_data->hw_macaddr) -+ if (iter_data->has_hw_macaddr) { - for (i = 0; i < ETH_ALEN; i++) - iter_data->mask[i] &= - ~(iter_data->hw_macaddr[i] ^ mac[i]); -+ } else { -+ memcpy(iter_data->hw_macaddr, mac, ETH_ALEN); -+ iter_data->has_hw_macaddr = true; -+ } - - switch (vif->type) { - case NL80211_IFTYPE_AP: -@@ -887,7 +891,6 @@ void ath9k_calculate_iter_data(struct ie - * together with the BSSID mask when matching addresses. - */ - memset(iter_data, 0, sizeof(*iter_data)); -- iter_data->hw_macaddr = common->macaddr; - memset(&iter_data->mask, 0xff, ETH_ALEN); - - if (vif) -@@ -897,6 +900,8 @@ void ath9k_calculate_iter_data(struct ie - ieee80211_iterate_active_interfaces_atomic( - sc->hw, IEEE80211_IFACE_ITER_RESUME_ALL, - ath9k_vif_iter, iter_data); ++ if (!wdev->conn) ++ return; + -+ memcpy(common->macaddr, iter_data->hw_macaddr, ETH_ALEN); ++ wdev->conn->state = CFG80211_CONN_ASSOC_FAILED; ++ schedule_work(&rdev->conn_work); } - /* Called with sc->mutex held. */ -@@ -1304,6 +1309,7 @@ static int ath9k_sta_add(struct ieee8021 - struct ath_common *common = ath9k_hw_common(sc->sc_ah); - struct ath_node *an = (struct ath_node *) sta->drv_priv; - struct ieee80211_key_conf ps_key = { }; -+ int key; - - ath_node_attach(sc, sta, vif); - -@@ -1311,7 +1317,9 @@ static int ath9k_sta_add(struct ieee8021 - vif->type != NL80211_IFTYPE_AP_VLAN) - return 0; - -- an->ps_key = ath_key_config(common, vif, sta, &ps_key); -+ key = ath_key_config(common, vif, sta, &ps_key); -+ if (key > 0) -+ an->ps_key = key; - - return 0; - } -@@ -1328,6 +1336,7 @@ static void ath9k_del_ps_key(struct ath_ - return; - - ath_key_delete(common, &ps_key); -+ an->ps_key = 0; - } - - static int ath9k_sta_remove(struct ieee80211_hw *hw, ---- a/drivers/net/wireless/ath/ath9k/reg.h -+++ b/drivers/net/wireless/ath/ath9k/reg.h -@@ -1493,9 +1493,6 @@ enum { - #define AR9271_RADIO_RF_RST 0x20 - #define AR9271_GATE_MAC_CTL 0x4000 - --#define AR_STA_ID0 0x8000 --#define AR_STA_ID1 0x8004 --#define AR_STA_ID1_SADH_MASK 0x0000FFFF - #define AR_STA_ID1_STA_AP 0x00010000 - #define AR_STA_ID1_ADHOC 0x00020000 - #define AR_STA_ID1_PWR_SAV 0x00040000 ---- a/drivers/net/wireless/ath/hw.c -+++ b/drivers/net/wireless/ath/hw.c -@@ -118,6 +118,12 @@ - void ath_hw_setbssidmask(struct ath_common *common) - { - void *ah = common->ah; -+ u32 id1; -+ -+ REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr)); -+ id1 = REG_READ(ah, AR_STA_ID1) & ~AR_STA_ID1_SADH_MASK; -+ id1 |= get_unaligned_le16(common->macaddr + 4); -+ REG_WRITE(ah, AR_STA_ID1, id1); - - REG_WRITE(ah, AR_BSSMSKL, get_unaligned_le32(common->bssidmask)); - REG_WRITE(ah, AR_BSSMSKU, get_unaligned_le16(common->bssidmask + 4)); ---- a/drivers/net/wireless/ath/reg.h -+++ b/drivers/net/wireless/ath/reg.h -@@ -23,6 +23,10 @@ - #define AR_MIBC_CMC 0x00000004 - #define AR_MIBC_MCS 0x00000008 - -+#define AR_STA_ID0 0x8000 -+#define AR_STA_ID1 0x8004 -+#define AR_STA_ID1_SADH_MASK 0x0000ffff -+ - /* - * BSSID mask registers. See ath_hw_set_bssid_mask() - * for detailed documentation about these registers. + static int cfg80211_sme_connect(struct wireless_dev *wdev, -- cgit v1.2.3