ath9k: add missing tx locking
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / 300-pending_work.patch
1 --- a/net/mac80211/agg-rx.c
2 +++ b/net/mac80211/agg-rx.c
3 @@ -204,6 +204,8 @@ static void ieee80211_send_addba_resp(st
4 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
5 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
6 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
7 + else if (sdata->vif.type == NL80211_IFTYPE_WDS)
8 + memcpy(mgmt->bssid, da, ETH_ALEN);
9
10 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
11 IEEE80211_STYPE_ACTION);
12 --- a/net/mac80211/agg-tx.c
13 +++ b/net/mac80211/agg-tx.c
14 @@ -81,7 +81,8 @@ static void ieee80211_send_addba_request
15 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
16 if (sdata->vif.type == NL80211_IFTYPE_AP ||
17 sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
18 - sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
19 + sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
20 + sdata->vif.type == NL80211_IFTYPE_WDS)
21 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
22 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
23 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
24 @@ -527,6 +528,7 @@ int ieee80211_start_tx_ba_session(struct
25 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
26 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
27 sdata->vif.type != NL80211_IFTYPE_AP &&
28 + sdata->vif.type != NL80211_IFTYPE_WDS &&
29 sdata->vif.type != NL80211_IFTYPE_ADHOC)
30 return -EINVAL;
31
32 --- a/net/mac80211/debugfs_sta.c
33 +++ b/net/mac80211/debugfs_sta.c
34 @@ -66,11 +66,11 @@ static ssize_t sta_flags_read(struct fil
35 test_sta_flag(sta, WLAN_STA_##flg) ? #flg "\n" : ""
36
37 int res = scnprintf(buf, sizeof(buf),
38 - "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
39 + "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
40 TEST(AUTH), TEST(ASSOC), TEST(PS_STA),
41 TEST(PS_DRIVER), TEST(AUTHORIZED),
42 TEST(SHORT_PREAMBLE),
43 - TEST(WME), TEST(WDS), TEST(CLEAR_PS_FILT),
44 + TEST(WME), TEST(CLEAR_PS_FILT),
45 TEST(MFP), TEST(BLOCK_BA), TEST(PSPOLL),
46 TEST(UAPSD), TEST(SP), TEST(TDLS_PEER),
47 TEST(TDLS_PEER_AUTH), TEST(4ADDR_EVENT),
48 @@ -455,6 +455,15 @@ void ieee80211_sta_debugfs_add(struct st
49 DEBUGFS_ADD_COUNTER(tx_retry_count, tx_retry_count);
50 DEBUGFS_ADD_COUNTER(wep_weak_iv_count, wep_weak_iv_count);
51
52 + if (sizeof(sta->driver_buffered_tids) == sizeof(u32))
53 + debugfs_create_x32("driver_buffered_tids", 0400,
54 + sta->debugfs.dir,
55 + (u32 *)&sta->driver_buffered_tids);
56 + else
57 + debugfs_create_x64("driver_buffered_tids", 0400,
58 + sta->debugfs.dir,
59 + (u64 *)&sta->driver_buffered_tids);
60 +
61 drv_sta_add_debugfs(local, sdata, &sta->sta, sta->debugfs.dir);
62 }
63
64 --- a/net/mac80211/iface.c
65 +++ b/net/mac80211/iface.c
66 @@ -274,6 +274,12 @@ static int ieee80211_check_concurrent_if
67 if (iftype == NL80211_IFTYPE_ADHOC &&
68 nsdata->vif.type == NL80211_IFTYPE_ADHOC)
69 return -EBUSY;
70 + /*
71 + * will not add another interface while any channel
72 + * switch is active.
73 + */
74 + if (nsdata->vif.csa_active)
75 + return -EBUSY;
76
77 /*
78 * The remaining checks are only performed for interfaces
79 @@ -463,7 +469,6 @@ int ieee80211_do_open(struct wireless_de
80 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
81 struct net_device *dev = wdev->netdev;
82 struct ieee80211_local *local = sdata->local;
83 - struct sta_info *sta;
84 u32 changed = 0;
85 int res;
86 u32 hw_reconf_flags = 0;
87 @@ -629,30 +634,8 @@ int ieee80211_do_open(struct wireless_de
88
89 set_bit(SDATA_STATE_RUNNING, &sdata->state);
90
91 - if (sdata->vif.type == NL80211_IFTYPE_WDS) {
92 - /* Create STA entry for the WDS peer */
93 - sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
94 - GFP_KERNEL);
95 - if (!sta) {
96 - res = -ENOMEM;
97 - goto err_del_interface;
98 - }
99 -
100 - sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
101 - sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
102 - sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
103 -
104 - res = sta_info_insert(sta);
105 - if (res) {
106 - /* STA has been freed */
107 - goto err_del_interface;
108 - }
109 -
110 - rate_control_rate_init(sta);
111 - netif_carrier_on(dev);
112 - } else if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
113 + if (sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE)
114 rcu_assign_pointer(local->p2p_sdata, sdata);
115 - }
116
117 /*
118 * set_multicast_list will be invoked by the networking core
119 @@ -809,6 +792,8 @@ static void ieee80211_do_stop(struct iee
120 cancel_work_sync(&local->dynamic_ps_enable_work);
121
122 cancel_work_sync(&sdata->recalc_smps);
123 + sdata->vif.csa_active = false;
124 + cancel_work_sync(&sdata->csa_finalize_work);
125
126 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
127
128 @@ -1116,6 +1101,74 @@ static void ieee80211_if_setup(struct ne
129 dev->destructor = free_netdev;
130 }
131
132 +static void ieee80211_wds_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
133 + struct sk_buff *skb)
134 +{
135 + struct ieee80211_local *local = sdata->local;
136 + struct ieee80211_rx_status *rx_status;
137 + struct ieee802_11_elems elems;
138 + struct ieee80211_mgmt *mgmt;
139 + struct sta_info *sta;
140 + size_t baselen;
141 + u32 rates = 0;
142 + u16 stype;
143 + bool new = false;
144 + enum ieee80211_band band;
145 + struct ieee80211_supported_band *sband;
146 +
147 + rx_status = IEEE80211_SKB_RXCB(skb);
148 + band = rx_status->band;
149 + sband = local->hw.wiphy->bands[band];
150 + mgmt = (struct ieee80211_mgmt *) skb->data;
151 + stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE;
152 +
153 + if (stype != IEEE80211_STYPE_BEACON)
154 + return;
155 +
156 + baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
157 + if (baselen > skb->len)
158 + return;
159 +
160 + ieee802_11_parse_elems(mgmt->u.probe_resp.variable,
161 + skb->len - baselen, false, &elems);
162 +
163 + rates = ieee80211_sta_get_rates(local, &elems, band, NULL);
164 +
165 + rcu_read_lock();
166 +
167 + sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
168 +
169 + if (!sta) {
170 + rcu_read_unlock();
171 + sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr,
172 + GFP_KERNEL);
173 + if (!sta)
174 + return;
175 +
176 + new = true;
177 + }
178 +
179 + sta->last_rx = jiffies;
180 + sta->sta.supp_rates[band] = rates;
181 +
182 + if (elems.ht_cap_elem)
183 + ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
184 + elems.ht_cap_elem, sta);
185 +
186 + if (elems.wmm_param)
187 + set_sta_flag(sta, WLAN_STA_WME);
188 +
189 + if (new) {
190 + sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
191 + sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
192 + sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED);
193 + rate_control_rate_init(sta);
194 + sta_info_insert_rcu(sta);
195 + }
196 +
197 + rcu_read_unlock();
198 +}
199 +
200 static void ieee80211_iface_work(struct work_struct *work)
201 {
202 struct ieee80211_sub_if_data *sdata =
203 @@ -1220,6 +1273,9 @@ static void ieee80211_iface_work(struct
204 break;
205 ieee80211_mesh_rx_queued_mgmt(sdata, skb);
206 break;
207 + case NL80211_IFTYPE_WDS:
208 + ieee80211_wds_rx_queued_mgmt(sdata, skb);
209 + break;
210 default:
211 WARN(1, "frame for unexpected interface type");
212 break;
213 @@ -1282,6 +1338,7 @@ static void ieee80211_setup_sdata(struct
214 skb_queue_head_init(&sdata->skb_queue);
215 INIT_WORK(&sdata->work, ieee80211_iface_work);
216 INIT_WORK(&sdata->recalc_smps, ieee80211_recalc_smps_work);
217 + INIT_WORK(&sdata->csa_finalize_work, ieee80211_csa_finalize_work);
218
219 switch (type) {
220 case NL80211_IFTYPE_P2P_GO:
221 --- a/net/mac80211/rc80211_minstrel_ht.c
222 +++ b/net/mac80211/rc80211_minstrel_ht.c
223 @@ -365,6 +365,14 @@ minstrel_ht_update_stats(struct minstrel
224 }
225 }
226
227 +#ifdef CPTCFG_MAC80211_DEBUGFS
228 + /* use fixed index if set */
229 + if (mp->fixed_rate_idx != -1) {
230 + mi->max_tp_rate = mp->fixed_rate_idx;
231 + mi->max_tp_rate2 = mp->fixed_rate_idx;
232 + mi->max_prob_rate = mp->fixed_rate_idx;
233 + }
234 +#endif
235
236 mi->stats_update = jiffies;
237 }
238 @@ -774,6 +782,11 @@ minstrel_ht_get_rate(void *priv, struct
239 info->flags |= mi->tx_flags;
240 minstrel_ht_check_cck_shortpreamble(mp, mi, txrc->short_preamble);
241
242 +#ifdef CPTCFG_MAC80211_DEBUGFS
243 + if (mp->fixed_rate_idx != -1)
244 + return;
245 +#endif
246 +
247 /* Don't use EAPOL frames for sampling on non-mrr hw */
248 if (mp->hw->max_rates == 1 &&
249 txrc->skb->protocol == cpu_to_be16(ETH_P_PAE))
250 @@ -781,16 +794,6 @@ minstrel_ht_get_rate(void *priv, struct
251 else
252 sample_idx = minstrel_get_sample_rate(mp, mi);
253
254 -#ifdef CPTCFG_MAC80211_DEBUGFS
255 - /* use fixed index if set */
256 - if (mp->fixed_rate_idx != -1) {
257 - mi->max_tp_rate = mp->fixed_rate_idx;
258 - mi->max_tp_rate2 = mp->fixed_rate_idx;
259 - mi->max_prob_rate = mp->fixed_rate_idx;
260 - sample_idx = -1;
261 - }
262 -#endif
263 -
264 mi->total_packets++;
265
266 /* wraparound */
267 @@ -804,10 +807,18 @@ minstrel_ht_get_rate(void *priv, struct
268
269 sample_group = &minstrel_mcs_groups[sample_idx / MCS_GROUP_RATES];
270 info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE;
271 + rate->count = 1;
272 +
273 + if (sample_idx / MCS_GROUP_RATES == MINSTREL_CCK_GROUP) {
274 + int idx = sample_idx % ARRAY_SIZE(mp->cck_rates);
275 + rate->idx = mp->cck_rates[idx];
276 + rate->flags = 0;
277 + return;
278 + }
279 +
280 rate->idx = sample_idx % MCS_GROUP_RATES +
281 (sample_group->streams - 1) * MCS_GROUP_RATES;
282 rate->flags = IEEE80211_TX_RC_MCS | sample_group->flags;
283 - rate->count = 1;
284 }
285
286 static void
287 @@ -820,6 +831,9 @@ minstrel_ht_update_cck(struct minstrel_p
288 if (sband->band != IEEE80211_BAND_2GHZ)
289 return;
290
291 + if (!(mp->hw->flags & IEEE80211_HW_SUPPORTS_HT_CCK_RATES))
292 + return;
293 +
294 mi->cck_supported = 0;
295 mi->cck_supported_short = 0;
296 for (i = 0; i < 4; i++) {
297 --- a/net/mac80211/rx.c
298 +++ b/net/mac80211/rx.c
299 @@ -936,8 +936,14 @@ ieee80211_rx_h_check(struct ieee80211_rx
300 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
301 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
302
303 - /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
304 - if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
305 + /*
306 + * Drop duplicate 802.11 retransmissions
307 + * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
308 + */
309 + if (rx->skb->len >= 24 && rx->sta &&
310 + !ieee80211_is_ctl(hdr->frame_control) &&
311 + !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
312 + !is_multicast_ether_addr(hdr->addr1)) {
313 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
314 rx->sta->last_seq_ctrl[rx->seqno_idx] ==
315 hdr->seq_ctrl)) {
316 @@ -2369,6 +2375,7 @@ ieee80211_rx_h_action(struct ieee80211_r
317 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
318 sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
319 sdata->vif.type != NL80211_IFTYPE_AP &&
320 + sdata->vif.type != NL80211_IFTYPE_WDS &&
321 sdata->vif.type != NL80211_IFTYPE_ADHOC)
322 break;
323
324 @@ -2720,14 +2727,15 @@ ieee80211_rx_h_mgmt(struct ieee80211_rx_
325
326 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
327 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
328 - sdata->vif.type != NL80211_IFTYPE_STATION)
329 + sdata->vif.type != NL80211_IFTYPE_STATION &&
330 + sdata->vif.type != NL80211_IFTYPE_WDS)
331 return RX_DROP_MONITOR;
332
333 switch (stype) {
334 case cpu_to_le16(IEEE80211_STYPE_AUTH):
335 case cpu_to_le16(IEEE80211_STYPE_BEACON):
336 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
337 - /* process for all: mesh, mlme, ibss */
338 + /* process for all: mesh, mlme, ibss, wds */
339 break;
340 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
341 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
342 @@ -3008,6 +3016,9 @@ static int prepare_for_handlers(struct i
343 case NL80211_IFTYPE_ADHOC:
344 if (!bssid)
345 return 0;
346 + if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
347 + ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
348 + return 0;
349 if (ieee80211_is_beacon(hdr->frame_control)) {
350 return 1;
351 } else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
352 @@ -3059,10 +3070,16 @@ static int prepare_for_handlers(struct i
353 }
354 break;
355 case NL80211_IFTYPE_WDS:
356 - if (bssid || !ieee80211_is_data(hdr->frame_control))
357 - return 0;
358 if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
359 return 0;
360 +
361 + if (ieee80211_is_data(hdr->frame_control) ||
362 + ieee80211_is_action(hdr->frame_control)) {
363 + if (compare_ether_addr(sdata->vif.addr, hdr->addr1))
364 + return 0;
365 + } else if (!ieee80211_is_beacon(hdr->frame_control))
366 + return 0;
367 +
368 break;
369 case NL80211_IFTYPE_P2P_DEVICE:
370 if (!ieee80211_is_public_action(hdr, skb->len) &&
371 --- a/net/mac80211/sta_info.h
372 +++ b/net/mac80211/sta_info.h
373 @@ -32,7 +32,6 @@
374 * @WLAN_STA_SHORT_PREAMBLE: Station is capable of receiving short-preamble
375 * frames.
376 * @WLAN_STA_WME: Station is a QoS-STA.
377 - * @WLAN_STA_WDS: Station is one of our WDS peers.
378 * @WLAN_STA_CLEAR_PS_FILT: Clear PS filter in hardware (using the
379 * IEEE80211_TX_CTL_CLEAR_PS_FILT control flag) when the next
380 * frame to this station is transmitted.
381 @@ -66,7 +65,6 @@ enum ieee80211_sta_info_flags {
382 WLAN_STA_AUTHORIZED,
383 WLAN_STA_SHORT_PREAMBLE,
384 WLAN_STA_WME,
385 - WLAN_STA_WDS,
386 WLAN_STA_CLEAR_PS_FILT,
387 WLAN_STA_MFP,
388 WLAN_STA_BLOCK_BA,
389 --- a/drivers/net/wireless/ath/ath9k/xmit.c
390 +++ b/drivers/net/wireless/ath/ath9k/xmit.c
391 @@ -135,6 +135,9 @@ static struct ath_frame_info *get_frame_
392
393 static void ath_send_bar(struct ath_atx_tid *tid, u16 seqno)
394 {
395 + if (!tid->an->sta)
396 + return;
397 +
398 ieee80211_send_bar(tid->an->vif, tid->an->sta->addr, tid->tidno,
399 seqno << IEEE80211_SEQ_SEQ_SHIFT);
400 }
401 @@ -146,6 +149,93 @@ static void ath_set_rates(struct ieee802
402 ARRAY_SIZE(bf->rates));
403 }
404
405 +static void ath_txq_skb_done(struct ath_softc *sc, struct ath_txq *txq,
406 + struct sk_buff *skb)
407 +{
408 + int q;
409 +
410 + q = skb_get_queue_mapping(skb);
411 + if (txq == sc->tx.uapsdq)
412 + txq = sc->tx.txq_map[q];
413 +
414 + if (txq != sc->tx.txq_map[q])
415 + return;
416 +
417 + if (WARN_ON(--txq->pending_frames < 0))
418 + txq->pending_frames = 0;
419 +
420 + if (txq->stopped &&
421 + txq->pending_frames < sc->tx.txq_max_pending[q]) {
422 + ieee80211_wake_queue(sc->hw, q);
423 + txq->stopped = false;
424 + }
425 +}
426 +
427 +static struct ath_atx_tid *
428 +ath_get_skb_tid(struct ath_softc *sc, struct ath_node *an, struct sk_buff *skb)
429 +{
430 + struct ieee80211_hdr *hdr;
431 + u8 tidno = 0;
432 +
433 + hdr = (struct ieee80211_hdr *) skb->data;
434 + if (ieee80211_is_data_qos(hdr->frame_control))
435 + tidno = ieee80211_get_qos_ctl(hdr)[0];
436 +
437 + tidno &= IEEE80211_QOS_CTL_TID_MASK;
438 + return ATH_AN_2_TID(an, tidno);
439 +}
440 +
441 +static bool ath_tid_has_buffered(struct ath_atx_tid *tid)
442 +{
443 + return !skb_queue_empty(&tid->buf_q) || !skb_queue_empty(&tid->retry_q);
444 +}
445 +
446 +static struct sk_buff *ath_tid_dequeue(struct ath_atx_tid *tid)
447 +{
448 + struct sk_buff *skb;
449 +
450 + skb = __skb_dequeue(&tid->retry_q);
451 + if (!skb)
452 + skb = __skb_dequeue(&tid->buf_q);
453 +
454 + return skb;
455 +}
456 +
457 +/*
458 + * ath_tx_tid_change_state:
459 + * - clears a-mpdu flag of previous session
460 + * - force sequence number allocation to fix next BlockAck Window
461 + */
462 +static void
463 +ath_tx_tid_change_state(struct ath_softc *sc, struct ath_atx_tid *tid)
464 +{
465 + struct ath_txq *txq = tid->ac->txq;
466 + struct ieee80211_tx_info *tx_info;
467 + struct sk_buff *skb, *tskb;
468 + struct ath_buf *bf;
469 + struct ath_frame_info *fi;
470 +
471 + skb_queue_walk_safe(&tid->buf_q, skb, tskb) {
472 + fi = get_frame_info(skb);
473 + bf = fi->bf;
474 +
475 + tx_info = IEEE80211_SKB_CB(skb);
476 + tx_info->flags &= ~IEEE80211_TX_CTL_AMPDU;
477 +
478 + if (bf)
479 + continue;
480 +
481 + bf = ath_tx_setup_buffer(sc, txq, tid, skb);
482 + if (!bf) {
483 + __skb_unlink(skb, &tid->buf_q);
484 + ath_txq_skb_done(sc, txq, skb);
485 + ieee80211_free_txskb(sc->hw, skb);
486 + continue;
487 + }
488 + }
489 +
490 +}
491 +
492 static void ath_tx_flush_tid(struct ath_softc *sc, struct ath_atx_tid *tid)
493 {
494 struct ath_txq *txq = tid->ac->txq;
495 @@ -160,27 +250,22 @@ static void ath_tx_flush_tid(struct ath_
496
497 memset(&ts, 0, sizeof(ts));
498
499 - while ((skb = __skb_dequeue(&tid->buf_q))) {
500 + while ((skb = __skb_dequeue(&tid->retry_q))) {
501 fi = get_frame_info(skb);
502 bf = fi->bf;
503 -
504 if (!bf) {
505 - bf = ath_tx_setup_buffer(sc, txq, tid, skb);
506 - if (!bf) {
507 - ieee80211_free_txskb(sc->hw, skb);
508 - continue;
509 - }
510 + ath_txq_skb_done(sc, txq, skb);
511 + ieee80211_free_txskb(sc->hw, skb);
512 + continue;
513 }
514
515 - if (fi->retries) {
516 - list_add_tail(&bf->list, &bf_head);
517 + if (fi->baw_tracked) {
518 ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
519 - ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
520 sendbar = true;
521 - } else {
522 - ath_set_rates(tid->an->vif, tid->an->sta, bf);
523 - ath_tx_send_normal(sc, txq, NULL, skb);
524 }
525 +
526 + list_add_tail(&bf->list, &bf_head);
527 + ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
528 }
529
530 if (sendbar) {
531 @@ -209,13 +294,16 @@ static void ath_tx_update_baw(struct ath
532 }
533
534 static void ath_tx_addto_baw(struct ath_softc *sc, struct ath_atx_tid *tid,
535 - u16 seqno)
536 + struct ath_buf *bf)
537 {
538 + struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
539 + u16 seqno = bf->bf_state.seqno;
540 int index, cindex;
541
542 index = ATH_BA_INDEX(tid->seq_start, seqno);
543 cindex = (tid->baw_head + index) & (ATH_TID_MAX_BUFS - 1);
544 __set_bit(cindex, tid->tx_buf);
545 + fi->baw_tracked = 1;
546
547 if (index >= ((tid->baw_tail - tid->baw_head) &
548 (ATH_TID_MAX_BUFS - 1))) {
549 @@ -224,12 +312,6 @@ static void ath_tx_addto_baw(struct ath_
550 }
551 }
552
553 -/*
554 - * TODO: For frame(s) that are in the retry state, we will reuse the
555 - * sequence number(s) without setting the retry bit. The
556 - * alternative is to give up on these and BAR the receiver's window
557 - * forward.
558 - */
559 static void ath_tid_drain(struct ath_softc *sc, struct ath_txq *txq,
560 struct ath_atx_tid *tid)
561
562 @@ -243,7 +325,7 @@ static void ath_tid_drain(struct ath_sof
563 memset(&ts, 0, sizeof(ts));
564 INIT_LIST_HEAD(&bf_head);
565
566 - while ((skb = __skb_dequeue(&tid->buf_q))) {
567 + while ((skb = ath_tid_dequeue(tid))) {
568 fi = get_frame_info(skb);
569 bf = fi->bf;
570
571 @@ -253,14 +335,8 @@ static void ath_tid_drain(struct ath_sof
572 }
573
574 list_add_tail(&bf->list, &bf_head);
575 -
576 - ath_tx_update_baw(sc, tid, bf->bf_state.seqno);
577 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
578 }
579 -
580 - tid->seq_next = tid->seq_start;
581 - tid->baw_tail = tid->baw_head;
582 - tid->bar_index = -1;
583 }
584
585 static void ath_tx_set_retry(struct ath_softc *sc, struct ath_txq *txq,
586 @@ -323,6 +399,7 @@ static struct ath_buf* ath_clone_txbuf(s
587 tbf->bf_buf_addr = bf->bf_buf_addr;
588 memcpy(tbf->bf_desc, bf->bf_desc, sc->sc_ah->caps.tx_desc_len);
589 tbf->bf_state = bf->bf_state;
590 + tbf->bf_state.stale = false;
591
592 return tbf;
593 }
594 @@ -380,7 +457,6 @@ static void ath_tx_complete_aggr(struct
595 struct ieee80211_tx_rate rates[4];
596 struct ath_frame_info *fi;
597 int nframes;
598 - u8 tidno;
599 bool flush = !!(ts->ts_status & ATH9K_TX_FLUSH);
600 int i, retries;
601 int bar_index = -1;
602 @@ -406,7 +482,7 @@ static void ath_tx_complete_aggr(struct
603 while (bf) {
604 bf_next = bf->bf_next;
605
606 - if (!bf->bf_stale || bf_next != NULL)
607 + if (!bf->bf_state.stale || bf_next != NULL)
608 list_move_tail(&bf->list, &bf_head);
609
610 ath_tx_complete_buf(sc, bf, txq, &bf_head, ts, 0);
611 @@ -417,8 +493,7 @@ static void ath_tx_complete_aggr(struct
612 }
613
614 an = (struct ath_node *)sta->drv_priv;
615 - tidno = ieee80211_get_qos_ctl(hdr)[0] & IEEE80211_QOS_CTL_TID_MASK;
616 - tid = ATH_AN_2_TID(an, tidno);
617 + tid = ath_get_skb_tid(sc, an, skb);
618 seq_first = tid->seq_start;
619 isba = ts->ts_flags & ATH9K_TX_BA;
620
621 @@ -430,7 +505,7 @@ static void ath_tx_complete_aggr(struct
622 * Only BlockAcks have a TID and therefore normal Acks cannot be
623 * checked
624 */
625 - if (isba && tidno != ts->tid)
626 + if (isba && tid->tidno != ts->tid)
627 txok = false;
628
629 isaggr = bf_isaggr(bf);
630 @@ -466,7 +541,8 @@ static void ath_tx_complete_aggr(struct
631 tx_info = IEEE80211_SKB_CB(skb);
632 fi = get_frame_info(skb);
633
634 - if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno)) {
635 + if (!BAW_WITHIN(tid->seq_start, tid->baw_size, seqno) ||
636 + !tid->active) {
637 /*
638 * Outside of the current BlockAck window,
639 * maybe part of a previous session
640 @@ -499,7 +575,7 @@ static void ath_tx_complete_aggr(struct
641 * not a holding desc.
642 */
643 INIT_LIST_HEAD(&bf_head);
644 - if (bf_next != NULL || !bf_last->bf_stale)
645 + if (bf_next != NULL || !bf_last->bf_state.stale)
646 list_move_tail(&bf->list, &bf_head);
647
648 if (!txpending) {
649 @@ -523,7 +599,7 @@ static void ath_tx_complete_aggr(struct
650 ieee80211_sta_eosp(sta);
651 }
652 /* retry the un-acked ones */
653 - if (bf->bf_next == NULL && bf_last->bf_stale) {
654 + if (bf->bf_next == NULL && bf_last->bf_state.stale) {
655 struct ath_buf *tbf;
656
657 tbf = ath_clone_txbuf(sc, bf_last);
658 @@ -560,7 +636,7 @@ static void ath_tx_complete_aggr(struct
659 if (an->sleeping)
660 ieee80211_sta_set_buffered(sta, tid->tidno, true);
661
662 - skb_queue_splice(&bf_pending, &tid->buf_q);
663 + skb_queue_splice_tail(&bf_pending, &tid->retry_q);
664 if (!an->sleeping) {
665 ath_tx_queue_tid(txq, tid);
666
667 @@ -618,7 +694,7 @@ static void ath_tx_process_buffer(struct
668 } else
669 ath_tx_complete_aggr(sc, txq, bf, bf_head, ts, txok);
670
671 - if ((sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) && !flush)
672 + if (!flush)
673 ath_txq_schedule(sc, txq);
674 }
675
676 @@ -792,15 +868,20 @@ static int ath_compute_num_delims(struct
677
678 static struct ath_buf *
679 ath_tx_get_tid_subframe(struct ath_softc *sc, struct ath_txq *txq,
680 - struct ath_atx_tid *tid)
681 + struct ath_atx_tid *tid, struct sk_buff_head **q)
682 {
683 + struct ieee80211_tx_info *tx_info;
684 struct ath_frame_info *fi;
685 struct sk_buff *skb;
686 struct ath_buf *bf;
687 u16 seqno;
688
689 while (1) {
690 - skb = skb_peek(&tid->buf_q);
691 + *q = &tid->retry_q;
692 + if (skb_queue_empty(*q))
693 + *q = &tid->buf_q;
694 +
695 + skb = skb_peek(*q);
696 if (!skb)
697 break;
698
699 @@ -808,13 +889,26 @@ ath_tx_get_tid_subframe(struct ath_softc
700 bf = fi->bf;
701 if (!fi->bf)
702 bf = ath_tx_setup_buffer(sc, txq, tid, skb);
703 + else
704 + bf->bf_state.stale = false;
705
706 if (!bf) {
707 - __skb_unlink(skb, &tid->buf_q);
708 + __skb_unlink(skb, *q);
709 + ath_txq_skb_done(sc, txq, skb);
710 ieee80211_free_txskb(sc->hw, skb);
711 continue;
712 }
713
714 + bf->bf_next = NULL;
715 + bf->bf_lastbf = bf;
716 +
717 + tx_info = IEEE80211_SKB_CB(skb);
718 + tx_info->flags &= ~IEEE80211_TX_CTL_CLEAR_PS_FILT;
719 + if (!(tx_info->flags & IEEE80211_TX_CTL_AMPDU)) {
720 + bf->bf_state.bf_type = 0;
721 + return bf;
722 + }
723 +
724 bf->bf_state.bf_type = BUF_AMPDU | BUF_AGGR;
725 seqno = bf->bf_state.seqno;
726
727 @@ -828,73 +922,52 @@ ath_tx_get_tid_subframe(struct ath_softc
728
729 INIT_LIST_HEAD(&bf_head);
730 list_add(&bf->list, &bf_head);
731 - __skb_unlink(skb, &tid->buf_q);
732 + __skb_unlink(skb, *q);
733 ath_tx_update_baw(sc, tid, seqno);
734 ath_tx_complete_buf(sc, bf, txq, &bf_head, &ts, 0);
735 continue;
736 }
737
738 - bf->bf_next = NULL;
739 - bf->bf_lastbf = bf;
740 return bf;
741 }
742
743 return NULL;
744 }
745
746 -static enum ATH_AGGR_STATUS ath_tx_form_aggr(struct ath_softc *sc,
747 - struct ath_txq *txq,
748 - struct ath_atx_tid *tid,
749 - struct list_head *bf_q,
750 - int *aggr_len)
751 +static bool
752 +ath_tx_form_aggr(struct ath_softc *sc, struct ath_txq *txq,
753 + struct ath_atx_tid *tid, struct list_head *bf_q,
754 + struct ath_buf *bf_first, struct sk_buff_head *tid_q,
755 + int *aggr_len)
756 {
757 #define PADBYTES(_len) ((4 - ((_len) % 4)) % 4)
758 - struct ath_buf *bf, *bf_first = NULL, *bf_prev = NULL;
759 - int rl = 0, nframes = 0, ndelim, prev_al = 0;
760 + struct ath_buf *bf = bf_first, *bf_prev = NULL;
761 + int nframes = 0, ndelim;
762 u16 aggr_limit = 0, al = 0, bpad = 0,
763 - al_delta, h_baw = tid->baw_size / 2;
764 - enum ATH_AGGR_STATUS status = ATH_AGGR_DONE;
765 + al_delta, h_baw = tid->baw_size / 2;
766 struct ieee80211_tx_info *tx_info;
767 struct ath_frame_info *fi;
768 struct sk_buff *skb;
769 + bool closed = false;
770
771 - do {
772 - bf = ath_tx_get_tid_subframe(sc, txq, tid);
773 - if (!bf) {
774 - status = ATH_AGGR_BAW_CLOSED;
775 - break;
776 - }
777 + bf = bf_first;
778 + aggr_limit = ath_lookup_rate(sc, bf, tid);
779
780 + do {
781 skb = bf->bf_mpdu;
782 fi = get_frame_info(skb);
783
784 - if (!bf_first)
785 - bf_first = bf;
786 -
787 - if (!rl) {
788 - ath_set_rates(tid->an->vif, tid->an->sta, bf);
789 - aggr_limit = ath_lookup_rate(sc, bf, tid);
790 - rl = 1;
791 - }
792 -
793 /* do not exceed aggregation limit */
794 al_delta = ATH_AGGR_DELIM_SZ + fi->framelen;
795 + if (nframes) {
796 + if (aggr_limit < al + bpad + al_delta ||
797 + ath_lookup_legacy(bf) || nframes >= h_baw)
798 + break;
799
800 - if (nframes &&
801 - ((aggr_limit < (al + bpad + al_delta + prev_al)) ||
802 - ath_lookup_legacy(bf))) {
803 - status = ATH_AGGR_LIMITED;
804 - break;
805 - }
806 -
807 - tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
808 - if (nframes && (tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE))
809 - break;
810 -
811 - /* do not exceed subframe limit */
812 - if (nframes >= min((int)h_baw, ATH_AMPDU_SUBFRAME_DEFAULT)) {
813 - status = ATH_AGGR_LIMITED;
814 - break;
815 + tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
816 + if ((tx_info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) ||
817 + !(tx_info->flags & IEEE80211_TX_CTL_AMPDU))
818 + break;
819 }
820
821 /* add padding for previous frame to aggregation length */
822 @@ -912,22 +985,37 @@ static enum ATH_AGGR_STATUS ath_tx_form_
823 bf->bf_next = NULL;
824
825 /* link buffers of this frame to the aggregate */
826 - if (!fi->retries)
827 - ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
828 + if (!fi->baw_tracked)
829 + ath_tx_addto_baw(sc, tid, bf);
830 bf->bf_state.ndelim = ndelim;
831
832 - __skb_unlink(skb, &tid->buf_q);
833 + __skb_unlink(skb, tid_q);
834 list_add_tail(&bf->list, bf_q);
835 if (bf_prev)
836 bf_prev->bf_next = bf;
837
838 bf_prev = bf;
839
840 - } while (!skb_queue_empty(&tid->buf_q));
841 + bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
842 + if (!bf) {
843 + closed = true;
844 + break;
845 + }
846 + } while (ath_tid_has_buffered(tid));
847 +
848 + bf = bf_first;
849 + bf->bf_lastbf = bf_prev;
850 +
851 + if (bf == bf_prev) {
852 + al = get_frame_info(bf->bf_mpdu)->framelen;
853 + bf->bf_state.bf_type = BUF_AMPDU;
854 + } else {
855 + TX_STAT_INC(txq->axq_qnum, a_aggr);
856 + }
857
858 *aggr_len = al;
859
860 - return status;
861 + return closed;
862 #undef PADBYTES
863 }
864
865 @@ -999,7 +1087,7 @@ void ath_update_max_aggr_framelen(struct
866 }
867
868 static void ath_buf_set_rate(struct ath_softc *sc, struct ath_buf *bf,
869 - struct ath_tx_info *info, int len)
870 + struct ath_tx_info *info, int len, bool rts)
871 {
872 struct ath_hw *ah = sc->sc_ah;
873 struct sk_buff *skb;
874 @@ -1008,6 +1096,7 @@ static void ath_buf_set_rate(struct ath_
875 const struct ieee80211_rate *rate;
876 struct ieee80211_hdr *hdr;
877 struct ath_frame_info *fi = get_frame_info(bf->bf_mpdu);
878 + u32 rts_thresh = sc->hw->wiphy->rts_threshold;
879 int i;
880 u8 rix = 0;
881
882 @@ -1030,7 +1119,17 @@ static void ath_buf_set_rate(struct ath_
883 rix = rates[i].idx;
884 info->rates[i].Tries = rates[i].count;
885
886 - if (rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
887 + /*
888 + * Handle RTS threshold for unaggregated HT frames.
889 + */
890 + if (bf_isampdu(bf) && !bf_isaggr(bf) &&
891 + (rates[i].flags & IEEE80211_TX_RC_MCS) &&
892 + unlikely(rts_thresh != (u32) -1)) {
893 + if (!rts_thresh || (len > rts_thresh))
894 + rts = true;
895 + }
896 +
897 + if (rts || rates[i].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
898 info->rates[i].RateFlags |= ATH9K_RATESERIES_RTS_CTS;
899 info->flags |= ATH9K_TXDESC_RTSENA;
900 } else if (rates[i].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
901 @@ -1123,6 +1222,8 @@ static void ath_tx_fill_desc(struct ath_
902 struct ath_hw *ah = sc->sc_ah;
903 struct ath_buf *bf_first = NULL;
904 struct ath_tx_info info;
905 + u32 rts_thresh = sc->hw->wiphy->rts_threshold;
906 + bool rts = false;
907
908 memset(&info, 0, sizeof(info));
909 info.is_first = true;
910 @@ -1159,7 +1260,22 @@ static void ath_tx_fill_desc(struct ath_
911 info.flags |= (u32) bf->bf_state.bfs_paprd <<
912 ATH9K_TXDESC_PAPRD_S;
913
914 - ath_buf_set_rate(sc, bf, &info, len);
915 + /*
916 + * mac80211 doesn't handle RTS threshold for HT because
917 + * the decision has to be taken based on AMPDU length
918 + * and aggregation is done entirely inside ath9k.
919 + * Set the RTS/CTS flag for the first subframe based
920 + * on the threshold.
921 + */
922 + if (aggr && (bf == bf_first) &&
923 + unlikely(rts_thresh != (u32) -1)) {
924 + /*
925 + * "len" is the size of the entire AMPDU.
926 + */
927 + if (!rts_thresh || (len > rts_thresh))
928 + rts = true;
929 + }
930 + ath_buf_set_rate(sc, bf, &info, len, rts);
931 }
932
933 info.buf_addr[0] = bf->bf_buf_addr;
934 @@ -1188,64 +1304,101 @@ static void ath_tx_fill_desc(struct ath_
935 }
936 }
937
938 -static void ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq,
939 - struct ath_atx_tid *tid)
940 +static void
941 +ath_tx_form_burst(struct ath_softc *sc, struct ath_txq *txq,
942 + struct ath_atx_tid *tid, struct list_head *bf_q,
943 + struct ath_buf *bf_first, struct sk_buff_head *tid_q)
944 {
945 - struct ath_buf *bf;
946 - enum ATH_AGGR_STATUS status;
947 - struct ieee80211_tx_info *tx_info;
948 - struct list_head bf_q;
949 - int aggr_len;
950 + struct ath_buf *bf = bf_first, *bf_prev = NULL;
951 + struct sk_buff *skb;
952 + int nframes = 0;
953
954 do {
955 - if (skb_queue_empty(&tid->buf_q))
956 - return;
957 + struct ieee80211_tx_info *tx_info;
958 + skb = bf->bf_mpdu;
959
960 - INIT_LIST_HEAD(&bf_q);
961 + nframes++;
962 + __skb_unlink(skb, tid_q);
963 + list_add_tail(&bf->list, bf_q);
964 + if (bf_prev)
965 + bf_prev->bf_next = bf;
966 + bf_prev = bf;
967
968 - status = ath_tx_form_aggr(sc, txq, tid, &bf_q, &aggr_len);
969 + if (nframes >= 2)
970 + break;
971
972 - /*
973 - * no frames picked up to be aggregated;
974 - * block-ack window is not open.
975 - */
976 - if (list_empty(&bf_q))
977 + bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
978 + if (!bf)
979 break;
980
981 - bf = list_first_entry(&bf_q, struct ath_buf, list);
982 - bf->bf_lastbf = list_entry(bf_q.prev, struct ath_buf, list);
983 tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
984 + if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
985 + break;
986
987 - if (tid->ac->clear_ps_filter) {
988 - tid->ac->clear_ps_filter = false;
989 - tx_info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
990 - } else {
991 - tx_info->flags &= ~IEEE80211_TX_CTL_CLEAR_PS_FILT;
992 - }
993 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
994 + } while (1);
995 +}
996
997 - /* if only one frame, send as non-aggregate */
998 - if (bf == bf->bf_lastbf) {
999 - aggr_len = get_frame_info(bf->bf_mpdu)->framelen;
1000 - bf->bf_state.bf_type = BUF_AMPDU;
1001 - } else {
1002 - TX_STAT_INC(txq->axq_qnum, a_aggr);
1003 - }
1004 +static bool ath_tx_sched_aggr(struct ath_softc *sc, struct ath_txq *txq,
1005 + struct ath_atx_tid *tid, bool *stop)
1006 +{
1007 + struct ath_buf *bf;
1008 + struct ieee80211_tx_info *tx_info;
1009 + struct sk_buff_head *tid_q;
1010 + struct list_head bf_q;
1011 + int aggr_len = 0;
1012 + bool aggr, last = true;
1013 +
1014 + if (!ath_tid_has_buffered(tid))
1015 + return false;
1016 +
1017 + INIT_LIST_HEAD(&bf_q);
1018 +
1019 + bf = ath_tx_get_tid_subframe(sc, txq, tid, &tid_q);
1020 + if (!bf)
1021 + return false;
1022 +
1023 + tx_info = IEEE80211_SKB_CB(bf->bf_mpdu);
1024 + aggr = !!(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
1025 + if ((aggr && txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) ||
1026 + (!aggr && txq->axq_depth >= ATH_NON_AGGR_MIN_QDEPTH)) {
1027 + *stop = true;
1028 + return false;
1029 + }
1030 +
1031 + ath_set_rates(tid->an->vif, tid->an->sta, bf);
1032 + if (aggr)
1033 + last = ath_tx_form_aggr(sc, txq, tid, &bf_q, bf,
1034 + tid_q, &aggr_len);
1035 + else
1036 + ath_tx_form_burst(sc, txq, tid, &bf_q, bf, tid_q);
1037 +
1038 + if (list_empty(&bf_q))
1039 + return false;
1040 +
1041 + if (tid->ac->clear_ps_filter || tid->an->no_ps_filter) {
1042 + tid->ac->clear_ps_filter = false;
1043 + tx_info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1044 + }
1045
1046 - ath_tx_fill_desc(sc, bf, txq, aggr_len);
1047 - ath_tx_txqaddbuf(sc, txq, &bf_q, false);
1048 - } while (txq->axq_ampdu_depth < ATH_AGGR_MIN_QDEPTH &&
1049 - status != ATH_AGGR_BAW_CLOSED);
1050 + ath_tx_fill_desc(sc, bf, txq, aggr_len);
1051 + ath_tx_txqaddbuf(sc, txq, &bf_q, false);
1052 + return true;
1053 }
1054
1055 int ath_tx_aggr_start(struct ath_softc *sc, struct ieee80211_sta *sta,
1056 u16 tid, u16 *ssn)
1057 {
1058 struct ath_atx_tid *txtid;
1059 + struct ath_txq *txq;
1060 struct ath_node *an;
1061 u8 density;
1062
1063 an = (struct ath_node *)sta->drv_priv;
1064 txtid = ATH_AN_2_TID(an, tid);
1065 + txq = txtid->ac->txq;
1066 +
1067 + ath_txq_lock(sc, txq);
1068
1069 /* update ampdu factor/density, they may have changed. This may happen
1070 * in HT IBSS when a beacon with HT-info is received after the station
1071 @@ -1258,6 +1411,9 @@ int ath_tx_aggr_start(struct ath_softc *
1072 an->mpdudensity = density;
1073 }
1074
1075 + /* force sequence number allocation for pending frames */
1076 + ath_tx_tid_change_state(sc, txtid);
1077 +
1078 txtid->active = true;
1079 txtid->paused = true;
1080 *ssn = txtid->seq_start = txtid->seq_next;
1081 @@ -1266,6 +1422,8 @@ int ath_tx_aggr_start(struct ath_softc *
1082 memset(txtid->tx_buf, 0, sizeof(txtid->tx_buf));
1083 txtid->baw_head = txtid->baw_tail = 0;
1084
1085 + ath_txq_unlock_complete(sc, txq);
1086 +
1087 return 0;
1088 }
1089
1090 @@ -1277,8 +1435,9 @@ void ath_tx_aggr_stop(struct ath_softc *
1091
1092 ath_txq_lock(sc, txq);
1093 txtid->active = false;
1094 - txtid->paused = true;
1095 + txtid->paused = false;
1096 ath_tx_flush_tid(sc, txtid);
1097 + ath_tx_tid_change_state(sc, txtid);
1098 ath_txq_unlock_complete(sc, txq);
1099 }
1100
1101 @@ -1302,7 +1461,7 @@ void ath_tx_aggr_sleep(struct ieee80211_
1102
1103 ath_txq_lock(sc, txq);
1104
1105 - buffered = !skb_queue_empty(&tid->buf_q);
1106 + buffered = ath_tid_has_buffered(tid);
1107
1108 tid->sched = false;
1109 list_del(&tid->list);
1110 @@ -1334,7 +1493,7 @@ void ath_tx_aggr_wakeup(struct ath_softc
1111 ath_txq_lock(sc, txq);
1112 ac->clear_ps_filter = true;
1113
1114 - if (!skb_queue_empty(&tid->buf_q) && !tid->paused) {
1115 + if (!tid->paused && ath_tid_has_buffered(tid)) {
1116 ath_tx_queue_tid(txq, tid);
1117 ath_txq_schedule(sc, txq);
1118 }
1119 @@ -1359,7 +1518,7 @@ void ath_tx_aggr_resume(struct ath_softc
1120 tid->baw_size = IEEE80211_MIN_AMPDU_BUF << sta->ht_cap.ampdu_factor;
1121 tid->paused = false;
1122
1123 - if (!skb_queue_empty(&tid->buf_q)) {
1124 + if (ath_tid_has_buffered(tid)) {
1125 ath_tx_queue_tid(txq, tid);
1126 ath_txq_schedule(sc, txq);
1127 }
1128 @@ -1379,6 +1538,7 @@ void ath9k_release_buffered_frames(struc
1129 struct ieee80211_tx_info *info;
1130 struct list_head bf_q;
1131 struct ath_buf *bf_tail = NULL, *bf;
1132 + struct sk_buff_head *tid_q;
1133 int sent = 0;
1134 int i;
1135
1136 @@ -1394,16 +1554,18 @@ void ath9k_release_buffered_frames(struc
1137 continue;
1138
1139 ath_txq_lock(sc, tid->ac->txq);
1140 - while (!skb_queue_empty(&tid->buf_q) && nframes > 0) {
1141 - bf = ath_tx_get_tid_subframe(sc, sc->tx.uapsdq, tid);
1142 + while (nframes > 0) {
1143 + bf = ath_tx_get_tid_subframe(sc, sc->tx.uapsdq, tid, &tid_q);
1144 if (!bf)
1145 break;
1146
1147 - __skb_unlink(bf->bf_mpdu, &tid->buf_q);
1148 + __skb_unlink(bf->bf_mpdu, tid_q);
1149 list_add_tail(&bf->list, &bf_q);
1150 ath_set_rates(tid->an->vif, tid->an->sta, bf);
1151 - ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
1152 - bf->bf_state.bf_type &= ~BUF_AGGR;
1153 + if (bf_isampdu(bf)) {
1154 + ath_tx_addto_baw(sc, tid, bf);
1155 + bf->bf_state.bf_type &= ~BUF_AGGR;
1156 + }
1157 if (bf_tail)
1158 bf_tail->bf_next = bf;
1159
1160 @@ -1412,7 +1574,7 @@ void ath9k_release_buffered_frames(struc
1161 sent++;
1162 TX_STAT_INC(txq->axq_qnum, a_queued_hw);
1163
1164 - if (skb_queue_empty(&tid->buf_q))
1165 + if (an->sta && !ath_tid_has_buffered(tid))
1166 ieee80211_sta_set_buffered(an->sta, i, false);
1167 }
1168 ath_txq_unlock_complete(sc, tid->ac->txq);
1169 @@ -1571,7 +1733,7 @@ static void ath_drain_txq_list(struct at
1170 while (!list_empty(list)) {
1171 bf = list_first_entry(list, struct ath_buf, list);
1172
1173 - if (bf->bf_stale) {
1174 + if (bf->bf_state.stale) {
1175 list_del(&bf->list);
1176
1177 ath_tx_return_buffer(sc, bf);
1178 @@ -1665,25 +1827,27 @@ void ath_tx_cleanupq(struct ath_softc *s
1179 */
1180 void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
1181 {
1182 - struct ath_atx_ac *ac, *ac_tmp, *last_ac;
1183 + struct ath_atx_ac *ac, *last_ac;
1184 struct ath_atx_tid *tid, *last_tid;
1185 + bool sent = false;
1186
1187 if (test_bit(SC_OP_HW_RESET, &sc->sc_flags) ||
1188 - list_empty(&txq->axq_acq) ||
1189 - txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH)
1190 + list_empty(&txq->axq_acq))
1191 return;
1192
1193 rcu_read_lock();
1194
1195 - ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list);
1196 last_ac = list_entry(txq->axq_acq.prev, struct ath_atx_ac, list);
1197 + while (!list_empty(&txq->axq_acq)) {
1198 + bool stop = false;
1199
1200 - list_for_each_entry_safe(ac, ac_tmp, &txq->axq_acq, list) {
1201 + ac = list_first_entry(&txq->axq_acq, struct ath_atx_ac, list);
1202 last_tid = list_entry(ac->tid_q.prev, struct ath_atx_tid, list);
1203 list_del(&ac->list);
1204 ac->sched = false;
1205
1206 while (!list_empty(&ac->tid_q)) {
1207 +
1208 tid = list_first_entry(&ac->tid_q, struct ath_atx_tid,
1209 list);
1210 list_del(&tid->list);
1211 @@ -1692,17 +1856,17 @@ void ath_txq_schedule(struct ath_softc *
1212 if (tid->paused)
1213 continue;
1214
1215 - ath_tx_sched_aggr(sc, txq, tid);
1216 + if (ath_tx_sched_aggr(sc, txq, tid, &stop))
1217 + sent = true;
1218
1219 /*
1220 * add tid to round-robin queue if more frames
1221 * are pending for the tid
1222 */
1223 - if (!skb_queue_empty(&tid->buf_q))
1224 + if (ath_tid_has_buffered(tid))
1225 ath_tx_queue_tid(txq, tid);
1226
1227 - if (tid == last_tid ||
1228 - txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH)
1229 + if (stop || tid == last_tid)
1230 break;
1231 }
1232
1233 @@ -1711,9 +1875,17 @@ void ath_txq_schedule(struct ath_softc *
1234 list_add_tail(&ac->list, &txq->axq_acq);
1235 }
1236
1237 - if (ac == last_ac ||
1238 - txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH)
1239 + if (stop)
1240 break;
1241 +
1242 + if (ac == last_ac) {
1243 + if (!sent)
1244 + break;
1245 +
1246 + sent = false;
1247 + last_ac = list_entry(txq->axq_acq.prev,
1248 + struct ath_atx_ac, list);
1249 + }
1250 }
1251
1252 rcu_read_unlock();
1253 @@ -1787,62 +1959,13 @@ static void ath_tx_txqaddbuf(struct ath_
1254 if (bf_is_ampdu_not_probing(bf))
1255 txq->axq_ampdu_depth++;
1256
1257 - bf = bf->bf_lastbf->bf_next;
1258 + bf_last = bf->bf_lastbf;
1259 + bf = bf_last->bf_next;
1260 + bf_last->bf_next = NULL;
1261 }
1262 }
1263 }
1264
1265 -static void ath_tx_send_ampdu(struct ath_softc *sc, struct ath_txq *txq,
1266 - struct ath_atx_tid *tid, struct sk_buff *skb,
1267 - struct ath_tx_control *txctl)
1268 -{
1269 - struct ath_frame_info *fi = get_frame_info(skb);
1270 - struct list_head bf_head;
1271 - struct ath_buf *bf;
1272 -
1273 - /*
1274 - * Do not queue to h/w when any of the following conditions is true:
1275 - * - there are pending frames in software queue
1276 - * - the TID is currently paused for ADDBA/BAR request
1277 - * - seqno is not within block-ack window
1278 - * - h/w queue depth exceeds low water mark
1279 - */
1280 - if ((!skb_queue_empty(&tid->buf_q) || tid->paused ||
1281 - !BAW_WITHIN(tid->seq_start, tid->baw_size, tid->seq_next) ||
1282 - txq->axq_ampdu_depth >= ATH_AGGR_MIN_QDEPTH) &&
1283 - txq != sc->tx.uapsdq) {
1284 - /*
1285 - * Add this frame to software queue for scheduling later
1286 - * for aggregation.
1287 - */
1288 - TX_STAT_INC(txq->axq_qnum, a_queued_sw);
1289 - __skb_queue_tail(&tid->buf_q, skb);
1290 - if (!txctl->an || !txctl->an->sleeping)
1291 - ath_tx_queue_tid(txq, tid);
1292 - return;
1293 - }
1294 -
1295 - bf = ath_tx_setup_buffer(sc, txq, tid, skb);
1296 - if (!bf) {
1297 - ieee80211_free_txskb(sc->hw, skb);
1298 - return;
1299 - }
1300 -
1301 - ath_set_rates(tid->an->vif, tid->an->sta, bf);
1302 - bf->bf_state.bf_type = BUF_AMPDU;
1303 - INIT_LIST_HEAD(&bf_head);
1304 - list_add(&bf->list, &bf_head);
1305 -
1306 - /* Add sub-frame to BAW */
1307 - ath_tx_addto_baw(sc, tid, bf->bf_state.seqno);
1308 -
1309 - /* Queue to h/w without aggregation */
1310 - TX_STAT_INC(txq->axq_qnum, a_queued_hw);
1311 - bf->bf_lastbf = bf;
1312 - ath_tx_fill_desc(sc, bf, txq, fi->framelen);
1313 - ath_tx_txqaddbuf(sc, txq, &bf_head, false);
1314 -}
1315 -
1316 static void ath_tx_send_normal(struct ath_softc *sc, struct ath_txq *txq,
1317 struct ath_atx_tid *tid, struct sk_buff *skb)
1318 {
1319 @@ -1985,6 +2108,7 @@ static int ath_tx_prepare(struct ieee802
1320 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1321 struct ieee80211_sta *sta = txctl->sta;
1322 struct ieee80211_vif *vif = info->control.vif;
1323 + struct ath_vif *avp;
1324 struct ath_softc *sc = hw->priv;
1325 int frmlen = skb->len + FCS_LEN;
1326 int padpos, padsize;
1327 @@ -1992,6 +2116,10 @@ static int ath_tx_prepare(struct ieee802
1328 /* NOTE: sta can be NULL according to net/mac80211.h */
1329 if (sta)
1330 txctl->an = (struct ath_node *)sta->drv_priv;
1331 + else if (vif && ieee80211_is_data(hdr->frame_control)) {
1332 + avp = (void *)vif->drv_priv;
1333 + txctl->an = &avp->mcast_node;
1334 + }
1335
1336 if (info->control.hw_key)
1337 frmlen += info->control.hw_key->icv_len;
1338 @@ -2041,7 +2169,6 @@ int ath_tx_start(struct ieee80211_hw *hw
1339 struct ath_txq *txq = txctl->txq;
1340 struct ath_atx_tid *tid = NULL;
1341 struct ath_buf *bf;
1342 - u8 tidno;
1343 int q;
1344 int ret;
1345
1346 @@ -2069,27 +2196,31 @@ int ath_tx_start(struct ieee80211_hw *hw
1347 ath_txq_unlock(sc, txq);
1348 txq = sc->tx.uapsdq;
1349 ath_txq_lock(sc, txq);
1350 - }
1351 -
1352 - if (txctl->an && ieee80211_is_data_qos(hdr->frame_control)) {
1353 - tidno = ieee80211_get_qos_ctl(hdr)[0] &
1354 - IEEE80211_QOS_CTL_TID_MASK;
1355 - tid = ATH_AN_2_TID(txctl->an, tidno);
1356 + } else if (txctl->an &&
1357 + ieee80211_is_data_present(hdr->frame_control)) {
1358 + tid = ath_get_skb_tid(sc, txctl->an, skb);
1359
1360 WARN_ON(tid->ac->txq != txctl->txq);
1361 - }
1362
1363 - if ((info->flags & IEEE80211_TX_CTL_AMPDU) && tid) {
1364 + if (info->flags & IEEE80211_TX_CTL_CLEAR_PS_FILT)
1365 + tid->ac->clear_ps_filter = true;
1366 +
1367 /*
1368 - * Try aggregation if it's a unicast data frame
1369 - * and the destination is HT capable.
1370 + * Add this frame to software queue for scheduling later
1371 + * for aggregation.
1372 */
1373 - ath_tx_send_ampdu(sc, txq, tid, skb, txctl);
1374 + TX_STAT_INC(txq->axq_qnum, a_queued_sw);
1375 + __skb_queue_tail(&tid->buf_q, skb);
1376 + if (!txctl->an->sleeping)
1377 + ath_tx_queue_tid(txq, tid);
1378 +
1379 + ath_txq_schedule(sc, txq);
1380 goto out;
1381 }
1382
1383 bf = ath_tx_setup_buffer(sc, txq, tid, skb);
1384 if (!bf) {
1385 + ath_txq_skb_done(sc, txq, skb);
1386 if (txctl->paprd)
1387 dev_kfree_skb_any(skb);
1388 else
1389 @@ -2142,7 +2273,7 @@ void ath_tx_cabq(struct ieee80211_hw *hw
1390
1391 bf->bf_lastbf = bf;
1392 ath_set_rates(vif, NULL, bf);
1393 - ath_buf_set_rate(sc, bf, &info, fi->framelen);
1394 + ath_buf_set_rate(sc, bf, &info, fi->framelen, false);
1395 duration += info.rates[0].PktDuration;
1396 if (bf_tail)
1397 bf_tail->bf_next = bf;
1398 @@ -2189,7 +2320,7 @@ static void ath_tx_complete(struct ath_s
1399 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
1400 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1401 struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
1402 - int q, padpos, padsize;
1403 + int padpos, padsize;
1404 unsigned long flags;
1405
1406 ath_dbg(common, XMIT, "TX complete: skb: %p\n", skb);
1407 @@ -2225,21 +2356,7 @@ static void ath_tx_complete(struct ath_s
1408 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
1409
1410 __skb_queue_tail(&txq->complete_q, skb);
1411 -
1412 - q = skb_get_queue_mapping(skb);
1413 - if (txq == sc->tx.uapsdq)
1414 - txq = sc->tx.txq_map[q];
1415 -
1416 - if (txq == sc->tx.txq_map[q]) {
1417 - if (WARN_ON(--txq->pending_frames < 0))
1418 - txq->pending_frames = 0;
1419 -
1420 - if (txq->stopped &&
1421 - txq->pending_frames < sc->tx.txq_max_pending[q]) {
1422 - ieee80211_wake_queue(sc->hw, q);
1423 - txq->stopped = false;
1424 - }
1425 - }
1426 + ath_txq_skb_done(sc, txq, skb);
1427 }
1428
1429 static void ath_tx_complete_buf(struct ath_softc *sc, struct ath_buf *bf,
1430 @@ -2360,8 +2477,7 @@ static void ath_tx_processq(struct ath_s
1431
1432 if (list_empty(&txq->axq_q)) {
1433 txq->axq_link = NULL;
1434 - if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
1435 - ath_txq_schedule(sc, txq);
1436 + ath_txq_schedule(sc, txq);
1437 break;
1438 }
1439 bf = list_first_entry(&txq->axq_q, struct ath_buf, list);
1440 @@ -2375,7 +2491,7 @@ static void ath_tx_processq(struct ath_s
1441 * it with the STALE flag.
1442 */
1443 bf_held = NULL;
1444 - if (bf->bf_stale) {
1445 + if (bf->bf_state.stale) {
1446 bf_held = bf;
1447 if (list_is_last(&bf_held->list, &txq->axq_q))
1448 break;
1449 @@ -2399,7 +2515,7 @@ static void ath_tx_processq(struct ath_s
1450 * however leave the last descriptor back as the holding
1451 * descriptor for hw.
1452 */
1453 - lastbf->bf_stale = true;
1454 + lastbf->bf_state.stale = true;
1455 INIT_LIST_HEAD(&bf_head);
1456 if (!list_is_singular(&lastbf->list))
1457 list_cut_position(&bf_head,
1458 @@ -2470,7 +2586,7 @@ void ath_tx_edma_tasklet(struct ath_soft
1459 }
1460
1461 bf = list_first_entry(fifo_list, struct ath_buf, list);
1462 - if (bf->bf_stale) {
1463 + if (bf->bf_state.stale) {
1464 list_del(&bf->list);
1465 ath_tx_return_buffer(sc, bf);
1466 bf = list_first_entry(fifo_list, struct ath_buf, list);
1467 @@ -2492,7 +2608,7 @@ void ath_tx_edma_tasklet(struct ath_soft
1468 ath_tx_txqaddbuf(sc, txq, &bf_q, true);
1469 }
1470 } else {
1471 - lastbf->bf_stale = true;
1472 + lastbf->bf_state.stale = true;
1473 if (bf != lastbf)
1474 list_cut_position(&bf_head, fifo_list,
1475 lastbf->list.prev);
1476 @@ -2583,6 +2699,7 @@ void ath_tx_node_init(struct ath_softc *
1477 tid->paused = false;
1478 tid->active = false;
1479 __skb_queue_head_init(&tid->buf_q);
1480 + __skb_queue_head_init(&tid->retry_q);
1481 acno = TID_TO_WME_AC(tidno);
1482 tid->ac = &an->ac[acno];
1483 }
1484 @@ -2590,6 +2707,7 @@ void ath_tx_node_init(struct ath_softc *
1485 for (acno = 0, ac = &an->ac[acno];
1486 acno < IEEE80211_NUM_ACS; acno++, ac++) {
1487 ac->sched = false;
1488 + ac->clear_ps_filter = true;
1489 ac->txq = sc->tx.txq_map[acno];
1490 INIT_LIST_HEAD(&ac->tid_q);
1491 }
1492 --- a/drivers/net/wireless/ath/ath9k/main.c
1493 +++ b/drivers/net/wireless/ath/ath9k/main.c
1494 @@ -173,8 +173,7 @@ static void ath_restart_work(struct ath_
1495 {
1496 ieee80211_queue_delayed_work(sc->hw, &sc->tx_complete_work, 0);
1497
1498 - if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9485(sc->sc_ah) ||
1499 - AR_SREV_9550(sc->sc_ah))
1500 + if (AR_SREV_9340(sc->sc_ah) || AR_SREV_9330(sc->sc_ah))
1501 ieee80211_queue_delayed_work(sc->hw, &sc->hw_pll_work,
1502 msecs_to_jiffies(ATH_PLL_WORK_INTERVAL));
1503
1504 @@ -238,9 +237,6 @@ static bool ath_complete_reset(struct at
1505 ath_restart_work(sc);
1506 }
1507
1508 - if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx != 3)
1509 - ath_ant_comb_update(sc);
1510 -
1511 ieee80211_wake_queues(sc->hw);
1512
1513 return true;
1514 @@ -966,6 +962,8 @@ static int ath9k_add_interface(struct ie
1515 struct ath_softc *sc = hw->priv;
1516 struct ath_hw *ah = sc->sc_ah;
1517 struct ath_common *common = ath9k_hw_common(ah);
1518 + struct ath_vif *avp = (void *)vif->drv_priv;
1519 + struct ath_node *an = &avp->mcast_node;
1520
1521 mutex_lock(&sc->mutex);
1522
1523 @@ -979,6 +977,12 @@ static int ath9k_add_interface(struct ie
1524 if (ath9k_uses_beacons(vif->type))
1525 ath9k_beacon_assign_slot(sc, vif);
1526
1527 + an->sc = sc;
1528 + an->sta = NULL;
1529 + an->vif = vif;
1530 + an->no_ps_filter = true;
1531 + ath_tx_node_init(sc, an);
1532 +
1533 mutex_unlock(&sc->mutex);
1534 return 0;
1535 }
1536 @@ -1016,6 +1020,7 @@ static void ath9k_remove_interface(struc
1537 {
1538 struct ath_softc *sc = hw->priv;
1539 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
1540 + struct ath_vif *avp = (void *)vif->drv_priv;
1541
1542 ath_dbg(common, CONFIG, "Detach Interface\n");
1543
1544 @@ -1030,6 +1035,8 @@ static void ath9k_remove_interface(struc
1545 ath9k_calculate_summary_state(hw, NULL);
1546 ath9k_ps_restore(sc);
1547
1548 + ath_tx_node_cleanup(sc, &avp->mcast_node);
1549 +
1550 mutex_unlock(&sc->mutex);
1551 }
1552
1553 @@ -1193,8 +1200,6 @@ static int ath9k_config(struct ieee80211
1554
1555 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || reset_channel) {
1556 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
1557 - enum nl80211_channel_type channel_type =
1558 - cfg80211_get_chandef_type(&conf->chandef);
1559 int pos = curchan->hw_value;
1560 int old_pos = -1;
1561 unsigned long flags;
1562 @@ -1202,8 +1207,8 @@ static int ath9k_config(struct ieee80211
1563 if (ah->curchan)
1564 old_pos = ah->curchan - &ah->channels[0];
1565
1566 - ath_dbg(common, CONFIG, "Set channel: %d MHz type: %d\n",
1567 - curchan->center_freq, channel_type);
1568 + ath_dbg(common, CONFIG, "Set channel: %d MHz width: %d\n",
1569 + curchan->center_freq, hw->conf.chandef.width);
1570
1571 /* update survey stats for the old channel before switching */
1572 spin_lock_irqsave(&common->cc_lock, flags);
1573 @@ -1211,7 +1216,7 @@ static int ath9k_config(struct ieee80211
1574 spin_unlock_irqrestore(&common->cc_lock, flags);
1575
1576 ath9k_cmn_update_ichannel(&sc->sc_ah->channels[pos],
1577 - curchan, channel_type);
1578 + &conf->chandef);
1579
1580 /*
1581 * If the operating channel changes, change the survey in-use flags
1582 @@ -1374,9 +1379,6 @@ static void ath9k_sta_notify(struct ieee
1583 struct ath_softc *sc = hw->priv;
1584 struct ath_node *an = (struct ath_node *) sta->drv_priv;
1585
1586 - if (!sta->ht_cap.ht_supported)
1587 - return;
1588 -
1589 switch (cmd) {
1590 case STA_NOTIFY_SLEEP:
1591 an->sleeping = true;
1592 @@ -2094,7 +2096,7 @@ static void ath9k_wow_add_pattern(struct
1593 {
1594 struct ath_hw *ah = sc->sc_ah;
1595 struct ath9k_wow_pattern *wow_pattern = NULL;
1596 - struct cfg80211_wowlan_trig_pkt_pattern *patterns = wowlan->patterns;
1597 + struct cfg80211_pkt_pattern *patterns = wowlan->patterns;
1598 int mask_len;
1599 s8 i = 0;
1600
1601 --- a/drivers/net/wireless/mwifiex/cfg80211.c
1602 +++ b/drivers/net/wireless/mwifiex/cfg80211.c
1603 @@ -2298,8 +2298,7 @@ EXPORT_SYMBOL_GPL(mwifiex_del_virtual_in
1604
1605 #ifdef CONFIG_PM
1606 static bool
1607 -mwifiex_is_pattern_supported(struct cfg80211_wowlan_trig_pkt_pattern *pat,
1608 - s8 *byte_seq)
1609 +mwifiex_is_pattern_supported(struct cfg80211_pkt_pattern *pat, s8 *byte_seq)
1610 {
1611 int j, k, valid_byte_cnt = 0;
1612 bool dont_care_byte = false;
1613 --- a/drivers/net/wireless/ti/wlcore/main.c
1614 +++ b/drivers/net/wireless/ti/wlcore/main.c
1615 @@ -1315,7 +1315,7 @@ static struct sk_buff *wl12xx_alloc_dumm
1616
1617 #ifdef CONFIG_PM
1618 static int
1619 -wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern *p)
1620 +wl1271_validate_wowlan_pattern(struct cfg80211_pkt_pattern *p)
1621 {
1622 int num_fields = 0, in_field = 0, fields_size = 0;
1623 int i, pattern_len = 0;
1624 @@ -1458,9 +1458,9 @@ void wl1271_rx_filter_flatten_fields(str
1625 * Allocates an RX filter returned through f
1626 * which needs to be freed using rx_filter_free()
1627 */
1628 -static int wl1271_convert_wowlan_pattern_to_rx_filter(
1629 - struct cfg80211_wowlan_trig_pkt_pattern *p,
1630 - struct wl12xx_rx_filter **f)
1631 +static int
1632 +wl1271_convert_wowlan_pattern_to_rx_filter(struct cfg80211_pkt_pattern *p,
1633 + struct wl12xx_rx_filter **f)
1634 {
1635 int i, j, ret = 0;
1636 struct wl12xx_rx_filter *filter;
1637 @@ -1562,7 +1562,7 @@ static int wl1271_configure_wowlan(struc
1638
1639 /* Translate WoWLAN patterns into filters */
1640 for (i = 0; i < wow->n_patterns; i++) {
1641 - struct cfg80211_wowlan_trig_pkt_pattern *p;
1642 + struct cfg80211_pkt_pattern *p;
1643 struct wl12xx_rx_filter *filter = NULL;
1644
1645 p = &wow->patterns[i];
1646 --- a/include/net/cfg80211.h
1647 +++ b/include/net/cfg80211.h
1648 @@ -639,6 +639,30 @@ struct cfg80211_ap_settings {
1649 };
1650
1651 /**
1652 + * struct cfg80211_csa_settings - channel switch settings
1653 + *
1654 + * Used for channel switch
1655 + *
1656 + * @chandef: defines the channel to use after the switch
1657 + * @beacon_csa: beacon data while performing the switch
1658 + * @counter_offset_beacon: offset for the counter within the beacon (tail)
1659 + * @counter_offset_presp: offset for the counter within the probe response
1660 + * @beacon_after: beacon data to be used on the new channel
1661 + * @radar_required: whether radar detection is required on the new channel
1662 + * @block_tx: whether transmissions should be blocked while changing
1663 + * @count: number of beacons until switch
1664 + */
1665 +struct cfg80211_csa_settings {
1666 + struct cfg80211_chan_def chandef;
1667 + struct cfg80211_beacon_data beacon_csa;
1668 + u16 counter_offset_beacon, counter_offset_presp;
1669 + struct cfg80211_beacon_data beacon_after;
1670 + bool radar_required;
1671 + bool block_tx;
1672 + u8 count;
1673 +};
1674 +
1675 +/**
1676 * enum station_parameters_apply_mask - station parameter values to apply
1677 * @STATION_PARAM_APPLY_UAPSD: apply new uAPSD parameters (uapsd_queues, max_sp)
1678 * @STATION_PARAM_APPLY_CAPABILITY: apply new capability
1679 @@ -1698,7 +1722,7 @@ struct cfg80211_pmksa {
1680 };
1681
1682 /**
1683 - * struct cfg80211_wowlan_trig_pkt_pattern - packet pattern
1684 + * struct cfg80211_pkt_pattern - packet pattern
1685 * @mask: bitmask where to match pattern and where to ignore bytes,
1686 * one bit per byte, in same format as nl80211
1687 * @pattern: bytes to match where bitmask is 1
1688 @@ -1708,7 +1732,7 @@ struct cfg80211_pmksa {
1689 * Internal note: @mask and @pattern are allocated in one chunk of
1690 * memory, free @mask only!
1691 */
1692 -struct cfg80211_wowlan_trig_pkt_pattern {
1693 +struct cfg80211_pkt_pattern {
1694 u8 *mask, *pattern;
1695 int pattern_len;
1696 int pkt_offset;
1697 @@ -1770,7 +1794,7 @@ struct cfg80211_wowlan {
1698 bool any, disconnect, magic_pkt, gtk_rekey_failure,
1699 eap_identity_req, four_way_handshake,
1700 rfkill_release;
1701 - struct cfg80211_wowlan_trig_pkt_pattern *patterns;
1702 + struct cfg80211_pkt_pattern *patterns;
1703 struct cfg80211_wowlan_tcp *tcp;
1704 int n_patterns;
1705 };
1706 @@ -2071,6 +2095,8 @@ struct cfg80211_update_ft_ies_params {
1707 * driver can take the most appropriate actions.
1708 * @crit_proto_stop: Indicates critical protocol no longer needs increased link
1709 * reliability. This operation can not fail.
1710 + *
1711 + * @channel_switch: initiate channel-switch procedure (with CSA)
1712 */
1713 struct cfg80211_ops {
1714 int (*suspend)(struct wiphy *wiphy, struct cfg80211_wowlan *wow);
1715 @@ -2306,6 +2332,10 @@ struct cfg80211_ops {
1716 u16 duration);
1717 void (*crit_proto_stop)(struct wiphy *wiphy,
1718 struct wireless_dev *wdev);
1719 +
1720 + int (*channel_switch)(struct wiphy *wiphy,
1721 + struct net_device *dev,
1722 + struct cfg80211_csa_settings *params);
1723 };
1724
1725 /*
1726 @@ -2371,6 +2401,8 @@ struct cfg80211_ops {
1727 * @WIPHY_FLAG_OFFCHAN_TX: Device supports direct off-channel TX.
1728 * @WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL: Device supports remain-on-channel call.
1729 * @WIPHY_FLAG_SUPPORTS_5_10_MHZ: Device supports 5 MHz and 10 MHz channels.
1730 + * @WIPHY_FLAG_HAS_CHANNEL_SWITCH: Device supports channel switch in
1731 + * beaconing mode (AP, IBSS, Mesh, ...).
1732 */
1733 enum wiphy_flags {
1734 WIPHY_FLAG_CUSTOM_REGULATORY = BIT(0),
1735 @@ -2395,6 +2427,7 @@ enum wiphy_flags {
1736 WIPHY_FLAG_OFFCHAN_TX = BIT(20),
1737 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL = BIT(21),
1738 WIPHY_FLAG_SUPPORTS_5_10_MHZ = BIT(22),
1739 + WIPHY_FLAG_HAS_CHANNEL_SWITCH = BIT(23),
1740 };
1741
1742 /**
1743 --- a/include/uapi/linux/nl80211.h
1744 +++ b/include/uapi/linux/nl80211.h
1745 @@ -648,6 +648,16 @@
1746 * @NL80211_CMD_CRIT_PROTOCOL_STOP: Indicates the connection reliability can
1747 * return back to normal.
1748 *
1749 + * @NL80211_CMD_CHANNEL_SWITCH: Perform a channel switch by announcing the
1750 + * the new channel information (Channel Switch Announcement - CSA)
1751 + * in the beacon for some time (as defined in the
1752 + * %NL80211_ATTR_CH_SWITCH_COUNT parameter) and then change to the
1753 + * new channel. Userspace provides the new channel information (using
1754 + * %NL80211_ATTR_WIPHY_FREQ and the attributes determining channel
1755 + * width). %NL80211_ATTR_CH_SWITCH_BLOCK_TX may be supplied to inform
1756 + * other station that transmission must be blocked until the channel
1757 + * switch is complete.
1758 + *
1759 * @NL80211_CMD_MAX: highest used command number
1760 * @__NL80211_CMD_AFTER_LAST: internal use
1761 */
1762 @@ -810,6 +820,8 @@ enum nl80211_commands {
1763 NL80211_CMD_CRIT_PROTOCOL_START,
1764 NL80211_CMD_CRIT_PROTOCOL_STOP,
1765
1766 + NL80211_CMD_CHANNEL_SWITCH,
1767 +
1768 /* add new commands above here */
1769
1770 /* used to define NL80211_CMD_MAX below */
1771 @@ -1436,6 +1448,18 @@ enum nl80211_commands {
1772 * allowed to be used with the first @NL80211_CMD_SET_STATION command to
1773 * update a TDLS peer STA entry.
1774 *
1775 + * @NL80211_ATTR_CH_SWITCH_COUNT: u32 attribute specifying the number of TBTT's
1776 + * until the channel switch event.
1777 + * @NL80211_ATTR_CH_SWITCH_BLOCK_TX: flag attribute specifying that transmission
1778 + * must be blocked on the current channel (before the channel switch
1779 + * operation).
1780 + * @NL80211_ATTR_CSA_IES: Nested set of attributes containing the IE information
1781 + * for the time while performing a channel switch.
1782 + * @NL80211_ATTR_CSA_C_OFF_BEACON: Offset of the channel switch counter
1783 + * field in the beacons tail (%NL80211_ATTR_BEACON_TAIL).
1784 + * @NL80211_ATTR_CSA_C_OFF_PRESP: Offset of the channel switch counter
1785 + * field in the probe response (%NL80211_ATTR_PROBE_RESP).
1786 + *
1787 * @NL80211_ATTR_MAX: highest attribute number currently defined
1788 * @__NL80211_ATTR_AFTER_LAST: internal use
1789 */
1790 @@ -1736,6 +1760,12 @@ enum nl80211_attrs {
1791
1792 NL80211_ATTR_PEER_AID,
1793
1794 + NL80211_ATTR_CH_SWITCH_COUNT,
1795 + NL80211_ATTR_CH_SWITCH_BLOCK_TX,
1796 + NL80211_ATTR_CSA_IES,
1797 + NL80211_ATTR_CSA_C_OFF_BEACON,
1798 + NL80211_ATTR_CSA_C_OFF_PRESP,
1799 +
1800 /* add attributes here, update the policy in nl80211.c */
1801
1802 __NL80211_ATTR_AFTER_LAST,
1803 @@ -3060,11 +3090,11 @@ enum nl80211_tx_power_setting {
1804 };
1805
1806 /**
1807 - * enum nl80211_wowlan_packet_pattern_attr - WoWLAN packet pattern attribute
1808 - * @__NL80211_WOWLAN_PKTPAT_INVALID: invalid number for nested attribute
1809 - * @NL80211_WOWLAN_PKTPAT_PATTERN: the pattern, values where the mask has
1810 + * enum nl80211_packet_pattern_attr - packet pattern attribute
1811 + * @__NL80211_PKTPAT_INVALID: invalid number for nested attribute
1812 + * @NL80211_PKTPAT_PATTERN: the pattern, values where the mask has
1813 * a zero bit are ignored
1814 - * @NL80211_WOWLAN_PKTPAT_MASK: pattern mask, must be long enough to have
1815 + * @NL80211_PKTPAT_MASK: pattern mask, must be long enough to have
1816 * a bit for each byte in the pattern. The lowest-order bit corresponds
1817 * to the first byte of the pattern, but the bytes of the pattern are
1818 * in a little-endian-like format, i.e. the 9th byte of the pattern
1819 @@ -3075,23 +3105,23 @@ enum nl80211_tx_power_setting {
1820 * Note that the pattern matching is done as though frames were not
1821 * 802.11 frames but 802.3 frames, i.e. the frame is fully unpacked
1822 * first (including SNAP header unpacking) and then matched.
1823 - * @NL80211_WOWLAN_PKTPAT_OFFSET: packet offset, pattern is matched after
1824 + * @NL80211_PKTPAT_OFFSET: packet offset, pattern is matched after
1825 * these fixed number of bytes of received packet
1826 - * @NUM_NL80211_WOWLAN_PKTPAT: number of attributes
1827 - * @MAX_NL80211_WOWLAN_PKTPAT: max attribute number
1828 + * @NUM_NL80211_PKTPAT: number of attributes
1829 + * @MAX_NL80211_PKTPAT: max attribute number
1830 */
1831 -enum nl80211_wowlan_packet_pattern_attr {
1832 - __NL80211_WOWLAN_PKTPAT_INVALID,
1833 - NL80211_WOWLAN_PKTPAT_MASK,
1834 - NL80211_WOWLAN_PKTPAT_PATTERN,
1835 - NL80211_WOWLAN_PKTPAT_OFFSET,
1836 +enum nl80211_packet_pattern_attr {
1837 + __NL80211_PKTPAT_INVALID,
1838 + NL80211_PKTPAT_MASK,
1839 + NL80211_PKTPAT_PATTERN,
1840 + NL80211_PKTPAT_OFFSET,
1841
1842 - NUM_NL80211_WOWLAN_PKTPAT,
1843 - MAX_NL80211_WOWLAN_PKTPAT = NUM_NL80211_WOWLAN_PKTPAT - 1,
1844 + NUM_NL80211_PKTPAT,
1845 + MAX_NL80211_PKTPAT = NUM_NL80211_PKTPAT - 1,
1846 };
1847
1848 /**
1849 - * struct nl80211_wowlan_pattern_support - pattern support information
1850 + * struct nl80211_pattern_support - packet pattern support information
1851 * @max_patterns: maximum number of patterns supported
1852 * @min_pattern_len: minimum length of each pattern
1853 * @max_pattern_len: maximum length of each pattern
1854 @@ -3101,13 +3131,22 @@ enum nl80211_wowlan_packet_pattern_attr
1855 * that is part of %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED in the
1856 * capability information given by the kernel to userspace.
1857 */
1858 -struct nl80211_wowlan_pattern_support {
1859 +struct nl80211_pattern_support {
1860 __u32 max_patterns;
1861 __u32 min_pattern_len;
1862 __u32 max_pattern_len;
1863 __u32 max_pkt_offset;
1864 } __attribute__((packed));
1865
1866 +/* only for backward compatibility */
1867 +#define __NL80211_WOWLAN_PKTPAT_INVALID __NL80211_PKTPAT_INVALID
1868 +#define NL80211_WOWLAN_PKTPAT_MASK NL80211_PKTPAT_MASK
1869 +#define NL80211_WOWLAN_PKTPAT_PATTERN NL80211_PKTPAT_PATTERN
1870 +#define NL80211_WOWLAN_PKTPAT_OFFSET NL80211_PKTPAT_OFFSET
1871 +#define NUM_NL80211_WOWLAN_PKTPAT NUM_NL80211_PKTPAT
1872 +#define MAX_NL80211_WOWLAN_PKTPAT MAX_NL80211_PKTPAT
1873 +#define nl80211_wowlan_pattern_support nl80211_pattern_support
1874 +
1875 /**
1876 * enum nl80211_wowlan_triggers - WoWLAN trigger definitions
1877 * @__NL80211_WOWLAN_TRIG_INVALID: invalid number for nested attributes
1878 @@ -3127,7 +3166,7 @@ struct nl80211_wowlan_pattern_support {
1879 * pattern matching is done after the packet is converted to the MSDU.
1880 *
1881 * In %NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED, it is a binary attribute
1882 - * carrying a &struct nl80211_wowlan_pattern_support.
1883 + * carrying a &struct nl80211_pattern_support.
1884 *
1885 * When reporting wakeup. it is a u32 attribute containing the 0-based
1886 * index of the pattern that caused the wakeup, in the patterns passed
1887 @@ -3284,7 +3323,7 @@ struct nl80211_wowlan_tcp_data_token_fea
1888 * @NL80211_WOWLAN_TCP_WAKE_PAYLOAD: wake packet payload, for advertising a
1889 * u32 attribute holding the maximum length
1890 * @NL80211_WOWLAN_TCP_WAKE_MASK: Wake packet payload mask, not used for
1891 - * feature advertising. The mask works like @NL80211_WOWLAN_PKTPAT_MASK
1892 + * feature advertising. The mask works like @NL80211_PKTPAT_MASK
1893 * but on the TCP payload only.
1894 * @NUM_NL80211_WOWLAN_TCP: number of TCP attributes
1895 * @MAX_NL80211_WOWLAN_TCP: highest attribute number
1896 --- a/net/mac80211/mesh_ps.c
1897 +++ b/net/mac80211/mesh_ps.c
1898 @@ -229,6 +229,10 @@ void ieee80211_mps_sta_status_update(str
1899 enum nl80211_mesh_power_mode pm;
1900 bool do_buffer;
1901
1902 + /* For non-assoc STA, prevent buffering or frame transmission */
1903 + if (sta->sta_state < IEEE80211_STA_ASSOC)
1904 + return;
1905 +
1906 /*
1907 * use peer-specific power mode if peering is established and the
1908 * peer's power mode is known
1909 --- a/net/wireless/nl80211.c
1910 +++ b/net/wireless/nl80211.c
1911 @@ -349,6 +349,11 @@ static const struct nla_policy nl80211_p
1912 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
1913 .len = IEEE80211_MAX_DATA_LEN },
1914 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
1915 + [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
1916 + [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
1917 + [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
1918 + [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_U16 },
1919 + [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_U16 },
1920 };
1921
1922 /* policy for the key attributes */
1923 @@ -441,10 +446,12 @@ static int nl80211_prepare_wdev_dump(str
1924 goto out_unlock;
1925 }
1926 *rdev = wiphy_to_dev((*wdev)->wiphy);
1927 - cb->args[0] = (*rdev)->wiphy_idx;
1928 + /* 0 is the first index - add 1 to parse only once */
1929 + cb->args[0] = (*rdev)->wiphy_idx + 1;
1930 cb->args[1] = (*wdev)->identifier;
1931 } else {
1932 - struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0]);
1933 + /* subtract the 1 again here */
1934 + struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
1935 struct wireless_dev *tmp;
1936
1937 if (!wiphy) {
1938 @@ -974,7 +981,7 @@ static int nl80211_send_wowlan(struct sk
1939 return -ENOBUFS;
1940
1941 if (dev->wiphy.wowlan->n_patterns) {
1942 - struct nl80211_wowlan_pattern_support pat = {
1943 + struct nl80211_pattern_support pat = {
1944 .max_patterns = dev->wiphy.wowlan->n_patterns,
1945 .min_pattern_len = dev->wiphy.wowlan->pattern_min_len,
1946 .max_pattern_len = dev->wiphy.wowlan->pattern_max_len,
1947 @@ -1393,6 +1400,8 @@ static int nl80211_send_wiphy(struct cfg
1948 if (state->split) {
1949 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1950 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
1951 + if (dev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
1952 + CMD(channel_switch, CHANNEL_SWITCH);
1953 }
1954
1955 #ifdef CPTCFG_NL80211_TESTMODE
1956 @@ -1568,8 +1577,10 @@ static int nl80211_dump_wiphy(struct sk_
1957 rtnl_lock();
1958 if (!state) {
1959 state = kzalloc(sizeof(*state), GFP_KERNEL);
1960 - if (!state)
1961 + if (!state) {
1962 + rtnl_unlock();
1963 return -ENOMEM;
1964 + }
1965 state->filter_wiphy = -1;
1966 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1967 if (ret) {
1968 @@ -2620,8 +2631,8 @@ static int nl80211_get_key(struct sk_buf
1969
1970 hdr = nl80211hdr_put(msg, genl_info_snd_portid(info), info->snd_seq, 0,
1971 NL80211_CMD_NEW_KEY);
1972 - if (IS_ERR(hdr))
1973 - return PTR_ERR(hdr);
1974 + if (!hdr)
1975 + return -ENOBUFS;
1976
1977 cookie.msg = msg;
1978 cookie.idx = key_idx;
1979 @@ -4770,9 +4781,9 @@ do { \
1980 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
1981 mask, NL80211_MESHCONF_FORWARDING,
1982 nla_get_u8);
1983 - FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, 1, 255,
1984 + FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
1985 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
1986 - nla_get_u32);
1987 + nla_get_s32);
1988 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
1989 mask, NL80211_MESHCONF_HT_OPMODE,
1990 nla_get_u16);
1991 @@ -5578,6 +5589,111 @@ static int nl80211_start_radar_detection
1992 return err;
1993 }
1994
1995 +static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
1996 +{
1997 + struct cfg80211_registered_device *rdev = info->user_ptr[0];
1998 + struct net_device *dev = info->user_ptr[1];
1999 + struct wireless_dev *wdev = dev->ieee80211_ptr;
2000 + struct cfg80211_csa_settings params;
2001 + /* csa_attrs is defined static to avoid waste of stack size - this
2002 + * function is called under RTNL lock, so this should not be a problem.
2003 + */
2004 + static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
2005 + u8 radar_detect_width = 0;
2006 + int err;
2007 +
2008 + if (!rdev->ops->channel_switch ||
2009 + !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
2010 + return -EOPNOTSUPP;
2011 +
2012 + /* may add IBSS support later */
2013 + if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
2014 + dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2015 + return -EOPNOTSUPP;
2016 +
2017 + memset(&params, 0, sizeof(params));
2018 +
2019 + if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
2020 + !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
2021 + return -EINVAL;
2022 +
2023 + /* only important for AP, IBSS and mesh create IEs internally */
2024 + if (!info->attrs[NL80211_ATTR_CSA_IES])
2025 + return -EINVAL;
2026 +
2027 + /* useless if AP is not running */
2028 + if (!wdev->beacon_interval)
2029 + return -EINVAL;
2030 +
2031 + params.count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
2032 +
2033 + err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
2034 + if (err)
2035 + return err;
2036 +
2037 + err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
2038 + info->attrs[NL80211_ATTR_CSA_IES],
2039 + nl80211_policy);
2040 + if (err)
2041 + return err;
2042 +
2043 + err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
2044 + if (err)
2045 + return err;
2046 +
2047 + if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
2048 + return -EINVAL;
2049 +
2050 + params.counter_offset_beacon =
2051 + nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
2052 + if (params.counter_offset_beacon >= params.beacon_csa.tail_len)
2053 + return -EINVAL;
2054 +
2055 + /* sanity check - counters should be the same */
2056 + if (params.beacon_csa.tail[params.counter_offset_beacon] !=
2057 + params.count)
2058 + return -EINVAL;
2059 +
2060 + if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
2061 + params.counter_offset_presp =
2062 + nla_get_u16(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
2063 + if (params.counter_offset_presp >=
2064 + params.beacon_csa.probe_resp_len)
2065 + return -EINVAL;
2066 +
2067 + if (params.beacon_csa.probe_resp[params.counter_offset_presp] !=
2068 + params.count)
2069 + return -EINVAL;
2070 + }
2071 +
2072 + err = nl80211_parse_chandef(rdev, info, &params.chandef);
2073 + if (err)
2074 + return err;
2075 +
2076 + if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef))
2077 + return -EINVAL;
2078 +
2079 + err = cfg80211_chandef_dfs_required(wdev->wiphy, &params.chandef);
2080 + if (err < 0) {
2081 + return err;
2082 + } else if (err) {
2083 + radar_detect_width = BIT(params.chandef.width);
2084 + params.radar_required = true;
2085 + }
2086 +
2087 + err = cfg80211_can_use_iftype_chan(rdev, wdev, wdev->iftype,
2088 + params.chandef.chan,
2089 + CHAN_MODE_SHARED,
2090 + radar_detect_width);
2091 + if (err)
2092 + return err;
2093 +
2094 + if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
2095 + params.block_tx = true;
2096 +
2097 + return rdev_channel_switch(rdev, dev, &params);
2098 +}
2099 +
2100 static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
2101 u32 seq, int flags,
2102 struct cfg80211_registered_device *rdev,
2103 @@ -6507,6 +6623,9 @@ static int nl80211_testmode_dump(struct
2104 NL80211_CMD_TESTMODE);
2105 struct nlattr *tmdata;
2106
2107 + if (!hdr)
2108 + break;
2109 +
2110 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
2111 genlmsg_cancel(skb, hdr);
2112 break;
2113 @@ -6615,12 +6734,14 @@ EXPORT_SYMBOL(cfg80211_testmode_alloc_ev
2114
2115 void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp)
2116 {
2117 + struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
2118 void *hdr = ((void **)skb->cb)[1];
2119 struct nlattr *data = ((void **)skb->cb)[2];
2120
2121 nla_nest_end(skb, data);
2122 genlmsg_end(skb, hdr);
2123 - genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp);
2124 + genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), skb, 0,
2125 + nl80211_testmode_mcgrp.id, gfp);
2126 }
2127 EXPORT_SYMBOL(cfg80211_testmode_event);
2128 #endif
2129 @@ -6949,9 +7070,8 @@ static int nl80211_remain_on_channel(str
2130
2131 hdr = nl80211hdr_put(msg, genl_info_snd_portid(info), info->snd_seq, 0,
2132 NL80211_CMD_REMAIN_ON_CHANNEL);
2133 -
2134 - if (IS_ERR(hdr)) {
2135 - err = PTR_ERR(hdr);
2136 + if (!hdr) {
2137 + err = -ENOBUFS;
2138 goto free_msg;
2139 }
2140
2141 @@ -7249,9 +7369,8 @@ static int nl80211_tx_mgmt(struct sk_buf
2142
2143 hdr = nl80211hdr_put(msg, genl_info_snd_portid(info), info->snd_seq, 0,
2144 NL80211_CMD_FRAME);
2145 -
2146 - if (IS_ERR(hdr)) {
2147 - err = PTR_ERR(hdr);
2148 + if (!hdr) {
2149 + err = -ENOBUFS;
2150 goto free_msg;
2151 }
2152 }
2153 @@ -7593,12 +7712,11 @@ static int nl80211_send_wowlan_patterns(
2154 if (!nl_pat)
2155 return -ENOBUFS;
2156 pat_len = wowlan->patterns[i].pattern_len;
2157 - if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK,
2158 - DIV_ROUND_UP(pat_len, 8),
2159 + if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
2160 wowlan->patterns[i].mask) ||
2161 - nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN,
2162 - pat_len, wowlan->patterns[i].pattern) ||
2163 - nla_put_u32(msg, NL80211_WOWLAN_PKTPAT_OFFSET,
2164 + nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
2165 + wowlan->patterns[i].pattern) ||
2166 + nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
2167 wowlan->patterns[i].pkt_offset))
2168 return -ENOBUFS;
2169 nla_nest_end(msg, nl_pat);
2170 @@ -7939,7 +8057,7 @@ static int nl80211_set_wowlan(struct sk_
2171 struct nlattr *pat;
2172 int n_patterns = 0;
2173 int rem, pat_len, mask_len, pkt_offset;
2174 - struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT];
2175 + struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
2176
2177 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
2178 rem)
2179 @@ -7958,26 +8076,25 @@ static int nl80211_set_wowlan(struct sk_
2180
2181 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
2182 rem) {
2183 - nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT,
2184 - nla_data(pat), nla_len(pat), NULL);
2185 + nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
2186 + nla_len(pat), NULL);
2187 err = -EINVAL;
2188 - if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] ||
2189 - !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN])
2190 + if (!pat_tb[NL80211_PKTPAT_MASK] ||
2191 + !pat_tb[NL80211_PKTPAT_PATTERN])
2192 goto error;
2193 - pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]);
2194 + pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
2195 mask_len = DIV_ROUND_UP(pat_len, 8);
2196 - if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) !=
2197 - mask_len)
2198 + if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
2199 goto error;
2200 if (pat_len > wowlan->pattern_max_len ||
2201 pat_len < wowlan->pattern_min_len)
2202 goto error;
2203
2204 - if (!pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET])
2205 + if (!pat_tb[NL80211_PKTPAT_OFFSET])
2206 pkt_offset = 0;
2207 else
2208 pkt_offset = nla_get_u32(
2209 - pat_tb[NL80211_WOWLAN_PKTPAT_OFFSET]);
2210 + pat_tb[NL80211_PKTPAT_OFFSET]);
2211 if (pkt_offset > wowlan->max_pkt_offset)
2212 goto error;
2213 new_triggers.patterns[i].pkt_offset = pkt_offset;
2214 @@ -7991,11 +8108,11 @@ static int nl80211_set_wowlan(struct sk_
2215 new_triggers.patterns[i].pattern =
2216 new_triggers.patterns[i].mask + mask_len;
2217 memcpy(new_triggers.patterns[i].mask,
2218 - nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]),
2219 + nla_data(pat_tb[NL80211_PKTPAT_MASK]),
2220 mask_len);
2221 new_triggers.patterns[i].pattern_len = pat_len;
2222 memcpy(new_triggers.patterns[i].pattern,
2223 - nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]),
2224 + nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
2225 pat_len);
2226 i++;
2227 }
2228 @@ -8130,9 +8247,8 @@ static int nl80211_probe_client(struct s
2229
2230 hdr = nl80211hdr_put(msg, genl_info_snd_portid(info), info->snd_seq, 0,
2231 NL80211_CMD_PROBE_CLIENT);
2232 -
2233 - if (IS_ERR(hdr)) {
2234 - err = PTR_ERR(hdr);
2235 + if (!hdr) {
2236 + err = -ENOBUFS;
2237 goto free_msg;
2238 }
2239
2240 @@ -9041,7 +9157,15 @@ static struct genl_ops nl80211_ops[] = {
2241 .flags = GENL_ADMIN_PERM,
2242 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
2243 NL80211_FLAG_NEED_RTNL,
2244 - }
2245 + },
2246 + {
2247 + .cmd = NL80211_CMD_CHANNEL_SWITCH,
2248 + .doit = nl80211_channel_switch,
2249 + .policy = nl80211_policy,
2250 + .flags = GENL_ADMIN_PERM,
2251 + .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
2252 + NL80211_FLAG_NEED_RTNL,
2253 + },
2254 };
2255
2256 static struct genl_multicast_group nl80211_mlme_mcgrp = {
2257 @@ -10066,7 +10190,8 @@ void cfg80211_mgmt_tx_status(struct wire
2258
2259 genlmsg_end(msg, hdr);
2260
2261 - genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
2262 + genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0,
2263 + nl80211_mlme_mcgrp.id, gfp);
2264 return;
2265
2266 nla_put_failure:
2267 --- a/net/wireless/reg.c
2268 +++ b/net/wireless/reg.c
2269 @@ -2247,10 +2247,13 @@ int reg_device_uevent(struct device *dev
2270
2271 void wiphy_regulatory_register(struct wiphy *wiphy)
2272 {
2273 + struct regulatory_request *lr;
2274 +
2275 if (!reg_dev_ignore_cell_hint(wiphy))
2276 reg_num_devs_support_basehint++;
2277
2278 - wiphy_update_regulatory(wiphy, NL80211_REGDOM_SET_BY_CORE);
2279 + lr = get_last_request();
2280 + wiphy_update_regulatory(wiphy, lr->initiator);
2281 }
2282
2283 void wiphy_regulatory_deregister(struct wiphy *wiphy)
2284 @@ -2279,7 +2282,9 @@ void wiphy_regulatory_deregister(struct
2285 static void reg_timeout_work(struct work_struct *work)
2286 {
2287 REG_DBG_PRINT("Timeout while waiting for CRDA to reply, restoring regulatory settings\n");
2288 + rtnl_lock();
2289 restore_regulatory_settings(true);
2290 + rtnl_unlock();
2291 }
2292
2293 int __init regulatory_init(void)
2294 --- a/net/wireless/sme.c
2295 +++ b/net/wireless/sme.c
2296 @@ -34,8 +34,10 @@ struct cfg80211_conn {
2297 CFG80211_CONN_SCAN_AGAIN,
2298 CFG80211_CONN_AUTHENTICATE_NEXT,
2299 CFG80211_CONN_AUTHENTICATING,
2300 + CFG80211_CONN_AUTH_FAILED,
2301 CFG80211_CONN_ASSOCIATE_NEXT,
2302 CFG80211_CONN_ASSOCIATING,
2303 + CFG80211_CONN_ASSOC_FAILED,
2304 CFG80211_CONN_DEAUTH,
2305 CFG80211_CONN_CONNECTED,
2306 } state;
2307 @@ -164,6 +166,8 @@ static int cfg80211_conn_do_work(struct
2308 NULL, 0,
2309 params->key, params->key_len,
2310 params->key_idx, NULL, 0);
2311 + case CFG80211_CONN_AUTH_FAILED:
2312 + return -ENOTCONN;
2313 case CFG80211_CONN_ASSOCIATE_NEXT:
2314 BUG_ON(!rdev->ops->assoc);
2315 wdev->conn->state = CFG80211_CONN_ASSOCIATING;
2316 @@ -188,10 +192,17 @@ static int cfg80211_conn_do_work(struct
2317 WLAN_REASON_DEAUTH_LEAVING,
2318 false);
2319 return err;
2320 + case CFG80211_CONN_ASSOC_FAILED:
2321 + cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
2322 + NULL, 0,
2323 + WLAN_REASON_DEAUTH_LEAVING, false);
2324 + return -ENOTCONN;
2325 case CFG80211_CONN_DEAUTH:
2326 cfg80211_mlme_deauth(rdev, wdev->netdev, params->bssid,
2327 NULL, 0,
2328 WLAN_REASON_DEAUTH_LEAVING, false);
2329 + /* free directly, disconnected event already sent */
2330 + cfg80211_sme_free(wdev);
2331 return 0;
2332 default:
2333 return 0;
2334 @@ -371,7 +382,7 @@ bool cfg80211_sme_rx_assoc_resp(struct w
2335 return true;
2336 }
2337
2338 - wdev->conn->state = CFG80211_CONN_DEAUTH;
2339 + wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
2340 schedule_work(&rdev->conn_work);
2341 return false;
2342 }
2343 @@ -383,7 +394,13 @@ void cfg80211_sme_deauth(struct wireless
2344
2345 void cfg80211_sme_auth_timeout(struct wireless_dev *wdev)
2346 {
2347 - cfg80211_sme_free(wdev);
2348 + struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
2349 +
2350 + if (!wdev->conn)
2351 + return;
2352 +
2353 + wdev->conn->state = CFG80211_CONN_AUTH_FAILED;
2354 + schedule_work(&rdev->conn_work);
2355 }
2356
2357 void cfg80211_sme_disassoc(struct wireless_dev *wdev)
2358 @@ -399,7 +416,13 @@ void cfg80211_sme_disassoc(struct wirele
2359
2360 void cfg80211_sme_assoc_timeout(struct wireless_dev *wdev)
2361 {
2362 - cfg80211_sme_disassoc(wdev);
2363 + struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy);
2364 +
2365 + if (!wdev->conn)
2366 + return;
2367 +
2368 + wdev->conn->state = CFG80211_CONN_ASSOC_FAILED;
2369 + schedule_work(&rdev->conn_work);
2370 }
2371
2372 static int cfg80211_sme_connect(struct wireless_dev *wdev,
2373 @@ -953,21 +976,19 @@ int cfg80211_disconnect(struct cfg80211_
2374 struct net_device *dev, u16 reason, bool wextev)
2375 {
2376 struct wireless_dev *wdev = dev->ieee80211_ptr;
2377 - int err;
2378 + int err = 0;
2379
2380 ASSERT_WDEV_LOCK(wdev);
2381
2382 kfree(wdev->connect_keys);
2383 wdev->connect_keys = NULL;
2384
2385 - if (wdev->conn) {
2386 + if (wdev->conn)
2387 err = cfg80211_sme_disconnect(wdev, reason);
2388 - } else if (!rdev->ops->disconnect) {
2389 + else if (!rdev->ops->disconnect)
2390 cfg80211_mlme_down(rdev, dev);
2391 - err = 0;
2392 - } else {
2393 + else if (wdev->current_bss)
2394 err = rdev_disconnect(rdev, dev, reason);
2395 - }
2396
2397 return err;
2398 }
2399 --- a/net/mac80211/rc80211_minstrel.c
2400 +++ b/net/mac80211/rc80211_minstrel.c
2401 @@ -203,6 +203,15 @@ minstrel_update_stats(struct minstrel_pr
2402 memcpy(mi->max_tp_rate, tmp_tp_rate, sizeof(mi->max_tp_rate));
2403 mi->max_prob_rate = tmp_prob_rate;
2404
2405 +#ifdef CPTCFG_MAC80211_DEBUGFS
2406 + /* use fixed index if set */
2407 + if (mp->fixed_rate_idx != -1) {
2408 + mi->max_tp_rate[0] = mp->fixed_rate_idx;
2409 + mi->max_tp_rate[1] = mp->fixed_rate_idx;
2410 + mi->max_prob_rate = mp->fixed_rate_idx;
2411 + }
2412 +#endif
2413 +
2414 /* Reset update timer */
2415 mi->stats_update = jiffies;
2416
2417 @@ -290,7 +299,7 @@ minstrel_get_rate(void *priv, struct iee
2418 struct minstrel_rate *msr, *mr;
2419 unsigned int ndx;
2420 bool mrr_capable;
2421 - bool prev_sample = mi->prev_sample;
2422 + bool prev_sample;
2423 int delta;
2424 int sampling_ratio;
2425
2426 @@ -310,10 +319,16 @@ minstrel_get_rate(void *priv, struct iee
2427 /* increase sum packet counter */
2428 mi->packet_count++;
2429
2430 +#ifdef CPTCFG_MAC80211_DEBUGFS
2431 + if (mp->fixed_rate_idx != -1)
2432 + return;
2433 +#endif
2434 +
2435 delta = (mi->packet_count * sampling_ratio / 100) -
2436 (mi->sample_count + mi->sample_deferred / 2);
2437
2438 /* delta < 0: no sampling required */
2439 + prev_sample = mi->prev_sample;
2440 mi->prev_sample = false;
2441 if (delta < 0 || (!mrr_capable && prev_sample))
2442 return;
2443 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
2444 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
2445 @@ -936,13 +936,8 @@ void rt2x00queue_index_inc(struct queue_
2446 spin_unlock_irqrestore(&queue->index_lock, irqflags);
2447 }
2448
2449 -void rt2x00queue_pause_queue(struct data_queue *queue)
2450 +void rt2x00queue_pause_queue_nocheck(struct data_queue *queue)
2451 {
2452 - if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) ||
2453 - !test_bit(QUEUE_STARTED, &queue->flags) ||
2454 - test_and_set_bit(QUEUE_PAUSED, &queue->flags))
2455 - return;
2456 -
2457 switch (queue->qid) {
2458 case QID_AC_VO:
2459 case QID_AC_VI:
2460 @@ -958,6 +953,15 @@ void rt2x00queue_pause_queue(struct data
2461 break;
2462 }
2463 }
2464 +void rt2x00queue_pause_queue(struct data_queue *queue)
2465 +{
2466 + if (!test_bit(DEVICE_STATE_PRESENT, &queue->rt2x00dev->flags) ||
2467 + !test_bit(QUEUE_STARTED, &queue->flags) ||
2468 + test_and_set_bit(QUEUE_PAUSED, &queue->flags))
2469 + return;
2470 +
2471 + rt2x00queue_pause_queue_nocheck(queue);
2472 +}
2473 EXPORT_SYMBOL_GPL(rt2x00queue_pause_queue);
2474
2475 void rt2x00queue_unpause_queue(struct data_queue *queue)
2476 @@ -1019,7 +1023,7 @@ void rt2x00queue_stop_queue(struct data_
2477 return;
2478 }
2479
2480 - rt2x00queue_pause_queue(queue);
2481 + rt2x00queue_pause_queue_nocheck(queue);
2482
2483 queue->rt2x00dev->ops->lib->stop_queue(queue);
2484
2485 --- a/net/mac80211/mlme.c
2486 +++ b/net/mac80211/mlme.c
2487 @@ -31,10 +31,12 @@
2488 #include "led.h"
2489
2490 #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
2491 +#define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
2492 #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
2493 #define IEEE80211_AUTH_MAX_TRIES 3
2494 #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
2495 #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
2496 +#define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
2497 #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
2498 #define IEEE80211_ASSOC_MAX_TRIES 3
2499
2500 @@ -209,8 +211,9 @@ ieee80211_determine_chantype(struct ieee
2501 struct ieee80211_channel *channel,
2502 const struct ieee80211_ht_operation *ht_oper,
2503 const struct ieee80211_vht_operation *vht_oper,
2504 - struct cfg80211_chan_def *chandef, bool verbose)
2505 + struct cfg80211_chan_def *chandef, bool tracking)
2506 {
2507 + struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
2508 struct cfg80211_chan_def vht_chandef;
2509 u32 ht_cfreq, ret;
2510
2511 @@ -229,7 +232,7 @@ ieee80211_determine_chantype(struct ieee
2512 ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
2513 channel->band);
2514 /* check that channel matches the right operating channel */
2515 - if (channel->center_freq != ht_cfreq) {
2516 + if (!tracking && channel->center_freq != ht_cfreq) {
2517 /*
2518 * It's possible that some APs are confused here;
2519 * Netgear WNDR3700 sometimes reports 4 higher than
2520 @@ -237,11 +240,10 @@ ieee80211_determine_chantype(struct ieee
2521 * since we look at probe response/beacon data here
2522 * it should be OK.
2523 */
2524 - if (verbose)
2525 - sdata_info(sdata,
2526 - "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
2527 - channel->center_freq, ht_cfreq,
2528 - ht_oper->primary_chan, channel->band);
2529 + sdata_info(sdata,
2530 + "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
2531 + channel->center_freq, ht_cfreq,
2532 + ht_oper->primary_chan, channel->band);
2533 ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
2534 goto out;
2535 }
2536 @@ -295,7 +297,7 @@ ieee80211_determine_chantype(struct ieee
2537 channel->band);
2538 break;
2539 default:
2540 - if (verbose)
2541 + if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2542 sdata_info(sdata,
2543 "AP VHT operation IE has invalid channel width (%d), disable VHT\n",
2544 vht_oper->chan_width);
2545 @@ -304,7 +306,7 @@ ieee80211_determine_chantype(struct ieee
2546 }
2547
2548 if (!cfg80211_chandef_valid(&vht_chandef)) {
2549 - if (verbose)
2550 + if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2551 sdata_info(sdata,
2552 "AP VHT information is invalid, disable VHT\n");
2553 ret = IEEE80211_STA_DISABLE_VHT;
2554 @@ -317,7 +319,7 @@ ieee80211_determine_chantype(struct ieee
2555 }
2556
2557 if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
2558 - if (verbose)
2559 + if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
2560 sdata_info(sdata,
2561 "AP VHT information doesn't match HT, disable VHT\n");
2562 ret = IEEE80211_STA_DISABLE_VHT;
2563 @@ -333,18 +335,27 @@ out:
2564 if (ret & IEEE80211_STA_DISABLE_VHT)
2565 vht_chandef = *chandef;
2566
2567 + /*
2568 + * Ignore the DISABLED flag when we're already connected and only
2569 + * tracking the APs beacon for bandwidth changes - otherwise we
2570 + * might get disconnected here if we connect to an AP, update our
2571 + * regulatory information based on the AP's country IE and the
2572 + * information we have is wrong/outdated and disables the channel
2573 + * that we're actually using for the connection to the AP.
2574 + */
2575 while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
2576 - IEEE80211_CHAN_DISABLED)) {
2577 + tracking ? 0 :
2578 + IEEE80211_CHAN_DISABLED)) {
2579 if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
2580 ret = IEEE80211_STA_DISABLE_HT |
2581 IEEE80211_STA_DISABLE_VHT;
2582 - goto out;
2583 + break;
2584 }
2585
2586 ret |= chandef_downgrade(chandef);
2587 }
2588
2589 - if (chandef->width != vht_chandef.width && verbose)
2590 + if (chandef->width != vht_chandef.width && !tracking)
2591 sdata_info(sdata,
2592 "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
2593
2594 @@ -384,7 +395,7 @@ static int ieee80211_config_bw(struct ie
2595
2596 /* calculate new channel (type) based on HT/VHT operation IEs */
2597 flags = ieee80211_determine_chantype(sdata, sband, chan, ht_oper,
2598 - vht_oper, &chandef, false);
2599 + vht_oper, &chandef, true);
2600
2601 /*
2602 * Downgrade the new channel if we associated with restricted
2603 @@ -1043,6 +1054,13 @@ ieee80211_sta_process_chanswitch(struct
2604 if (!ieee80211_operating_class_to_band(
2605 elems->ext_chansw_ie->new_operating_class,
2606 &new_band)) {
2607 + /*
2608 + * Some APs send invalid ECSA IEs in probe response
2609 + * frames, so check for these and ignore them.
2610 + */
2611 + if (beacon && elems->ext_chansw_ie->new_ch_num == 0 &&
2612 + elems->ext_chansw_ie->new_operating_class == 0)
2613 + return;
2614 sdata_info(sdata,
2615 "cannot understand ECSA IE operating class %d, disconnecting\n",
2616 elems->ext_chansw_ie->new_operating_class);
2617 @@ -1110,6 +1128,15 @@ ieee80211_sta_process_chanswitch(struct
2618 case -1:
2619 cfg80211_chandef_create(&new_chandef, new_chan,
2620 NL80211_CHAN_NO_HT);
2621 + /* keep width for 5/10 MHz channels */
2622 + switch (sdata->vif.bss_conf.chandef.width) {
2623 + case NL80211_CHAN_WIDTH_5:
2624 + case NL80211_CHAN_WIDTH_10:
2625 + new_chandef.width = sdata->vif.bss_conf.chandef.width;
2626 + break;
2627 + default:
2628 + break;
2629 + }
2630 break;
2631 }
2632
2633 @@ -3394,10 +3421,13 @@ static int ieee80211_probe_auth(struct i
2634
2635 if (tx_flags == 0) {
2636 auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
2637 - ifmgd->auth_data->timeout_started = true;
2638 + auth_data->timeout_started = true;
2639 run_again(sdata, auth_data->timeout);
2640 } else {
2641 - auth_data->timeout_started = false;
2642 + auth_data->timeout =
2643 + round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
2644 + auth_data->timeout_started = true;
2645 + run_again(sdata, auth_data->timeout);
2646 }
2647
2648 return 0;
2649 @@ -3434,7 +3464,11 @@ static int ieee80211_do_assoc(struct iee
2650 assoc_data->timeout_started = true;
2651 run_again(sdata, assoc_data->timeout);
2652 } else {
2653 - assoc_data->timeout_started = false;
2654 + assoc_data->timeout =
2655 + round_jiffies_up(jiffies +
2656 + IEEE80211_ASSOC_TIMEOUT_LONG);
2657 + assoc_data->timeout_started = true;
2658 + run_again(sdata, assoc_data->timeout);
2659 }
2660
2661 return 0;
2662 @@ -3829,7 +3863,7 @@ static int ieee80211_prep_channel(struct
2663 ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
2664 cbss->channel,
2665 ht_oper, vht_oper,
2666 - &chandef, true);
2667 + &chandef, false);
2668
2669 sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
2670 local->rx_chains);
2671 --- a/net/wireless/core.c
2672 +++ b/net/wireless/core.c
2673 @@ -772,6 +772,7 @@ void cfg80211_leave(struct cfg80211_regi
2674 cfg80211_leave_mesh(rdev, dev);
2675 break;
2676 case NL80211_IFTYPE_AP:
2677 + case NL80211_IFTYPE_P2P_GO:
2678 cfg80211_stop_ap(rdev, dev);
2679 break;
2680 default:
2681 --- a/drivers/net/wireless/rtlwifi/Kconfig
2682 +++ b/drivers/net/wireless/rtlwifi/Kconfig
2683 @@ -1,29 +1,22 @@
2684 -config RTLWIFI
2685 - tristate "Realtek wireless card support"
2686 +menuconfig RTL_CARDS
2687 + tristate "Realtek rtlwifi family of devices"
2688 depends on m
2689 - depends on MAC80211
2690 - select BACKPORT_FW_LOADER
2691 - ---help---
2692 - This is common code for RTL8192CE/RTL8192CU/RTL8192SE/RTL8723AE
2693 - drivers. This module does nothing by itself - the various front-end
2694 - drivers need to be enabled to support any desired devices.
2695 -
2696 - If you choose to build as a module, it'll be called rtlwifi.
2697 -
2698 -config RTLWIFI_DEBUG
2699 - bool "Debugging output for rtlwifi driver family"
2700 - depends on RTLWIFI
2701 + depends on MAC80211 && (PCI || USB)
2702 default y
2703 ---help---
2704 - To use the module option that sets the dynamic-debugging level for,
2705 - the front-end driver, this parameter must be "Y". For memory-limited
2706 - systems, choose "N". If in doubt, choose "Y".
2707 + This option will enable support for the Realtek mac80211-based
2708 + wireless drivers. Drivers rtl8192ce, rtl8192cu, rtl8192se, rtl8192de,
2709 + rtl8723eu, and rtl8188eu share some common code.
2710 +
2711 +if RTL_CARDS
2712
2713 config RTL8192CE
2714 tristate "Realtek RTL8192CE/RTL8188CE Wireless Network Adapter"
2715 depends on m
2716 - depends on RTLWIFI && PCI
2717 + depends on PCI
2718 select RTL8192C_COMMON
2719 + select RTLWIFI
2720 + select RTLWIFI_PCI
2721 ---help---
2722 This is the driver for Realtek RTL8192CE/RTL8188CE 802.11n PCIe
2723 wireless network adapters.
2724 @@ -33,7 +26,9 @@ config RTL8192CE
2725 config RTL8192SE
2726 tristate "Realtek RTL8192SE/RTL8191SE PCIe Wireless Network Adapter"
2727 depends on m
2728 - depends on RTLWIFI && PCI
2729 + depends on PCI
2730 + select RTLWIFI
2731 + select RTLWIFI_PCI
2732 ---help---
2733 This is the driver for Realtek RTL8192SE/RTL8191SE 802.11n PCIe
2734 wireless network adapters.
2735 @@ -43,7 +38,9 @@ config RTL8192SE
2736 config RTL8192DE
2737 tristate "Realtek RTL8192DE/RTL8188DE PCIe Wireless Network Adapter"
2738 depends on m
2739 - depends on RTLWIFI && PCI
2740 + depends on PCI
2741 + select RTLWIFI
2742 + select RTLWIFI_PCI
2743 ---help---
2744 This is the driver for Realtek RTL8192DE/RTL8188DE 802.11n PCIe
2745 wireless network adapters.
2746 @@ -53,7 +50,9 @@ config RTL8192DE
2747 config RTL8723AE
2748 tristate "Realtek RTL8723AE PCIe Wireless Network Adapter"
2749 depends on m
2750 - depends on RTLWIFI && PCI
2751 + depends on PCI
2752 + select RTLWIFI
2753 + select RTLWIFI_PCI
2754 ---help---
2755 This is the driver for Realtek RTL8723AE 802.11n PCIe
2756 wireless network adapters.
2757 @@ -63,7 +62,9 @@ config RTL8723AE
2758 config RTL8188EE
2759 tristate "Realtek RTL8188EE Wireless Network Adapter"
2760 depends on m
2761 - depends on RTLWIFI && PCI
2762 + depends on PCI
2763 + select RTLWIFI
2764 + select RTLWIFI_PCI
2765 ---help---
2766 This is the driver for Realtek RTL8188EE 802.11n PCIe
2767 wireless network adapters.
2768 @@ -73,7 +74,9 @@ config RTL8188EE
2769 config RTL8192CU
2770 tristate "Realtek RTL8192CU/RTL8188CU USB Wireless Network Adapter"
2771 depends on m
2772 - depends on RTLWIFI && USB
2773 + depends on USB
2774 + select RTLWIFI
2775 + select RTLWIFI_USB
2776 select RTL8192C_COMMON
2777 ---help---
2778 This is the driver for Realtek RTL8192CU/RTL8188CU 802.11n USB
2779 @@ -81,8 +84,32 @@ config RTL8192CU
2780
2781 If you choose to build it as a module, it will be called rtl8192cu
2782
2783 +config RTLWIFI
2784 + tristate
2785 + depends on m
2786 + select BACKPORT_FW_LOADER
2787 +
2788 +config RTLWIFI_PCI
2789 + tristate
2790 + depends on m
2791 +
2792 +config RTLWIFI_USB
2793 + tristate
2794 + depends on m
2795 +
2796 +config RTLWIFI_DEBUG
2797 + bool "Debugging output for rtlwifi driver family"
2798 + depends on RTLWIFI
2799 + default y
2800 + ---help---
2801 + To use the module option that sets the dynamic-debugging level for,
2802 + the front-end driver, this parameter must be "Y". For memory-limited
2803 + systems, choose "N". If in doubt, choose "Y".
2804 +
2805 config RTL8192C_COMMON
2806 tristate
2807 depends on m
2808 depends on RTL8192CE || RTL8192CU
2809 - default m
2810 + default y
2811 +
2812 +endif
2813 --- a/drivers/net/wireless/rtlwifi/Makefile
2814 +++ b/drivers/net/wireless/rtlwifi/Makefile
2815 @@ -12,13 +12,11 @@ rtlwifi-objs := \
2816
2817 rtl8192c_common-objs += \
2818
2819 -ifneq ($(CONFIG_PCI),)
2820 -rtlwifi-objs += pci.o
2821 -endif
2822 +obj-$(CPTCFG_RTLWIFI_PCI) += rtl_pci.o
2823 +rtl_pci-objs := pci.o
2824
2825 -ifneq ($(CONFIG_USB),)
2826 -rtlwifi-objs += usb.o
2827 -endif
2828 +obj-$(CPTCFG_RTLWIFI_USB) += rtl_usb.o
2829 +rtl_usb-objs := usb.o
2830
2831 obj-$(CPTCFG_RTL8192C_COMMON) += rtl8192c/
2832 obj-$(CPTCFG_RTL8192CE) += rtl8192ce/
2833 --- a/drivers/net/wireless/rtlwifi/ps.h
2834 +++ b/drivers/net/wireless/rtlwifi/ps.h
2835 @@ -49,5 +49,6 @@ void rtl_swlps_rf_awake(struct ieee80211
2836 void rtl_swlps_rf_sleep(struct ieee80211_hw *hw);
2837 void rtl_p2p_ps_cmd(struct ieee80211_hw *hw, u8 p2p_ps_state);
2838 void rtl_p2p_info(struct ieee80211_hw *hw, void *data, unsigned int len);
2839 +void rtl_lps_change_work_callback(struct work_struct *work);
2840
2841 #endif
2842 --- a/drivers/net/wireless/rtlwifi/base.c
2843 +++ b/drivers/net/wireless/rtlwifi/base.c
2844 @@ -173,6 +173,7 @@ u8 rtl_tid_to_ac(u8 tid)
2845 {
2846 return tid_to_ac[tid];
2847 }
2848 +EXPORT_SYMBOL_GPL(rtl_tid_to_ac);
2849
2850 static void _rtl_init_hw_ht_capab(struct ieee80211_hw *hw,
2851 struct ieee80211_sta_ht_cap *ht_cap)
2852 @@ -407,6 +408,7 @@ void rtl_deinit_deferred_work(struct iee
2853 cancel_delayed_work(&rtlpriv->works.ps_rfon_wq);
2854 cancel_delayed_work(&rtlpriv->works.fwevt_wq);
2855 }
2856 +EXPORT_SYMBOL_GPL(rtl_deinit_deferred_work);
2857
2858 void rtl_init_rfkill(struct ieee80211_hw *hw)
2859 {
2860 @@ -440,6 +442,7 @@ void rtl_deinit_rfkill(struct ieee80211_
2861 {
2862 wiphy_rfkill_stop_polling(hw->wiphy);
2863 }
2864 +EXPORT_SYMBOL_GPL(rtl_deinit_rfkill);
2865
2866 int rtl_init_core(struct ieee80211_hw *hw)
2867 {
2868 @@ -490,10 +493,12 @@ int rtl_init_core(struct ieee80211_hw *h
2869
2870 return 0;
2871 }
2872 +EXPORT_SYMBOL_GPL(rtl_init_core);
2873
2874 void rtl_deinit_core(struct ieee80211_hw *hw)
2875 {
2876 }
2877 +EXPORT_SYMBOL_GPL(rtl_deinit_core);
2878
2879 void rtl_init_rx_config(struct ieee80211_hw *hw)
2880 {
2881 @@ -502,6 +507,7 @@ void rtl_init_rx_config(struct ieee80211
2882
2883 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *) (&mac->rx_conf));
2884 }
2885 +EXPORT_SYMBOL_GPL(rtl_init_rx_config);
2886
2887 /*********************************************************
2888 *
2889 @@ -880,6 +886,7 @@ bool rtl_tx_mgmt_proc(struct ieee80211_h
2890
2891 return true;
2892 }
2893 +EXPORT_SYMBOL_GPL(rtl_tx_mgmt_proc);
2894
2895 void rtl_get_tcb_desc(struct ieee80211_hw *hw,
2896 struct ieee80211_tx_info *info,
2897 @@ -1053,6 +1060,7 @@ bool rtl_action_proc(struct ieee80211_hw
2898
2899 return true;
2900 }
2901 +EXPORT_SYMBOL_GPL(rtl_action_proc);
2902
2903 /*should call before software enc*/
2904 u8 rtl_is_special_data(struct ieee80211_hw *hw, struct sk_buff *skb, u8 is_tx)
2905 @@ -1126,6 +1134,7 @@ u8 rtl_is_special_data(struct ieee80211_
2906
2907 return false;
2908 }
2909 +EXPORT_SYMBOL_GPL(rtl_is_special_data);
2910
2911 /*********************************************************
2912 *
2913 @@ -1301,6 +1310,7 @@ void rtl_beacon_statistic(struct ieee802
2914
2915 rtlpriv->link_info.bcn_rx_inperiod++;
2916 }
2917 +EXPORT_SYMBOL_GPL(rtl_beacon_statistic);
2918
2919 void rtl_watchdog_wq_callback(void *data)
2920 {
2921 @@ -1794,6 +1804,7 @@ void rtl_recognize_peer(struct ieee80211
2922
2923 mac->vendor = vendor;
2924 }
2925 +EXPORT_SYMBOL_GPL(rtl_recognize_peer);
2926
2927 /*********************************************************
2928 *
2929 @@ -1850,6 +1861,7 @@ struct attribute_group rtl_attribute_gro
2930 .name = "rtlsysfs",
2931 .attrs = rtl_sysfs_entries,
2932 };
2933 +EXPORT_SYMBOL_GPL(rtl_attribute_group);
2934
2935 MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
2936 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
2937 @@ -1857,7 +1869,8 @@ MODULE_AUTHOR("Larry Finger <Larry.FInge
2938 MODULE_LICENSE("GPL");
2939 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
2940
2941 -struct rtl_global_var global_var = {};
2942 +struct rtl_global_var rtl_global_var = {};
2943 +EXPORT_SYMBOL_GPL(rtl_global_var);
2944
2945 static int __init rtl_core_module_init(void)
2946 {
2947 @@ -1865,8 +1878,8 @@ static int __init rtl_core_module_init(v
2948 pr_err("Unable to register rtl_rc, use default RC !!\n");
2949
2950 /* init some global vars */
2951 - INIT_LIST_HEAD(&global_var.glb_priv_list);
2952 - spin_lock_init(&global_var.glb_list_lock);
2953 + INIT_LIST_HEAD(&rtl_global_var.glb_priv_list);
2954 + spin_lock_init(&rtl_global_var.glb_list_lock);
2955
2956 return 0;
2957 }
2958 --- a/drivers/net/wireless/rtlwifi/base.h
2959 +++ b/drivers/net/wireless/rtlwifi/base.h
2960 @@ -147,7 +147,7 @@ void rtl_recognize_peer(struct ieee80211
2961 u8 rtl_tid_to_ac(u8 tid);
2962 extern struct attribute_group rtl_attribute_group;
2963 void rtl_easy_concurrent_retrytimer_callback(unsigned long data);
2964 -extern struct rtl_global_var global_var;
2965 +extern struct rtl_global_var rtl_global_var;
2966 int rtlwifi_rate_mapping(struct ieee80211_hw *hw,
2967 bool isht, u8 desc_rate, bool first_ampdu);
2968 bool rtl_tx_mgmt_proc(struct ieee80211_hw *hw, struct sk_buff *skb);
2969 --- a/drivers/net/wireless/rtlwifi/core.c
2970 +++ b/drivers/net/wireless/rtlwifi/core.c
2971 @@ -1330,3 +1330,4 @@ const struct ieee80211_ops rtl_ops = {
2972 .rfkill_poll = rtl_op_rfkill_poll,
2973 .flush = rtl_op_flush,
2974 };
2975 +EXPORT_SYMBOL_GPL(rtl_ops);
2976 --- a/drivers/net/wireless/rtlwifi/debug.c
2977 +++ b/drivers/net/wireless/rtlwifi/debug.c
2978 @@ -51,3 +51,4 @@ void rtl_dbgp_flag_init(struct ieee80211
2979
2980 /*Init Debug flag enable condition */
2981 }
2982 +EXPORT_SYMBOL_GPL(rtl_dbgp_flag_init);
2983 --- a/drivers/net/wireless/rtlwifi/efuse.c
2984 +++ b/drivers/net/wireless/rtlwifi/efuse.c
2985 @@ -229,6 +229,7 @@ void read_efuse_byte(struct ieee80211_hw
2986
2987 *pbuf = (u8) (value32 & 0xff);
2988 }
2989 +EXPORT_SYMBOL_GPL(read_efuse_byte);
2990
2991 void read_efuse(struct ieee80211_hw *hw, u16 _offset, u16 _size_byte, u8 *pbuf)
2992 {
2993 --- a/drivers/net/wireless/rtlwifi/pci.c
2994 +++ b/drivers/net/wireless/rtlwifi/pci.c
2995 @@ -35,6 +35,13 @@
2996 #include "efuse.h"
2997 #include <linux/export.h>
2998 #include <linux/kmemleak.h>
2999 +#include <linux/module.h>
3000 +
3001 +MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
3002 +MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
3003 +MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
3004 +MODULE_LICENSE("GPL");
3005 +MODULE_DESCRIPTION("PCI basic driver for rtlwifi");
3006
3007 static const u16 pcibridge_vendors[PCI_BRIDGE_VENDOR_MAX] = {
3008 PCI_VENDOR_ID_INTEL,
3009 @@ -1008,19 +1015,6 @@ static void _rtl_pci_prepare_bcn_tasklet
3010 return;
3011 }
3012
3013 -static void rtl_lps_change_work_callback(struct work_struct *work)
3014 -{
3015 - struct rtl_works *rtlworks =
3016 - container_of(work, struct rtl_works, lps_change_work);
3017 - struct ieee80211_hw *hw = rtlworks->hw;
3018 - struct rtl_priv *rtlpriv = rtl_priv(hw);
3019 -
3020 - if (rtlpriv->enter_ps)
3021 - rtl_lps_enter(hw);
3022 - else
3023 - rtl_lps_leave(hw);
3024 -}
3025 -
3026 static void _rtl_pci_init_trx_var(struct ieee80211_hw *hw)
3027 {
3028 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
3029 @@ -1899,7 +1893,7 @@ int rtl_pci_probe(struct pci_dev *pdev,
3030 rtlpriv->rtlhal.interface = INTF_PCI;
3031 rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_data);
3032 rtlpriv->intf_ops = &rtl_pci_ops;
3033 - rtlpriv->glb_var = &global_var;
3034 + rtlpriv->glb_var = &rtl_global_var;
3035
3036 /*
3037 *init dbgp flags before all
3038 --- a/drivers/net/wireless/rtlwifi/ps.c
3039 +++ b/drivers/net/wireless/rtlwifi/ps.c
3040 @@ -269,6 +269,7 @@ void rtl_ips_nic_on(struct ieee80211_hw
3041
3042 spin_unlock_irqrestore(&rtlpriv->locks.ips_lock, flags);
3043 }
3044 +EXPORT_SYMBOL_GPL(rtl_ips_nic_on);
3045
3046 /*for FW LPS*/
3047
3048 @@ -518,6 +519,7 @@ void rtl_swlps_beacon(struct ieee80211_h
3049 "u_bufferd: %x, m_buffered: %x\n", u_buffed, m_buffed);
3050 }
3051 }
3052 +EXPORT_SYMBOL_GPL(rtl_swlps_beacon);
3053
3054 void rtl_swlps_rf_awake(struct ieee80211_hw *hw)
3055 {
3056 @@ -611,6 +613,19 @@ void rtl_swlps_rf_sleep(struct ieee80211
3057 MSECS(sleep_intv * mac->vif->bss_conf.beacon_int - 40));
3058 }
3059
3060 +void rtl_lps_change_work_callback(struct work_struct *work)
3061 +{
3062 + struct rtl_works *rtlworks =
3063 + container_of(work, struct rtl_works, lps_change_work);
3064 + struct ieee80211_hw *hw = rtlworks->hw;
3065 + struct rtl_priv *rtlpriv = rtl_priv(hw);
3066 +
3067 + if (rtlpriv->enter_ps)
3068 + rtl_lps_enter(hw);
3069 + else
3070 + rtl_lps_leave(hw);
3071 +}
3072 +EXPORT_SYMBOL_GPL(rtl_lps_change_work_callback);
3073
3074 void rtl_swlps_wq_callback(void *data)
3075 {
3076 @@ -922,3 +937,4 @@ void rtl_p2p_info(struct ieee80211_hw *h
3077 else
3078 rtl_p2p_noa_ie(hw, data, len - FCS_LEN);
3079 }
3080 +EXPORT_SYMBOL_GPL(rtl_p2p_info);
3081 --- a/drivers/net/wireless/rtlwifi/usb.c
3082 +++ b/drivers/net/wireless/rtlwifi/usb.c
3083 @@ -32,6 +32,13 @@
3084 #include "ps.h"
3085 #include "rtl8192c/fw_common.h"
3086 #include <linux/export.h>
3087 +#include <linux/module.h>
3088 +
3089 +MODULE_AUTHOR("lizhaoming <chaoming_li@realsil.com.cn>");
3090 +MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
3091 +MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
3092 +MODULE_LICENSE("GPL");
3093 +MODULE_DESCRIPTION("USB basic driver for rtlwifi");
3094
3095 #define REALTEK_USB_VENQT_READ 0xC0
3096 #define REALTEK_USB_VENQT_WRITE 0x40
3097 @@ -1070,6 +1077,8 @@ int rtl_usb_probe(struct usb_interface *
3098 spin_lock_init(&rtlpriv->locks.usb_lock);
3099 INIT_WORK(&rtlpriv->works.fill_h2c_cmd,
3100 rtl_fill_h2c_cmd_work_callback);
3101 + INIT_WORK(&rtlpriv->works.lps_change_work,
3102 + rtl_lps_change_work_callback);
3103
3104 rtlpriv->usb_data_index = 0;
3105 init_completion(&rtlpriv->firmware_loading_complete);
3106 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
3107 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
3108 @@ -72,17 +72,12 @@ struct ath_config {
3109 /*************************/
3110
3111 #define ATH_TXBUF_RESET(_bf) do { \
3112 - (_bf)->bf_stale = false; \
3113 (_bf)->bf_lastbf = NULL; \
3114 (_bf)->bf_next = NULL; \
3115 memset(&((_bf)->bf_state), 0, \
3116 sizeof(struct ath_buf_state)); \
3117 } while (0)
3118
3119 -#define ATH_RXBUF_RESET(_bf) do { \
3120 - (_bf)->bf_stale = false; \
3121 - } while (0)
3122 -
3123 /**
3124 * enum buffer_type - Buffer type flags
3125 *
3126 @@ -137,7 +132,8 @@ int ath_descdma_setup(struct ath_softc *
3127 #define ATH_AGGR_ENCRYPTDELIM 10
3128 /* minimum h/w qdepth to be sustained to maximize aggregation */
3129 #define ATH_AGGR_MIN_QDEPTH 2
3130 -#define ATH_AMPDU_SUBFRAME_DEFAULT 32
3131 +/* minimum h/w qdepth for non-aggregated traffic */
3132 +#define ATH_NON_AGGR_MIN_QDEPTH 8
3133
3134 #define IEEE80211_SEQ_SEQ_SHIFT 4
3135 #define IEEE80211_SEQ_MAX 4096
3136 @@ -174,12 +170,6 @@ int ath_descdma_setup(struct ath_softc *
3137
3138 #define ATH_TX_COMPLETE_POLL_INT 1000
3139
3140 -enum ATH_AGGR_STATUS {
3141 - ATH_AGGR_DONE,
3142 - ATH_AGGR_BAW_CLOSED,
3143 - ATH_AGGR_LIMITED,
3144 -};
3145 -
3146 #define ATH_TXFIFO_DEPTH 8
3147 struct ath_txq {
3148 int mac80211_qnum; /* mac80211 queue number, -1 means not mac80211 Q */
3149 @@ -201,10 +191,10 @@ struct ath_txq {
3150
3151 struct ath_atx_ac {
3152 struct ath_txq *txq;
3153 - int sched;
3154 struct list_head list;
3155 struct list_head tid_q;
3156 bool clear_ps_filter;
3157 + bool sched;
3158 };
3159
3160 struct ath_frame_info {
3161 @@ -212,14 +202,16 @@ struct ath_frame_info {
3162 int framelen;
3163 enum ath9k_key_type keytype;
3164 u8 keyix;
3165 - u8 retries;
3166 u8 rtscts_rate;
3167 + u8 retries : 7;
3168 + u8 baw_tracked : 1;
3169 };
3170
3171 struct ath_buf_state {
3172 u8 bf_type;
3173 u8 bfs_paprd;
3174 u8 ndelim;
3175 + bool stale;
3176 u16 seqno;
3177 unsigned long bfs_paprd_timestamp;
3178 };
3179 @@ -233,7 +225,6 @@ struct ath_buf {
3180 void *bf_desc; /* virtual addr of desc */
3181 dma_addr_t bf_daddr; /* physical addr of desc */
3182 dma_addr_t bf_buf_addr; /* physical addr of data buffer, for DMA */
3183 - bool bf_stale;
3184 struct ieee80211_tx_rate rates[4];
3185 struct ath_buf_state bf_state;
3186 };
3187 @@ -241,16 +232,18 @@ struct ath_buf {
3188 struct ath_atx_tid {
3189 struct list_head list;
3190 struct sk_buff_head buf_q;
3191 + struct sk_buff_head retry_q;
3192 struct ath_node *an;
3193 struct ath_atx_ac *ac;
3194 unsigned long tx_buf[BITS_TO_LONGS(ATH_TID_MAX_BUFS)];
3195 - int bar_index;
3196 u16 seq_start;
3197 u16 seq_next;
3198 u16 baw_size;
3199 - int tidno;
3200 + u8 tidno;
3201 int baw_head; /* first un-acked tx buffer */
3202 int baw_tail; /* next unused tx buffer slot */
3203 +
3204 + s8 bar_index;
3205 bool sched;
3206 bool paused;
3207 bool active;
3208 @@ -262,12 +255,13 @@ struct ath_node {
3209 struct ieee80211_vif *vif; /* interface with which we're associated */
3210 struct ath_atx_tid tid[IEEE80211_NUM_TIDS];
3211 struct ath_atx_ac ac[IEEE80211_NUM_ACS];
3212 - int ps_key;
3213
3214 u16 maxampdu;
3215 u8 mpdudensity;
3216 + s8 ps_key;
3217
3218 bool sleeping;
3219 + bool no_ps_filter;
3220
3221 #if defined(CPTCFG_MAC80211_DEBUGFS) && defined(CPTCFG_ATH9K_DEBUGFS)
3222 struct dentry *node_stat;
3223 @@ -317,6 +311,7 @@ struct ath_rx {
3224 struct ath_descdma rxdma;
3225 struct ath_rx_edma rx_edma[ATH9K_RX_QUEUE_MAX];
3226
3227 + struct ath_buf *buf_hold;
3228 struct sk_buff *frag;
3229
3230 u32 ampdu_ref;
3231 @@ -367,6 +362,7 @@ void ath9k_release_buffered_frames(struc
3232 /********/
3233
3234 struct ath_vif {
3235 + struct ath_node mcast_node;
3236 int av_bslot;
3237 bool primary_sta_vif;
3238 __le64 tsf_adjust; /* TSF adjustment for staggered beacons */
3239 @@ -585,19 +581,14 @@ static inline void ath_fill_led_pin(stru
3240 #define ATH_ANT_DIV_COMB_MAX_COUNT 100
3241 #define ATH_ANT_DIV_COMB_ALT_ANT_RATIO 30
3242 #define ATH_ANT_DIV_COMB_ALT_ANT_RATIO2 20
3243 +#define ATH_ANT_DIV_COMB_ALT_ANT_RATIO_LOW_RSSI 50
3244 +#define ATH_ANT_DIV_COMB_ALT_ANT_RATIO2_LOW_RSSI 50
3245
3246 #define ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA -1
3247 #define ATH_ANT_DIV_COMB_LNA1_DELTA_HI -4
3248 #define ATH_ANT_DIV_COMB_LNA1_DELTA_MID -2
3249 #define ATH_ANT_DIV_COMB_LNA1_DELTA_LOW 2
3250
3251 -enum ath9k_ant_div_comb_lna_conf {
3252 - ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2,
3253 - ATH_ANT_DIV_COMB_LNA2,
3254 - ATH_ANT_DIV_COMB_LNA1,
3255 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2,
3256 -};
3257 -
3258 struct ath_ant_comb {
3259 u16 count;
3260 u16 total_pkt_count;
3261 @@ -614,27 +605,36 @@ struct ath_ant_comb {
3262 int rssi_first;
3263 int rssi_second;
3264 int rssi_third;
3265 + int ant_ratio;
3266 + int ant_ratio2;
3267 bool alt_good;
3268 int quick_scan_cnt;
3269 - int main_conf;
3270 + enum ath9k_ant_div_comb_lna_conf main_conf;
3271 enum ath9k_ant_div_comb_lna_conf first_quick_scan_conf;
3272 enum ath9k_ant_div_comb_lna_conf second_quick_scan_conf;
3273 bool first_ratio;
3274 bool second_ratio;
3275 unsigned long scan_start_time;
3276 +
3277 + /*
3278 + * Card-specific config values.
3279 + */
3280 + int low_rssi_thresh;
3281 + int fast_div_bias;
3282 };
3283
3284 void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs);
3285 -void ath_ant_comb_update(struct ath_softc *sc);
3286
3287 /********************/
3288 /* Main driver core */
3289 /********************/
3290
3291 -#define ATH9K_PCI_CUS198 0x0001
3292 -#define ATH9K_PCI_CUS230 0x0002
3293 -#define ATH9K_PCI_CUS217 0x0004
3294 -#define ATH9K_PCI_WOW 0x0008
3295 +#define ATH9K_PCI_CUS198 0x0001
3296 +#define ATH9K_PCI_CUS230 0x0002
3297 +#define ATH9K_PCI_CUS217 0x0004
3298 +#define ATH9K_PCI_WOW 0x0008
3299 +#define ATH9K_PCI_BT_ANT_DIV 0x0010
3300 +#define ATH9K_PCI_D3_L1_WAR 0x0020
3301
3302 /*
3303 * Default cache line size, in bytes.
3304 --- a/drivers/net/wireless/ath/ath9k/debug.c
3305 +++ b/drivers/net/wireless/ath/ath9k/debug.c
3306 @@ -270,25 +270,29 @@ static const struct file_operations fops
3307 .llseek = default_llseek,
3308 };
3309
3310 -static ssize_t read_file_ant_diversity(struct file *file, char __user *user_buf,
3311 - size_t count, loff_t *ppos)
3312 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
3313 +
3314 +static ssize_t read_file_bt_ant_diversity(struct file *file,
3315 + char __user *user_buf,
3316 + size_t count, loff_t *ppos)
3317 {
3318 struct ath_softc *sc = file->private_data;
3319 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
3320 char buf[32];
3321 unsigned int len;
3322
3323 - len = sprintf(buf, "%d\n", common->antenna_diversity);
3324 + len = sprintf(buf, "%d\n", common->bt_ant_diversity);
3325 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
3326 }
3327
3328 -static ssize_t write_file_ant_diversity(struct file *file,
3329 - const char __user *user_buf,
3330 - size_t count, loff_t *ppos)
3331 +static ssize_t write_file_bt_ant_diversity(struct file *file,
3332 + const char __user *user_buf,
3333 + size_t count, loff_t *ppos)
3334 {
3335 struct ath_softc *sc = file->private_data;
3336 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
3337 - unsigned long antenna_diversity;
3338 + struct ath9k_hw_capabilities *pCap = &sc->sc_ah->caps;
3339 + unsigned long bt_ant_diversity;
3340 char buf[32];
3341 ssize_t len;
3342
3343 @@ -296,26 +300,147 @@ static ssize_t write_file_ant_diversity(
3344 if (copy_from_user(buf, user_buf, len))
3345 return -EFAULT;
3346
3347 - if (!AR_SREV_9565(sc->sc_ah))
3348 + if (!(pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
3349 goto exit;
3350
3351 buf[len] = '\0';
3352 - if (strict_strtoul(buf, 0, &antenna_diversity))
3353 + if (kstrtoul(buf, 0, &bt_ant_diversity))
3354 return -EINVAL;
3355
3356 - common->antenna_diversity = !!antenna_diversity;
3357 + common->bt_ant_diversity = !!bt_ant_diversity;
3358 ath9k_ps_wakeup(sc);
3359 - ath_ant_comb_update(sc);
3360 - ath_dbg(common, CONFIG, "Antenna diversity: %d\n",
3361 - common->antenna_diversity);
3362 + ath9k_hw_set_bt_ant_diversity(sc->sc_ah, common->bt_ant_diversity);
3363 + ath_dbg(common, CONFIG, "Enable WLAN/BT RX Antenna diversity: %d\n",
3364 + common->bt_ant_diversity);
3365 ath9k_ps_restore(sc);
3366 exit:
3367 return count;
3368 }
3369
3370 -static const struct file_operations fops_ant_diversity = {
3371 - .read = read_file_ant_diversity,
3372 - .write = write_file_ant_diversity,
3373 +static const struct file_operations fops_bt_ant_diversity = {
3374 + .read = read_file_bt_ant_diversity,
3375 + .write = write_file_bt_ant_diversity,
3376 + .open = simple_open,
3377 + .owner = THIS_MODULE,
3378 + .llseek = default_llseek,
3379 +};
3380 +
3381 +#endif
3382 +
3383 +void ath9k_debug_stat_ant(struct ath_softc *sc,
3384 + struct ath_hw_antcomb_conf *div_ant_conf,
3385 + int main_rssi_avg, int alt_rssi_avg)
3386 +{
3387 + struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
3388 + struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
3389 +
3390 + as_main->lna_attempt_cnt[div_ant_conf->main_lna_conf]++;
3391 + as_alt->lna_attempt_cnt[div_ant_conf->alt_lna_conf]++;
3392 +
3393 + as_main->rssi_avg = main_rssi_avg;
3394 + as_alt->rssi_avg = alt_rssi_avg;
3395 +}
3396 +
3397 +static ssize_t read_file_antenna_diversity(struct file *file,
3398 + char __user *user_buf,
3399 + size_t count, loff_t *ppos)
3400 +{
3401 + struct ath_softc *sc = file->private_data;
3402 + struct ath_hw *ah = sc->sc_ah;
3403 + struct ath9k_hw_capabilities *pCap = &ah->caps;
3404 + struct ath_antenna_stats *as_main = &sc->debug.stats.ant_stats[ANT_MAIN];
3405 + struct ath_antenna_stats *as_alt = &sc->debug.stats.ant_stats[ANT_ALT];
3406 + struct ath_hw_antcomb_conf div_ant_conf;
3407 + unsigned int len = 0, size = 1024;
3408 + ssize_t retval = 0;
3409 + char *buf;
3410 + char *lna_conf_str[4] = {"LNA1_MINUS_LNA2",
3411 + "LNA2",
3412 + "LNA1",
3413 + "LNA1_PLUS_LNA2"};
3414 +
3415 + buf = kzalloc(size, GFP_KERNEL);
3416 + if (buf == NULL)
3417 + return -ENOMEM;
3418 +
3419 + if (!(pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)) {
3420 + len += snprintf(buf + len, size - len, "%s\n",
3421 + "Antenna Diversity Combining is disabled");
3422 + goto exit;
3423 + }
3424 +
3425 + ath9k_ps_wakeup(sc);
3426 + ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
3427 + len += snprintf(buf + len, size - len, "Current MAIN config : %s\n",
3428 + lna_conf_str[div_ant_conf.main_lna_conf]);
3429 + len += snprintf(buf + len, size - len, "Current ALT config : %s\n",
3430 + lna_conf_str[div_ant_conf.alt_lna_conf]);
3431 + len += snprintf(buf + len, size - len, "Average MAIN RSSI : %d\n",
3432 + as_main->rssi_avg);
3433 + len += snprintf(buf + len, size - len, "Average ALT RSSI : %d\n\n",
3434 + as_alt->rssi_avg);
3435 + ath9k_ps_restore(sc);
3436 +
3437 + len += snprintf(buf + len, size - len, "Packet Receive Cnt:\n");
3438 + len += snprintf(buf + len, size - len, "-------------------\n");
3439 +
3440 + len += snprintf(buf + len, size - len, "%30s%15s\n",
3441 + "MAIN", "ALT");
3442 + len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3443 + "TOTAL COUNT",
3444 + as_main->recv_cnt,
3445 + as_alt->recv_cnt);
3446 + len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3447 + "LNA1",
3448 + as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1],
3449 + as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1]);
3450 + len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3451 + "LNA2",
3452 + as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2],
3453 + as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA2]);
3454 + len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3455 + "LNA1 + LNA2",
3456 + as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
3457 + as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
3458 + len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3459 + "LNA1 - LNA2",
3460 + as_main->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
3461 + as_alt->lna_recv_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
3462 +
3463 + len += snprintf(buf + len, size - len, "\nLNA Config Attempts:\n");
3464 + len += snprintf(buf + len, size - len, "--------------------\n");
3465 +
3466 + len += snprintf(buf + len, size - len, "%30s%15s\n",
3467 + "MAIN", "ALT");
3468 + len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3469 + "LNA1",
3470 + as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1],
3471 + as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1]);
3472 + len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3473 + "LNA2",
3474 + as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2],
3475 + as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA2]);
3476 + len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3477 + "LNA1 + LNA2",
3478 + as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2],
3479 + as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2]);
3480 + len += snprintf(buf + len, size - len, "%-14s:%15d%15d\n",
3481 + "LNA1 - LNA2",
3482 + as_main->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2],
3483 + as_alt->lna_attempt_cnt[ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2]);
3484 +
3485 +exit:
3486 + if (len > size)
3487 + len = size;
3488 +
3489 + retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
3490 + kfree(buf);
3491 +
3492 + return retval;
3493 +}
3494 +
3495 +static const struct file_operations fops_antenna_diversity = {
3496 + .read = read_file_antenna_diversity,
3497 .open = simple_open,
3498 .owner = THIS_MODULE,
3499 .llseek = default_llseek,
3500 @@ -607,6 +732,28 @@ static ssize_t read_file_xmit(struct fil
3501 return retval;
3502 }
3503
3504 +static ssize_t print_queue(struct ath_softc *sc, struct ath_txq *txq,
3505 + char *buf, ssize_t size)
3506 +{
3507 + ssize_t len = 0;
3508 +
3509 + ath_txq_lock(sc, txq);
3510 +
3511 + len += snprintf(buf + len, size - len, "%s: %d ",
3512 + "qnum", txq->axq_qnum);
3513 + len += snprintf(buf + len, size - len, "%s: %2d ",
3514 + "qdepth", txq->axq_depth);
3515 + len += snprintf(buf + len, size - len, "%s: %2d ",
3516 + "ampdu-depth", txq->axq_ampdu_depth);
3517 + len += snprintf(buf + len, size - len, "%s: %3d ",
3518 + "pending", txq->pending_frames);
3519 + len += snprintf(buf + len, size - len, "%s: %d\n",
3520 + "stopped", txq->stopped);
3521 +
3522 + ath_txq_unlock(sc, txq);
3523 + return len;
3524 +}
3525 +
3526 static ssize_t read_file_queues(struct file *file, char __user *user_buf,
3527 size_t count, loff_t *ppos)
3528 {
3529 @@ -624,24 +771,13 @@ static ssize_t read_file_queues(struct f
3530
3531 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
3532 txq = sc->tx.txq_map[i];
3533 - len += snprintf(buf + len, size - len, "(%s): ", qname[i]);
3534 -
3535 - ath_txq_lock(sc, txq);
3536 -
3537 - len += snprintf(buf + len, size - len, "%s: %d ",
3538 - "qnum", txq->axq_qnum);
3539 - len += snprintf(buf + len, size - len, "%s: %2d ",
3540 - "qdepth", txq->axq_depth);
3541 - len += snprintf(buf + len, size - len, "%s: %2d ",
3542 - "ampdu-depth", txq->axq_ampdu_depth);
3543 - len += snprintf(buf + len, size - len, "%s: %3d ",
3544 - "pending", txq->pending_frames);
3545 - len += snprintf(buf + len, size - len, "%s: %d\n",
3546 - "stopped", txq->stopped);
3547 -
3548 - ath_txq_unlock(sc, txq);
3549 + len += snprintf(buf + len, size - len, "(%s): ", qname[i]);
3550 + len += print_queue(sc, txq, buf + len, size - len);
3551 }
3552
3553 + len += snprintf(buf + len, size - len, "(CAB): ");
3554 + len += print_queue(sc, sc->beacon.cabq, buf + len, size - len);
3555 +
3556 if (len > size)
3557 len = size;
3558
3559 @@ -1818,9 +1954,11 @@ int ath9k_init_debug(struct ath_hw *ah)
3560 sc->debug.debugfs_phy, &sc->sc_ah->gpio_mask);
3561 debugfs_create_u32("gpio_val", S_IRUSR | S_IWUSR,
3562 sc->debug.debugfs_phy, &sc->sc_ah->gpio_val);
3563 - debugfs_create_file("diversity", S_IRUSR | S_IWUSR,
3564 - sc->debug.debugfs_phy, sc, &fops_ant_diversity);
3565 + debugfs_create_file("antenna_diversity", S_IRUSR,
3566 + sc->debug.debugfs_phy, sc, &fops_antenna_diversity);
3567 #ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
3568 + debugfs_create_file("bt_ant_diversity", S_IRUSR | S_IWUSR,
3569 + sc->debug.debugfs_phy, sc, &fops_bt_ant_diversity);
3570 debugfs_create_file("btcoex", S_IRUSR, sc->debug.debugfs_phy, sc,
3571 &fops_btcoex);
3572 #endif
3573 --- a/net/mac80211/ibss.c
3574 +++ b/net/mac80211/ibss.c
3575 @@ -30,13 +30,14 @@
3576
3577 #define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
3578 #define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
3579 +#define IEEE80211_IBSS_RSN_INACTIVITY_LIMIT (10 * HZ)
3580
3581 #define IEEE80211_IBSS_MAX_STA_ENTRIES 128
3582
3583
3584 static void __ieee80211_sta_join_ibss(struct ieee80211_sub_if_data *sdata,
3585 const u8 *bssid, const int beacon_int,
3586 - struct ieee80211_channel *chan,
3587 + struct cfg80211_chan_def *req_chandef,
3588 const u32 basic_rates,
3589 const u16 capability, u64 tsf,
3590 bool creator)
3591 @@ -51,6 +52,7 @@ static void __ieee80211_sta_join_ibss(st
3592 u32 bss_change;
3593 u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
3594 struct cfg80211_chan_def chandef;
3595 + struct ieee80211_channel *chan;
3596 struct beacon_data *presp;
3597 int frame_len;
3598
3599 @@ -81,7 +83,9 @@ static void __ieee80211_sta_join_ibss(st
3600
3601 sdata->drop_unencrypted = capability & WLAN_CAPABILITY_PRIVACY ? 1 : 0;
3602
3603 - chandef = ifibss->chandef;
3604 + /* make a copy of the chandef, it could be modified below. */
3605 + chandef = *req_chandef;
3606 + chan = chandef.chan;
3607 if (!cfg80211_reg_can_beacon(local->hw.wiphy, &chandef)) {
3608 chandef.width = NL80211_CHAN_WIDTH_20;
3609 chandef.center_freq1 = chan->center_freq;
3610 @@ -259,10 +263,12 @@ static void ieee80211_sta_join_ibss(stru
3611 struct cfg80211_bss *cbss =
3612 container_of((void *)bss, struct cfg80211_bss, priv);
3613 struct ieee80211_supported_band *sband;
3614 + struct cfg80211_chan_def chandef;
3615 u32 basic_rates;
3616 int i, j;
3617 u16 beacon_int = cbss->beacon_interval;
3618 const struct cfg80211_bss_ies *ies;
3619 + enum nl80211_channel_type chan_type;
3620 u64 tsf;
3621
3622 sdata_assert_lock(sdata);
3623 @@ -270,6 +276,26 @@ static void ieee80211_sta_join_ibss(stru
3624 if (beacon_int < 10)
3625 beacon_int = 10;
3626
3627 + switch (sdata->u.ibss.chandef.width) {
3628 + case NL80211_CHAN_WIDTH_20_NOHT:
3629 + case NL80211_CHAN_WIDTH_20:
3630 + case NL80211_CHAN_WIDTH_40:
3631 + chan_type = cfg80211_get_chandef_type(&sdata->u.ibss.chandef);
3632 + cfg80211_chandef_create(&chandef, cbss->channel, chan_type);
3633 + break;
3634 + case NL80211_CHAN_WIDTH_5:
3635 + case NL80211_CHAN_WIDTH_10:
3636 + cfg80211_chandef_create(&chandef, cbss->channel,
3637 + NL80211_CHAN_WIDTH_20_NOHT);
3638 + chandef.width = sdata->u.ibss.chandef.width;
3639 + break;
3640 + default:
3641 + /* fall back to 20 MHz for unsupported modes */
3642 + cfg80211_chandef_create(&chandef, cbss->channel,
3643 + NL80211_CHAN_WIDTH_20_NOHT);
3644 + break;
3645 + }
3646 +
3647 sband = sdata->local->hw.wiphy->bands[cbss->channel->band];
3648
3649 basic_rates = 0;
3650 @@ -294,7 +320,7 @@ static void ieee80211_sta_join_ibss(stru
3651
3652 __ieee80211_sta_join_ibss(sdata, cbss->bssid,
3653 beacon_int,
3654 - cbss->channel,
3655 + &chandef,
3656 basic_rates,
3657 cbss->capability,
3658 tsf, false);
3659 @@ -672,6 +698,33 @@ static int ieee80211_sta_active_ibss(str
3660 return active;
3661 }
3662
3663 +static void ieee80211_ibss_sta_expire(struct ieee80211_sub_if_data *sdata)
3664 +{
3665 + struct ieee80211_local *local = sdata->local;
3666 + struct sta_info *sta, *tmp;
3667 + unsigned long exp_time = IEEE80211_IBSS_INACTIVITY_LIMIT;
3668 + unsigned long exp_rsn_time = IEEE80211_IBSS_RSN_INACTIVITY_LIMIT;
3669 +
3670 + mutex_lock(&local->sta_mtx);
3671 +
3672 + list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
3673 + if (sdata != sta->sdata)
3674 + continue;
3675 +
3676 + if (time_after(jiffies, sta->last_rx + exp_time) ||
3677 + (time_after(jiffies, sta->last_rx + exp_rsn_time) &&
3678 + sta->sta_state != IEEE80211_STA_AUTHORIZED)) {
3679 + sta_dbg(sta->sdata, "expiring inactive %sSTA %pM\n",
3680 + sta->sta_state != IEEE80211_STA_AUTHORIZED ?
3681 + "not authorized " : "", sta->sta.addr);
3682 +
3683 + WARN_ON(__sta_info_destroy(sta));
3684 + }
3685 + }
3686 +
3687 + mutex_unlock(&local->sta_mtx);
3688 +}
3689 +
3690 /*
3691 * This function is called with state == IEEE80211_IBSS_MLME_JOINED
3692 */
3693 @@ -685,7 +738,7 @@ static void ieee80211_sta_merge_ibss(str
3694 mod_timer(&ifibss->timer,
3695 round_jiffies(jiffies + IEEE80211_IBSS_MERGE_INTERVAL));
3696
3697 - ieee80211_sta_expire(sdata, IEEE80211_IBSS_INACTIVITY_LIMIT);
3698 + ieee80211_ibss_sta_expire(sdata);
3699
3700 if (time_before(jiffies, ifibss->last_scan_completed +
3701 IEEE80211_IBSS_MERGE_INTERVAL))
3702 @@ -736,7 +789,7 @@ static void ieee80211_sta_create_ibss(st
3703 sdata->drop_unencrypted = 0;
3704
3705 __ieee80211_sta_join_ibss(sdata, bssid, sdata->vif.bss_conf.beacon_int,
3706 - ifibss->chandef.chan, ifibss->basic_rates,
3707 + &ifibss->chandef, ifibss->basic_rates,
3708 capability, 0, true);
3709 }
3710
3711 @@ -792,6 +845,17 @@ static void ieee80211_sta_find_ibss(stru
3712 return;
3713 }
3714
3715 + /* if a fixed bssid and a fixed freq have been provided create the IBSS
3716 + * directly and do not waste time scanning
3717 + */
3718 + if (ifibss->fixed_bssid && ifibss->fixed_channel) {
3719 + sdata_info(sdata, "Created IBSS using preconfigured BSSID %pM\n",
3720 + bssid);
3721 + ieee80211_sta_create_ibss(sdata);
3722 + return;
3723 + }
3724 +
3725 +
3726 ibss_dbg(sdata, "sta_find_ibss: did not try to join ibss\n");
3727
3728 /* Selected IBSS not found in current scan results - try to scan */
3729 @@ -1138,6 +1202,7 @@ int ieee80211_ibss_leave(struct ieee8021
3730 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
3731 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
3732 BSS_CHANGED_IBSS);
3733 + ieee80211_vif_release_channel(sdata);
3734 synchronize_rcu();
3735 kfree(presp);
3736
3737 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
3738 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
3739 @@ -632,6 +632,22 @@ static void ar9003_hw_override_ini(struc
3740
3741 REG_SET_BIT(ah, AR_PHY_CCK_DETECT,
3742 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
3743 +
3744 + if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
3745 + REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
3746 + AR_GLB_SWREG_DISCONT_EN_BT_WLAN);
3747 +
3748 + if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
3749 + AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
3750 + ah->enabled_cals |= TX_IQ_CAL;
3751 + else
3752 + ah->enabled_cals &= ~TX_IQ_CAL;
3753 +
3754 + if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
3755 + ah->enabled_cals |= TX_CL_CAL;
3756 + else
3757 + ah->enabled_cals &= ~TX_CL_CAL;
3758 + }
3759 }
3760
3761 static void ar9003_hw_prog_ini(struct ath_hw *ah,
3762 @@ -814,29 +830,12 @@ static int ar9003_hw_process_ini(struct
3763 if (chan->channel == 2484)
3764 ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
3765
3766 - if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
3767 - REG_WRITE(ah, AR_GLB_SWREG_DISCONT_MODE,
3768 - AR_GLB_SWREG_DISCONT_EN_BT_WLAN);
3769 -
3770 ah->modes_index = modesIndex;
3771 ar9003_hw_override_ini(ah);
3772 ar9003_hw_set_channel_regs(ah, chan);
3773 ar9003_hw_set_chain_masks(ah, ah->rxchainmask, ah->txchainmask);
3774 ath9k_hw_apply_txpower(ah, chan, false);
3775
3776 - if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
3777 - if (REG_READ_FIELD(ah, AR_PHY_TX_IQCAL_CONTROL_0,
3778 - AR_PHY_TX_IQCAL_CONTROL_0_ENABLE_TXIQ_CAL))
3779 - ah->enabled_cals |= TX_IQ_CAL;
3780 - else
3781 - ah->enabled_cals &= ~TX_IQ_CAL;
3782 -
3783 - if (REG_READ(ah, AR_PHY_CL_CAL_CTL) & AR_PHY_CL_CAL_ENABLE)
3784 - ah->enabled_cals |= TX_CL_CAL;
3785 - else
3786 - ah->enabled_cals &= ~TX_CL_CAL;
3787 - }
3788 -
3789 return 0;
3790 }
3791
3792 @@ -1173,6 +1172,10 @@ skip_ws_det:
3793 * is_on == 0 means MRC CCK is OFF (more noise imm)
3794 */
3795 bool is_on = param ? 1 : 0;
3796 +
3797 + if (ah->caps.rx_chainmask == 1)
3798 + break;
3799 +
3800 REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
3801 AR_PHY_MRC_CCK_ENABLE, is_on);
3802 REG_RMW_FIELD(ah, AR_PHY_MRC_CCK_CTRL,
3803 @@ -1413,65 +1416,111 @@ static void ar9003_hw_antdiv_comb_conf_s
3804 REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
3805 }
3806
3807 -static void ar9003_hw_antctrl_shared_chain_lnadiv(struct ath_hw *ah,
3808 - bool enable)
3809 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
3810 +
3811 +static void ar9003_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable)
3812 {
3813 + struct ath9k_hw_capabilities *pCap = &ah->caps;
3814 u8 ant_div_ctl1;
3815 u32 regval;
3816
3817 - if (!AR_SREV_9565(ah))
3818 + if (!AR_SREV_9485(ah) && !AR_SREV_9565(ah))
3819 return;
3820
3821 - ah->shared_chain_lnadiv = enable;
3822 + if (AR_SREV_9485(ah)) {
3823 + regval = ar9003_hw_ant_ctrl_common_2_get(ah,
3824 + IS_CHAN_2GHZ(ah->curchan));
3825 + if (enable) {
3826 + regval &= ~AR_SWITCH_TABLE_COM2_ALL;
3827 + regval |= ah->config.ant_ctrl_comm2g_switch_enable;
3828 + }
3829 + REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2,
3830 + AR_SWITCH_TABLE_COM2_ALL, regval);
3831 + }
3832 +
3833 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
3834
3835 + /*
3836 + * Set MAIN/ALT LNA conf.
3837 + * Set MAIN/ALT gain_tb.
3838 + */
3839 regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
3840 regval &= (~AR_ANT_DIV_CTRL_ALL);
3841 regval |= (ant_div_ctl1 & 0x3f) << AR_ANT_DIV_CTRL_ALL_S;
3842 - regval &= ~AR_PHY_ANT_DIV_LNADIV;
3843 - regval |= ((ant_div_ctl1 >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S;
3844 -
3845 - if (enable)
3846 - regval |= AR_ANT_DIV_ENABLE;
3847 -
3848 REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
3849
3850 - regval = REG_READ(ah, AR_PHY_CCK_DETECT);
3851 - regval &= ~AR_FAST_DIV_ENABLE;
3852 - regval |= ((ant_div_ctl1 >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
3853 -
3854 - if (enable)
3855 - regval |= AR_FAST_DIV_ENABLE;
3856 -
3857 - REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
3858 -
3859 - if (enable) {
3860 - REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
3861 - (1 << AR_PHY_ANT_SW_RX_PROT_S));
3862 - if (ah->curchan && IS_CHAN_2GHZ(ah->curchan))
3863 - REG_SET_BIT(ah, AR_PHY_RESTART,
3864 - AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
3865 - REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
3866 - AR_BTCOEX_WL_LNADIV_FORCE_ON);
3867 - } else {
3868 - REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL, AR_ANT_DIV_ENABLE);
3869 - REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
3870 - (1 << AR_PHY_ANT_SW_RX_PROT_S));
3871 - REG_CLR_BIT(ah, AR_PHY_CCK_DETECT, AR_FAST_DIV_ENABLE);
3872 - REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,
3873 - AR_BTCOEX_WL_LNADIV_FORCE_ON);
3874 -
3875 + if (AR_SREV_9485_11_OR_LATER(ah)) {
3876 + /*
3877 + * Enable LNA diversity.
3878 + */
3879 regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
3880 - regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
3881 - AR_PHY_ANT_DIV_ALT_LNACONF |
3882 - AR_PHY_ANT_DIV_MAIN_GAINTB |
3883 - AR_PHY_ANT_DIV_ALT_GAINTB);
3884 - regval |= (AR_PHY_ANT_DIV_LNA1 << AR_PHY_ANT_DIV_MAIN_LNACONF_S);
3885 - regval |= (AR_PHY_ANT_DIV_LNA2 << AR_PHY_ANT_DIV_ALT_LNACONF_S);
3886 + regval &= ~AR_PHY_ANT_DIV_LNADIV;
3887 + regval |= ((ant_div_ctl1 >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S;
3888 + if (enable)
3889 + regval |= AR_ANT_DIV_ENABLE;
3890 +
3891 REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
3892 +
3893 + /*
3894 + * Enable fast antenna diversity.
3895 + */
3896 + regval = REG_READ(ah, AR_PHY_CCK_DETECT);
3897 + regval &= ~AR_FAST_DIV_ENABLE;
3898 + regval |= ((ant_div_ctl1 >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
3899 + if (enable)
3900 + regval |= AR_FAST_DIV_ENABLE;
3901 +
3902 + REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
3903 +
3904 + if (pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
3905 + regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
3906 + regval &= (~(AR_PHY_ANT_DIV_MAIN_LNACONF |
3907 + AR_PHY_ANT_DIV_ALT_LNACONF |
3908 + AR_PHY_ANT_DIV_ALT_GAINTB |
3909 + AR_PHY_ANT_DIV_MAIN_GAINTB));
3910 + /*
3911 + * Set MAIN to LNA1 and ALT to LNA2 at the
3912 + * beginning.
3913 + */
3914 + regval |= (ATH_ANT_DIV_COMB_LNA1 <<
3915 + AR_PHY_ANT_DIV_MAIN_LNACONF_S);
3916 + regval |= (ATH_ANT_DIV_COMB_LNA2 <<
3917 + AR_PHY_ANT_DIV_ALT_LNACONF_S);
3918 + REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
3919 + }
3920 + } else if (AR_SREV_9565(ah)) {
3921 + if (enable) {
3922 + REG_SET_BIT(ah, AR_PHY_MC_GAIN_CTRL,
3923 + (1 << AR_PHY_ANT_SW_RX_PROT_S));
3924 + if (ah->curchan && IS_CHAN_2GHZ(ah->curchan))
3925 + REG_SET_BIT(ah, AR_PHY_RESTART,
3926 + AR_PHY_RESTART_ENABLE_DIV_M2FLAG);
3927 + REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV,
3928 + AR_BTCOEX_WL_LNADIV_FORCE_ON);
3929 + } else {
3930 + REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL, AR_ANT_DIV_ENABLE);
3931 + REG_CLR_BIT(ah, AR_PHY_MC_GAIN_CTRL,
3932 + (1 << AR_PHY_ANT_SW_RX_PROT_S));
3933 + REG_CLR_BIT(ah, AR_PHY_CCK_DETECT, AR_FAST_DIV_ENABLE);
3934 + REG_CLR_BIT(ah, AR_BTCOEX_WL_LNADIV,
3935 + AR_BTCOEX_WL_LNADIV_FORCE_ON);
3936 +
3937 + regval = REG_READ(ah, AR_PHY_MC_GAIN_CTRL);
3938 + regval &= ~(AR_PHY_ANT_DIV_MAIN_LNACONF |
3939 + AR_PHY_ANT_DIV_ALT_LNACONF |
3940 + AR_PHY_ANT_DIV_MAIN_GAINTB |
3941 + AR_PHY_ANT_DIV_ALT_GAINTB);
3942 + regval |= (ATH_ANT_DIV_COMB_LNA1 <<
3943 + AR_PHY_ANT_DIV_MAIN_LNACONF_S);
3944 + regval |= (ATH_ANT_DIV_COMB_LNA2 <<
3945 + AR_PHY_ANT_DIV_ALT_LNACONF_S);
3946 + REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
3947 + }
3948 }
3949 }
3950
3951 +#endif
3952 +
3953 static int ar9003_hw_fast_chan_change(struct ath_hw *ah,
3954 struct ath9k_channel *chan,
3955 u8 *ini_reloaded)
3956 @@ -1518,6 +1567,18 @@ static int ar9003_hw_fast_chan_change(st
3957
3958 REG_WRITE_ARRAY(&ah->iniModesTxGain, modesIndex, regWrites);
3959
3960 + if (AR_SREV_9462_20_OR_LATER(ah)) {
3961 + /*
3962 + * CUS217 mix LNA mode.
3963 + */
3964 + if (ar9003_hw_get_rx_gain_idx(ah) == 2) {
3965 + REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_core,
3966 + 1, regWrites);
3967 + REG_WRITE_ARRAY(&ah->ini_modes_rxgain_bb_postamble,
3968 + modesIndex, regWrites);
3969 + }
3970 + }
3971 +
3972 /*
3973 * For 5GHz channels requiring Fast Clock, apply
3974 * different modal values.
3975 @@ -1528,7 +1589,11 @@ static int ar9003_hw_fast_chan_change(st
3976 if (AR_SREV_9565(ah))
3977 REG_WRITE_ARRAY(&ah->iniModesFastClock, 1, regWrites);
3978
3979 - REG_WRITE_ARRAY(&ah->iniAdditional, 1, regWrites);
3980 + /*
3981 + * JAPAN regulatory.
3982 + */
3983 + if (chan->channel == 2484)
3984 + ar9003_hw_prog_ini(ah, &ah->iniCckfirJapan2484, 1);
3985
3986 ah->modes_index = modesIndex;
3987 *ini_reloaded = true;
3988 @@ -1631,11 +1696,14 @@ void ar9003_hw_attach_phy_ops(struct ath
3989
3990 ops->antdiv_comb_conf_get = ar9003_hw_antdiv_comb_conf_get;
3991 ops->antdiv_comb_conf_set = ar9003_hw_antdiv_comb_conf_set;
3992 - ops->antctrl_shared_chain_lnadiv = ar9003_hw_antctrl_shared_chain_lnadiv;
3993 ops->spectral_scan_config = ar9003_hw_spectral_scan_config;
3994 ops->spectral_scan_trigger = ar9003_hw_spectral_scan_trigger;
3995 ops->spectral_scan_wait = ar9003_hw_spectral_scan_wait;
3996
3997 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
3998 + ops->set_bt_ant_diversity = ar9003_hw_set_bt_ant_diversity;
3999 +#endif
4000 +
4001 ar9003_hw_set_nf_limits(ah);
4002 ar9003_hw_set_radar_conf(ah);
4003 memcpy(ah->nf_regs, ar9300_cca_regs, sizeof(ah->nf_regs));
4004 --- a/drivers/net/wireless/ath/ath9k/recv.c
4005 +++ b/drivers/net/wireless/ath/ath9k/recv.c
4006 @@ -42,8 +42,6 @@ static void ath_rx_buf_link(struct ath_s
4007 struct ath_desc *ds;
4008 struct sk_buff *skb;
4009
4010 - ATH_RXBUF_RESET(bf);
4011 -
4012 ds = bf->bf_desc;
4013 ds->ds_link = 0; /* link to null */
4014 ds->ds_data = bf->bf_buf_addr;
4015 @@ -70,6 +68,14 @@ static void ath_rx_buf_link(struct ath_s
4016 sc->rx.rxlink = &ds->ds_link;
4017 }
4018
4019 +static void ath_rx_buf_relink(struct ath_softc *sc, struct ath_buf *bf)
4020 +{
4021 + if (sc->rx.buf_hold)
4022 + ath_rx_buf_link(sc, sc->rx.buf_hold);
4023 +
4024 + sc->rx.buf_hold = bf;
4025 +}
4026 +
4027 static void ath_setdefantenna(struct ath_softc *sc, u32 antenna)
4028 {
4029 /* XXX block beacon interrupts */
4030 @@ -117,7 +123,6 @@ static bool ath_rx_edma_buf_link(struct
4031
4032 skb = bf->bf_mpdu;
4033
4034 - ATH_RXBUF_RESET(bf);
4035 memset(skb->data, 0, ah->caps.rx_status_len);
4036 dma_sync_single_for_device(sc->dev, bf->bf_buf_addr,
4037 ah->caps.rx_status_len, DMA_TO_DEVICE);
4038 @@ -185,7 +190,7 @@ static void ath_rx_edma_cleanup(struct a
4039
4040 static void ath_rx_edma_init_queue(struct ath_rx_edma *rx_edma, int size)
4041 {
4042 - skb_queue_head_init(&rx_edma->rx_fifo);
4043 + __skb_queue_head_init(&rx_edma->rx_fifo);
4044 rx_edma->rx_fifo_hwsize = size;
4045 }
4046
4047 @@ -432,6 +437,7 @@ int ath_startrecv(struct ath_softc *sc)
4048 if (list_empty(&sc->rx.rxbuf))
4049 goto start_recv;
4050
4051 + sc->rx.buf_hold = NULL;
4052 sc->rx.rxlink = NULL;
4053 list_for_each_entry_safe(bf, tbf, &sc->rx.rxbuf, list) {
4054 ath_rx_buf_link(sc, bf);
4055 @@ -677,6 +683,9 @@ static struct ath_buf *ath_get_next_rx_b
4056 }
4057
4058 bf = list_first_entry(&sc->rx.rxbuf, struct ath_buf, list);
4059 + if (bf == sc->rx.buf_hold)
4060 + return NULL;
4061 +
4062 ds = bf->bf_desc;
4063
4064 /*
4065 @@ -755,7 +764,6 @@ static bool ath9k_rx_accept(struct ath_c
4066 bool is_mc, is_valid_tkip, strip_mic, mic_error;
4067 struct ath_hw *ah = common->ah;
4068 __le16 fc;
4069 - u8 rx_status_len = ah->caps.rx_status_len;
4070
4071 fc = hdr->frame_control;
4072
4073 @@ -777,25 +785,6 @@ static bool ath9k_rx_accept(struct ath_c
4074 !test_bit(rx_stats->rs_keyix, common->ccmp_keymap))
4075 rx_stats->rs_status &= ~ATH9K_RXERR_KEYMISS;
4076
4077 - if (!rx_stats->rs_datalen) {
4078 - RX_STAT_INC(rx_len_err);
4079 - return false;
4080 - }
4081 -
4082 - /*
4083 - * rs_status follows rs_datalen so if rs_datalen is too large
4084 - * we can take a hint that hardware corrupted it, so ignore
4085 - * those frames.
4086 - */
4087 - if (rx_stats->rs_datalen > (common->rx_bufsize - rx_status_len)) {
4088 - RX_STAT_INC(rx_len_err);
4089 - return false;
4090 - }
4091 -
4092 - /* Only use error bits from the last fragment */
4093 - if (rx_stats->rs_more)
4094 - return true;
4095 -
4096 mic_error = is_valid_tkip && !ieee80211_is_ctl(fc) &&
4097 !ieee80211_has_morefrags(fc) &&
4098 !(le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG) &&
4099 @@ -814,8 +803,6 @@ static bool ath9k_rx_accept(struct ath_c
4100 rxs->flag |= RX_FLAG_FAILED_FCS_CRC;
4101 mic_error = false;
4102 }
4103 - if (rx_stats->rs_status & ATH9K_RXERR_PHY)
4104 - return false;
4105
4106 if ((rx_stats->rs_status & ATH9K_RXERR_DECRYPT) ||
4107 (!is_mc && (rx_stats->rs_status & ATH9K_RXERR_KEYMISS))) {
4108 @@ -898,129 +885,65 @@ static int ath9k_process_rate(struct ath
4109
4110 static void ath9k_process_rssi(struct ath_common *common,
4111 struct ieee80211_hw *hw,
4112 - struct ieee80211_hdr *hdr,
4113 - struct ath_rx_status *rx_stats)
4114 + struct ath_rx_status *rx_stats,
4115 + struct ieee80211_rx_status *rxs)
4116 {
4117 struct ath_softc *sc = hw->priv;
4118 struct ath_hw *ah = common->ah;
4119 int last_rssi;
4120 int rssi = rx_stats->rs_rssi;
4121
4122 - if (!rx_stats->is_mybeacon ||
4123 - ((ah->opmode != NL80211_IFTYPE_STATION) &&
4124 - (ah->opmode != NL80211_IFTYPE_ADHOC)))
4125 + /*
4126 + * RSSI is not available for subframes in an A-MPDU.
4127 + */
4128 + if (rx_stats->rs_moreaggr) {
4129 + rxs->flag |= RX_FLAG_NO_SIGNAL_VAL;
4130 return;
4131 -
4132 - if (rx_stats->rs_rssi != ATH9K_RSSI_BAD && !rx_stats->rs_moreaggr)
4133 - ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
4134 -
4135 - last_rssi = sc->last_rssi;
4136 - if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
4137 - rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
4138 - if (rssi < 0)
4139 - rssi = 0;
4140 -
4141 - /* Update Beacon RSSI, this is used by ANI. */
4142 - ah->stats.avgbrssi = rssi;
4143 -}
4144 -
4145 -/*
4146 - * For Decrypt or Demic errors, we only mark packet status here and always push
4147 - * up the frame up to let mac80211 handle the actual error case, be it no
4148 - * decryption key or real decryption error. This let us keep statistics there.
4149 - */
4150 -static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
4151 - struct ieee80211_hdr *hdr,
4152 - struct ath_rx_status *rx_stats,
4153 - struct ieee80211_rx_status *rx_status,
4154 - bool *decrypt_error)
4155 -{
4156 - struct ieee80211_hw *hw = sc->hw;
4157 - struct ath_hw *ah = sc->sc_ah;
4158 - struct ath_common *common = ath9k_hw_common(ah);
4159 - bool discard_current = sc->rx.discard_next;
4160 -
4161 - sc->rx.discard_next = rx_stats->rs_more;
4162 - if (discard_current)
4163 - return -EINVAL;
4164 + }
4165
4166 /*
4167 - * everything but the rate is checked here, the rate check is done
4168 - * separately to avoid doing two lookups for a rate for each frame.
4169 + * Check if the RSSI for the last subframe in an A-MPDU
4170 + * or an unaggregated frame is valid.
4171 */
4172 - if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error))
4173 - return -EINVAL;
4174 -
4175 - /* Only use status info from the last fragment */
4176 - if (rx_stats->rs_more)
4177 - return 0;
4178 + if (rx_stats->rs_rssi == ATH9K_RSSI_BAD) {
4179 + rxs->flag |= RX_FLAG_NO_SIGNAL_VAL;
4180 + return;
4181 + }
4182
4183 - if (ath9k_process_rate(common, hw, rx_stats, rx_status))
4184 - return -EINVAL;
4185 + /*
4186 + * Update Beacon RSSI, this is used by ANI.
4187 + */
4188 + if (rx_stats->is_mybeacon &&
4189 + ((ah->opmode == NL80211_IFTYPE_STATION) ||
4190 + (ah->opmode == NL80211_IFTYPE_ADHOC))) {
4191 + ATH_RSSI_LPF(sc->last_rssi, rx_stats->rs_rssi);
4192 + last_rssi = sc->last_rssi;
4193
4194 - ath9k_process_rssi(common, hw, hdr, rx_stats);
4195 + if (likely(last_rssi != ATH_RSSI_DUMMY_MARKER))
4196 + rssi = ATH_EP_RND(last_rssi, ATH_RSSI_EP_MULTIPLIER);
4197 + if (rssi < 0)
4198 + rssi = 0;
4199
4200 - rx_status->band = hw->conf.chandef.chan->band;
4201 - rx_status->freq = hw->conf.chandef.chan->center_freq;
4202 - rx_status->signal = ah->noise + rx_stats->rs_rssi;
4203 - rx_status->antenna = rx_stats->rs_antenna;
4204 - rx_status->flag |= RX_FLAG_MACTIME_END;
4205 - if (rx_stats->rs_moreaggr)
4206 - rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
4207 + ah->stats.avgbrssi = rssi;
4208 + }
4209
4210 - sc->rx.discard_next = false;
4211 - return 0;
4212 + rxs->signal = ah->noise + rx_stats->rs_rssi;
4213 }
4214
4215 -static void ath9k_rx_skb_postprocess(struct ath_common *common,
4216 - struct sk_buff *skb,
4217 - struct ath_rx_status *rx_stats,
4218 - struct ieee80211_rx_status *rxs,
4219 - bool decrypt_error)
4220 +static void ath9k_process_tsf(struct ath_rx_status *rs,
4221 + struct ieee80211_rx_status *rxs,
4222 + u64 tsf)
4223 {
4224 - struct ath_hw *ah = common->ah;
4225 - struct ieee80211_hdr *hdr;
4226 - int hdrlen, padpos, padsize;
4227 - u8 keyix;
4228 - __le16 fc;
4229 + u32 tsf_lower = tsf & 0xffffffff;
4230
4231 - /* see if any padding is done by the hw and remove it */
4232 - hdr = (struct ieee80211_hdr *) skb->data;
4233 - hdrlen = ieee80211_get_hdrlen_from_skb(skb);
4234 - fc = hdr->frame_control;
4235 - padpos = ieee80211_hdrlen(fc);
4236 + rxs->mactime = (tsf & ~0xffffffffULL) | rs->rs_tstamp;
4237 + if (rs->rs_tstamp > tsf_lower &&
4238 + unlikely(rs->rs_tstamp - tsf_lower > 0x10000000))
4239 + rxs->mactime -= 0x100000000ULL;
4240
4241 - /* The MAC header is padded to have 32-bit boundary if the
4242 - * packet payload is non-zero. The general calculation for
4243 - * padsize would take into account odd header lengths:
4244 - * padsize = (4 - padpos % 4) % 4; However, since only
4245 - * even-length headers are used, padding can only be 0 or 2
4246 - * bytes and we can optimize this a bit. In addition, we must
4247 - * not try to remove padding from short control frames that do
4248 - * not have payload. */
4249 - padsize = padpos & 3;
4250 - if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
4251 - memmove(skb->data + padsize, skb->data, padpos);
4252 - skb_pull(skb, padsize);
4253 - }
4254 -
4255 - keyix = rx_stats->rs_keyix;
4256 -
4257 - if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
4258 - ieee80211_has_protected(fc)) {
4259 - rxs->flag |= RX_FLAG_DECRYPTED;
4260 - } else if (ieee80211_has_protected(fc)
4261 - && !decrypt_error && skb->len >= hdrlen + 4) {
4262 - keyix = skb->data[hdrlen + 3] >> 6;
4263 -
4264 - if (test_bit(keyix, common->keymap))
4265 - rxs->flag |= RX_FLAG_DECRYPTED;
4266 - }
4267 - if (ah->sw_mgmt_crypto &&
4268 - (rxs->flag & RX_FLAG_DECRYPTED) &&
4269 - ieee80211_is_mgmt(fc))
4270 - /* Use software decrypt for management frames. */
4271 - rxs->flag &= ~RX_FLAG_DECRYPTED;
4272 + if (rs->rs_tstamp < tsf_lower &&
4273 + unlikely(tsf_lower - rs->rs_tstamp > 0x10000000))
4274 + rxs->mactime += 0x100000000ULL;
4275 }
4276
4277 #ifdef CPTCFG_ATH9K_DEBUGFS
4278 @@ -1133,6 +1056,234 @@ static int ath_process_fft(struct ath_so
4279 #endif
4280 }
4281
4282 +static bool ath9k_is_mybeacon(struct ath_softc *sc, struct ieee80211_hdr *hdr)
4283 +{
4284 + struct ath_hw *ah = sc->sc_ah;
4285 + struct ath_common *common = ath9k_hw_common(ah);
4286 +
4287 + if (ieee80211_is_beacon(hdr->frame_control)) {
4288 + RX_STAT_INC(rx_beacons);
4289 + if (!is_zero_ether_addr(common->curbssid) &&
4290 + ether_addr_equal(hdr->addr3, common->curbssid))
4291 + return true;
4292 + }
4293 +
4294 + return false;
4295 +}
4296 +
4297 +/*
4298 + * For Decrypt or Demic errors, we only mark packet status here and always push
4299 + * up the frame up to let mac80211 handle the actual error case, be it no
4300 + * decryption key or real decryption error. This let us keep statistics there.
4301 + */
4302 +static int ath9k_rx_skb_preprocess(struct ath_softc *sc,
4303 + struct sk_buff *skb,
4304 + struct ath_rx_status *rx_stats,
4305 + struct ieee80211_rx_status *rx_status,
4306 + bool *decrypt_error, u64 tsf)
4307 +{
4308 + struct ieee80211_hw *hw = sc->hw;
4309 + struct ath_hw *ah = sc->sc_ah;
4310 + struct ath_common *common = ath9k_hw_common(ah);
4311 + struct ieee80211_hdr *hdr;
4312 + bool discard_current = sc->rx.discard_next;
4313 + int ret = 0;
4314 +
4315 + /*
4316 + * Discard corrupt descriptors which are marked in
4317 + * ath_get_next_rx_buf().
4318 + */
4319 + sc->rx.discard_next = rx_stats->rs_more;
4320 + if (discard_current)
4321 + return -EINVAL;
4322 +
4323 + /*
4324 + * Discard zero-length packets.
4325 + */
4326 + if (!rx_stats->rs_datalen) {
4327 + RX_STAT_INC(rx_len_err);
4328 + return -EINVAL;
4329 + }
4330 +
4331 + /*
4332 + * rs_status follows rs_datalen so if rs_datalen is too large
4333 + * we can take a hint that hardware corrupted it, so ignore
4334 + * those frames.
4335 + */
4336 + if (rx_stats->rs_datalen > (common->rx_bufsize - ah->caps.rx_status_len)) {
4337 + RX_STAT_INC(rx_len_err);
4338 + return -EINVAL;
4339 + }
4340 +
4341 + /* Only use status info from the last fragment */
4342 + if (rx_stats->rs_more)
4343 + return 0;
4344 +
4345 + /*
4346 + * Return immediately if the RX descriptor has been marked
4347 + * as corrupt based on the various error bits.
4348 + *
4349 + * This is different from the other corrupt descriptor
4350 + * condition handled above.
4351 + */
4352 + if (rx_stats->rs_status & ATH9K_RXERR_CORRUPT_DESC) {
4353 + ret = -EINVAL;
4354 + goto exit;
4355 + }
4356 +
4357 + hdr = (struct ieee80211_hdr *) (skb->data + ah->caps.rx_status_len);
4358 +
4359 + ath9k_process_tsf(rx_stats, rx_status, tsf);
4360 + ath_debug_stat_rx(sc, rx_stats);
4361 +
4362 + /*
4363 + * Process PHY errors and return so that the packet
4364 + * can be dropped.
4365 + */
4366 + if (rx_stats->rs_status & ATH9K_RXERR_PHY) {
4367 + ath9k_dfs_process_phyerr(sc, hdr, rx_stats, rx_status->mactime);
4368 + if (ath_process_fft(sc, hdr, rx_stats, rx_status->mactime))
4369 + RX_STAT_INC(rx_spectral);
4370 +
4371 + ret = -EINVAL;
4372 + goto exit;
4373 + }
4374 +
4375 + /*
4376 + * everything but the rate is checked here, the rate check is done
4377 + * separately to avoid doing two lookups for a rate for each frame.
4378 + */
4379 + if (!ath9k_rx_accept(common, hdr, rx_status, rx_stats, decrypt_error)) {
4380 + ret = -EINVAL;
4381 + goto exit;
4382 + }
4383 +
4384 + rx_stats->is_mybeacon = ath9k_is_mybeacon(sc, hdr);
4385 + if (rx_stats->is_mybeacon) {
4386 + sc->hw_busy_count = 0;
4387 + ath_start_rx_poll(sc, 3);
4388 + }
4389 +
4390 + if (ath9k_process_rate(common, hw, rx_stats, rx_status)) {
4391 + ret =-EINVAL;
4392 + goto exit;
4393 + }
4394 +
4395 + ath9k_process_rssi(common, hw, rx_stats, rx_status);
4396 +
4397 + rx_status->band = hw->conf.chandef.chan->band;
4398 + rx_status->freq = hw->conf.chandef.chan->center_freq;
4399 + rx_status->antenna = rx_stats->rs_antenna;
4400 + rx_status->flag |= RX_FLAG_MACTIME_END;
4401 +
4402 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
4403 + if (ieee80211_is_data_present(hdr->frame_control) &&
4404 + !ieee80211_is_qos_nullfunc(hdr->frame_control))
4405 + sc->rx.num_pkts++;
4406 +#endif
4407 +
4408 +exit:
4409 + sc->rx.discard_next = false;
4410 + return ret;
4411 +}
4412 +
4413 +static void ath9k_rx_skb_postprocess(struct ath_common *common,
4414 + struct sk_buff *skb,
4415 + struct ath_rx_status *rx_stats,
4416 + struct ieee80211_rx_status *rxs,
4417 + bool decrypt_error)
4418 +{
4419 + struct ath_hw *ah = common->ah;
4420 + struct ieee80211_hdr *hdr;
4421 + int hdrlen, padpos, padsize;
4422 + u8 keyix;
4423 + __le16 fc;
4424 +
4425 + /* see if any padding is done by the hw and remove it */
4426 + hdr = (struct ieee80211_hdr *) skb->data;
4427 + hdrlen = ieee80211_get_hdrlen_from_skb(skb);
4428 + fc = hdr->frame_control;
4429 + padpos = ieee80211_hdrlen(fc);
4430 +
4431 + /* The MAC header is padded to have 32-bit boundary if the
4432 + * packet payload is non-zero. The general calculation for
4433 + * padsize would take into account odd header lengths:
4434 + * padsize = (4 - padpos % 4) % 4; However, since only
4435 + * even-length headers are used, padding can only be 0 or 2
4436 + * bytes and we can optimize this a bit. In addition, we must
4437 + * not try to remove padding from short control frames that do
4438 + * not have payload. */
4439 + padsize = padpos & 3;
4440 + if (padsize && skb->len>=padpos+padsize+FCS_LEN) {
4441 + memmove(skb->data + padsize, skb->data, padpos);
4442 + skb_pull(skb, padsize);
4443 + }
4444 +
4445 + keyix = rx_stats->rs_keyix;
4446 +
4447 + if (!(keyix == ATH9K_RXKEYIX_INVALID) && !decrypt_error &&
4448 + ieee80211_has_protected(fc)) {
4449 + rxs->flag |= RX_FLAG_DECRYPTED;
4450 + } else if (ieee80211_has_protected(fc)
4451 + && !decrypt_error && skb->len >= hdrlen + 4) {
4452 + keyix = skb->data[hdrlen + 3] >> 6;
4453 +
4454 + if (test_bit(keyix, common->keymap))
4455 + rxs->flag |= RX_FLAG_DECRYPTED;
4456 + }
4457 + if (ah->sw_mgmt_crypto &&
4458 + (rxs->flag & RX_FLAG_DECRYPTED) &&
4459 + ieee80211_is_mgmt(fc))
4460 + /* Use software decrypt for management frames. */
4461 + rxs->flag &= ~RX_FLAG_DECRYPTED;
4462 +}
4463 +
4464 +/*
4465 + * Run the LNA combining algorithm only in these cases:
4466 + *
4467 + * Standalone WLAN cards with both LNA/Antenna diversity
4468 + * enabled in the EEPROM.
4469 + *
4470 + * WLAN+BT cards which are in the supported card list
4471 + * in ath_pci_id_table and the user has loaded the
4472 + * driver with "bt_ant_diversity" set to true.
4473 + */
4474 +static void ath9k_antenna_check(struct ath_softc *sc,
4475 + struct ath_rx_status *rs)
4476 +{
4477 + struct ath_hw *ah = sc->sc_ah;
4478 + struct ath9k_hw_capabilities *pCap = &ah->caps;
4479 + struct ath_common *common = ath9k_hw_common(ah);
4480 +
4481 + if (!(ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB))
4482 + return;
4483 +
4484 + /*
4485 + * All MPDUs in an aggregate will use the same LNA
4486 + * as the first MPDU.
4487 + */
4488 + if (rs->rs_isaggr && !rs->rs_firstaggr)
4489 + return;
4490 +
4491 + /*
4492 + * Change the default rx antenna if rx diversity
4493 + * chooses the other antenna 3 times in a row.
4494 + */
4495 + if (sc->rx.defant != rs->rs_antenna) {
4496 + if (++sc->rx.rxotherant >= 3)
4497 + ath_setdefantenna(sc, rs->rs_antenna);
4498 + } else {
4499 + sc->rx.rxotherant = 0;
4500 + }
4501 +
4502 + if (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV) {
4503 + if (common->bt_ant_diversity)
4504 + ath_ant_comb_scan(sc, rs);
4505 + } else {
4506 + ath_ant_comb_scan(sc, rs);
4507 + }
4508 +}
4509 +
4510 static void ath9k_apply_ampdu_details(struct ath_softc *sc,
4511 struct ath_rx_status *rs, struct ieee80211_rx_status *rxs)
4512 {
4513 @@ -1159,15 +1310,12 @@ int ath_rx_tasklet(struct ath_softc *sc,
4514 struct ath_hw *ah = sc->sc_ah;
4515 struct ath_common *common = ath9k_hw_common(ah);
4516 struct ieee80211_hw *hw = sc->hw;
4517 - struct ieee80211_hdr *hdr;
4518 int retval;
4519 struct ath_rx_status rs;
4520 enum ath9k_rx_qtype qtype;
4521 bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
4522 int dma_type;
4523 - u8 rx_status_len = ah->caps.rx_status_len;
4524 u64 tsf = 0;
4525 - u32 tsf_lower = 0;
4526 unsigned long flags;
4527 dma_addr_t new_buf_addr;
4528
4529 @@ -1179,7 +1327,6 @@ int ath_rx_tasklet(struct ath_softc *sc,
4530 qtype = hp ? ATH9K_RX_QUEUE_HP : ATH9K_RX_QUEUE_LP;
4531
4532 tsf = ath9k_hw_gettsf64(ah);
4533 - tsf_lower = tsf & 0xffffffff;
4534
4535 do {
4536 bool decrypt_error = false;
4537 @@ -1206,55 +1353,14 @@ int ath_rx_tasklet(struct ath_softc *sc,
4538 else
4539 hdr_skb = skb;
4540
4541 - hdr = (struct ieee80211_hdr *) (hdr_skb->data + rx_status_len);
4542 rxs = IEEE80211_SKB_RXCB(hdr_skb);
4543 - if (ieee80211_is_beacon(hdr->frame_control)) {
4544 - RX_STAT_INC(rx_beacons);
4545 - if (!is_zero_ether_addr(common->curbssid) &&
4546 - ether_addr_equal(hdr->addr3, common->curbssid))
4547 - rs.is_mybeacon = true;
4548 - else
4549 - rs.is_mybeacon = false;
4550 - }
4551 - else
4552 - rs.is_mybeacon = false;
4553 -
4554 - if (ieee80211_is_data_present(hdr->frame_control) &&
4555 - !ieee80211_is_qos_nullfunc(hdr->frame_control))
4556 - sc->rx.num_pkts++;
4557 -
4558 - ath_debug_stat_rx(sc, &rs);
4559 -
4560 memset(rxs, 0, sizeof(struct ieee80211_rx_status));
4561
4562 - rxs->mactime = (tsf & ~0xffffffffULL) | rs.rs_tstamp;
4563 - if (rs.rs_tstamp > tsf_lower &&
4564 - unlikely(rs.rs_tstamp - tsf_lower > 0x10000000))
4565 - rxs->mactime -= 0x100000000ULL;
4566 -
4567 - if (rs.rs_tstamp < tsf_lower &&
4568 - unlikely(tsf_lower - rs.rs_tstamp > 0x10000000))
4569 - rxs->mactime += 0x100000000ULL;
4570 -
4571 - if (rs.rs_phyerr == ATH9K_PHYERR_RADAR)
4572 - ath9k_dfs_process_phyerr(sc, hdr, &rs, rxs->mactime);
4573 -
4574 - if (rs.rs_status & ATH9K_RXERR_PHY) {
4575 - if (ath_process_fft(sc, hdr, &rs, rxs->mactime)) {
4576 - RX_STAT_INC(rx_spectral);
4577 - goto requeue_drop_frag;
4578 - }
4579 - }
4580 -
4581 - retval = ath9k_rx_skb_preprocess(sc, hdr, &rs, rxs,
4582 - &decrypt_error);
4583 + retval = ath9k_rx_skb_preprocess(sc, hdr_skb, &rs, rxs,
4584 + &decrypt_error, tsf);
4585 if (retval)
4586 goto requeue_drop_frag;
4587
4588 - if (rs.is_mybeacon) {
4589 - sc->hw_busy_count = 0;
4590 - ath_start_rx_poll(sc, 3);
4591 - }
4592 /* Ensure we always have an skb to requeue once we are done
4593 * processing the current buffer's skb */
4594 requeue_skb = ath_rxbuf_alloc(common, common->rx_bufsize, GFP_ATOMIC);
4595 @@ -1308,8 +1414,6 @@ int ath_rx_tasklet(struct ath_softc *sc,
4596 sc->rx.frag = skb;
4597 goto requeue;
4598 }
4599 - if (rs.rs_status & ATH9K_RXERR_CORRUPT_DESC)
4600 - goto requeue_drop_frag;
4601
4602 if (sc->rx.frag) {
4603 int space = skb->len - skb_tailroom(hdr_skb);
4604 @@ -1328,22 +1432,6 @@ int ath_rx_tasklet(struct ath_softc *sc,
4605 skb = hdr_skb;
4606 }
4607
4608 -
4609 - if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
4610 -
4611 - /*
4612 - * change the default rx antenna if rx diversity
4613 - * chooses the other antenna 3 times in a row.
4614 - */
4615 - if (sc->rx.defant != rs.rs_antenna) {
4616 - if (++sc->rx.rxotherant >= 3)
4617 - ath_setdefantenna(sc, rs.rs_antenna);
4618 - } else {
4619 - sc->rx.rxotherant = 0;
4620 - }
4621 -
4622 - }
4623 -
4624 if (rxs->flag & RX_FLAG_MMIC_STRIPPED)
4625 skb_trim(skb, skb->len - 8);
4626
4627 @@ -1355,8 +1443,7 @@ int ath_rx_tasklet(struct ath_softc *sc,
4628 ath_rx_ps(sc, skb, rs.is_mybeacon);
4629 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
4630
4631 - if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
4632 - ath_ant_comb_scan(sc, &rs);
4633 + ath9k_antenna_check(sc, &rs);
4634
4635 ath9k_apply_ampdu_details(sc, &rs, rxs);
4636
4637 @@ -1375,7 +1462,7 @@ requeue:
4638 if (edma) {
4639 ath_rx_edma_buf_link(sc, qtype);
4640 } else {
4641 - ath_rx_buf_link(sc, bf);
4642 + ath_rx_buf_relink(sc, bf);
4643 ath9k_hw_rxena(ah);
4644 }
4645 } while (1);
4646 --- a/drivers/net/wireless/ath/ath9k/init.c
4647 +++ b/drivers/net/wireless/ath/ath9k/init.c
4648 @@ -53,9 +53,9 @@ static int ath9k_btcoex_enable;
4649 module_param_named(btcoex_enable, ath9k_btcoex_enable, int, 0444);
4650 MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
4651
4652 -static int ath9k_enable_diversity;
4653 -module_param_named(enable_diversity, ath9k_enable_diversity, int, 0444);
4654 -MODULE_PARM_DESC(enable_diversity, "Enable Antenna diversity for AR9565");
4655 +static int ath9k_bt_ant_diversity;
4656 +module_param_named(bt_ant_diversity, ath9k_bt_ant_diversity, int, 0444);
4657 +MODULE_PARM_DESC(bt_ant_diversity, "Enable WLAN/BT RX antenna diversity");
4658
4659 bool is_ath9k_unloaded;
4660 /* We use the hw_value as an index into our private channel structure */
4661 @@ -516,6 +516,7 @@ static void ath9k_init_misc(struct ath_s
4662 static void ath9k_init_platform(struct ath_softc *sc)
4663 {
4664 struct ath_hw *ah = sc->sc_ah;
4665 + struct ath9k_hw_capabilities *pCap = &ah->caps;
4666 struct ath_common *common = ath9k_hw_common(ah);
4667
4668 if (common->bus_ops->ath_bus_type != ATH_PCI)
4669 @@ -525,12 +526,27 @@ static void ath9k_init_platform(struct a
4670 ATH9K_PCI_CUS230)) {
4671 ah->config.xlna_gpio = 9;
4672 ah->config.xatten_margin_cfg = true;
4673 + ah->config.alt_mingainidx = true;
4674 + ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
4675 + sc->ant_comb.low_rssi_thresh = 20;
4676 + sc->ant_comb.fast_div_bias = 3;
4677
4678 ath_info(common, "Set parameters for %s\n",
4679 (sc->driver_data & ATH9K_PCI_CUS198) ?
4680 "CUS198" : "CUS230");
4681 - } else if (sc->driver_data & ATH9K_PCI_CUS217) {
4682 + }
4683 +
4684 + if (sc->driver_data & ATH9K_PCI_CUS217)
4685 ath_info(common, "CUS217 card detected\n");
4686 +
4687 + if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
4688 + pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
4689 + ath_info(common, "Set BT/WLAN RX diversity capability\n");
4690 + }
4691 +
4692 + if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) {
4693 + ah->config.pcie_waen = 0x0040473b;
4694 + ath_info(common, "Enable WAR for ASPM D3/L1\n");
4695 }
4696 }
4697
4698 @@ -584,6 +600,7 @@ static int ath9k_init_softc(u16 devid, s
4699 {
4700 struct ath9k_platform_data *pdata = sc->dev->platform_data;
4701 struct ath_hw *ah = NULL;
4702 + struct ath9k_hw_capabilities *pCap;
4703 struct ath_common *common;
4704 int ret = 0, i;
4705 int csz = 0;
4706 @@ -600,6 +617,7 @@ static int ath9k_init_softc(u16 devid, s
4707 ah->reg_ops.rmw = ath9k_reg_rmw;
4708 atomic_set(&ah->intr_ref_cnt, -1);
4709 sc->sc_ah = ah;
4710 + pCap = &ah->caps;
4711
4712 sc->dfs_detector = dfs_pattern_detector_init(ah, NL80211_DFS_UNSET);
4713
4714 @@ -631,11 +649,15 @@ static int ath9k_init_softc(u16 devid, s
4715 ath9k_init_platform(sc);
4716
4717 /*
4718 - * Enable Antenna diversity only when BTCOEX is disabled
4719 - * and the user manually requests the feature.
4720 + * Enable WLAN/BT RX Antenna diversity only when:
4721 + *
4722 + * - BTCOEX is disabled.
4723 + * - the user manually requests the feature.
4724 + * - the HW cap is set using the platform data.
4725 */
4726 - if (!common->btcoex_enabled && ath9k_enable_diversity)
4727 - common->antenna_diversity = 1;
4728 + if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
4729 + (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
4730 + common->bt_ant_diversity = 1;
4731
4732 spin_lock_init(&common->cc_lock);
4733
4734 @@ -710,13 +732,15 @@ static void ath9k_init_band_txpower(stru
4735 struct ieee80211_supported_band *sband;
4736 struct ieee80211_channel *chan;
4737 struct ath_hw *ah = sc->sc_ah;
4738 + struct cfg80211_chan_def chandef;
4739 int i;
4740
4741 sband = &sc->sbands[band];
4742 for (i = 0; i < sband->n_channels; i++) {
4743 chan = &sband->channels[i];
4744 ah->curchan = &ah->channels[chan->hw_value];
4745 - ath9k_cmn_update_ichannel(ah->curchan, chan, NL80211_CHAN_HT20);
4746 + cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
4747 + ath9k_cmn_update_ichannel(ah->curchan, &chandef);
4748 ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
4749 }
4750 }
4751 @@ -802,7 +826,8 @@ void ath9k_set_hw_capab(struct ath_softc
4752 IEEE80211_HW_PS_NULLFUNC_STACK |
4753 IEEE80211_HW_SPECTRUM_MGMT |
4754 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4755 - IEEE80211_HW_SUPPORTS_RC_TABLE;
4756 + IEEE80211_HW_SUPPORTS_RC_TABLE |
4757 + IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
4758
4759 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
4760 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
4761 --- a/drivers/net/wireless/ath/carl9170/main.c
4762 +++ b/drivers/net/wireless/ath/carl9170/main.c
4763 @@ -1878,7 +1878,8 @@ void *carl9170_alloc(size_t priv_size)
4764 IEEE80211_HW_PS_NULLFUNC_STACK |
4765 IEEE80211_HW_NEED_DTIM_BEFORE_ASSOC |
4766 IEEE80211_HW_SUPPORTS_RC_TABLE |
4767 - IEEE80211_HW_SIGNAL_DBM;
4768 + IEEE80211_HW_SIGNAL_DBM |
4769 + IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
4770
4771 if (!modparam_noht) {
4772 /*
4773 --- a/drivers/net/wireless/rt2x00/rt2800lib.c
4774 +++ b/drivers/net/wireless/rt2x00/rt2800lib.c
4775 @@ -6133,7 +6133,8 @@ static int rt2800_probe_hw_mode(struct r
4776 IEEE80211_HW_SUPPORTS_PS |
4777 IEEE80211_HW_PS_NULLFUNC_STACK |
4778 IEEE80211_HW_AMPDU_AGGREGATION |
4779 - IEEE80211_HW_REPORTS_TX_ACK_STATUS;
4780 + IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4781 + IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
4782
4783 /*
4784 * Don't set IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING for USB devices
4785 --- a/include/net/mac80211.h
4786 +++ b/include/net/mac80211.h
4787 @@ -152,11 +152,14 @@ struct ieee80211_low_level_stats {
4788 * @IEEE80211_CHANCTX_CHANGE_WIDTH: The channel width changed
4789 * @IEEE80211_CHANCTX_CHANGE_RX_CHAINS: The number of RX chains changed
4790 * @IEEE80211_CHANCTX_CHANGE_RADAR: radar detection flag changed
4791 + * @IEEE80211_CHANCTX_CHANGE_CHANNEL: switched to another operating channel,
4792 + * this is used only with channel switching with CSA
4793 */
4794 enum ieee80211_chanctx_change {
4795 IEEE80211_CHANCTX_CHANGE_WIDTH = BIT(0),
4796 IEEE80211_CHANCTX_CHANGE_RX_CHAINS = BIT(1),
4797 IEEE80211_CHANCTX_CHANGE_RADAR = BIT(2),
4798 + IEEE80211_CHANCTX_CHANGE_CHANNEL = BIT(3),
4799 };
4800
4801 /**
4802 @@ -1080,6 +1083,7 @@ enum ieee80211_vif_flags {
4803 * @addr: address of this interface
4804 * @p2p: indicates whether this AP or STA interface is a p2p
4805 * interface, i.e. a GO or p2p-sta respectively
4806 + * @csa_active: marks whether a channel switch is going on
4807 * @driver_flags: flags/capabilities the driver has for this interface,
4808 * these need to be set (or cleared) when the interface is added
4809 * or, if supported by the driver, the interface type is changed
4810 @@ -1102,6 +1106,7 @@ struct ieee80211_vif {
4811 struct ieee80211_bss_conf bss_conf;
4812 u8 addr[ETH_ALEN];
4813 bool p2p;
4814 + bool csa_active;
4815
4816 u8 cab_queue;
4817 u8 hw_queue[IEEE80211_NUM_ACS];
4818 @@ -1499,6 +1504,7 @@ enum ieee80211_hw_flags {
4819 IEEE80211_HW_SUPPORTS_RC_TABLE = 1<<24,
4820 IEEE80211_HW_P2P_DEV_ADDR_FOR_INTF = 1<<25,
4821 IEEE80211_HW_TIMING_BEACON_ONLY = 1<<26,
4822 + IEEE80211_HW_SUPPORTS_HT_CCK_RATES = 1<<27,
4823 };
4824
4825 /**
4826 @@ -2633,6 +2639,16 @@ enum ieee80211_roc_type {
4827 * @ipv6_addr_change: IPv6 address assignment on the given interface changed.
4828 * Currently, this is only called for managed or P2P client interfaces.
4829 * This callback is optional; it must not sleep.
4830 + *
4831 + * @channel_switch_beacon: Starts a channel switch to a new channel.
4832 + * Beacons are modified to include CSA or ECSA IEs before calling this
4833 + * function. The corresponding count fields in these IEs must be
4834 + * decremented, and when they reach zero the driver must call
4835 + * ieee80211_csa_finish(). Drivers which use ieee80211_beacon_get()
4836 + * get the csa counter decremented by mac80211, but must check if it is
4837 + * zero using ieee80211_csa_is_complete() after the beacon has been
4838 + * transmitted and then call ieee80211_csa_finish().
4839 + *
4840 */
4841 struct ieee80211_ops {
4842 void (*tx)(struct ieee80211_hw *hw,
4843 @@ -2830,6 +2846,9 @@ struct ieee80211_ops {
4844 struct ieee80211_vif *vif,
4845 struct inet6_dev *idev);
4846 #endif
4847 + void (*channel_switch_beacon)(struct ieee80211_hw *hw,
4848 + struct ieee80211_vif *vif,
4849 + struct cfg80211_chan_def *chandef);
4850 };
4851
4852 /**
4853 @@ -3325,6 +3344,25 @@ static inline struct sk_buff *ieee80211_
4854 }
4855
4856 /**
4857 + * ieee80211_csa_finish - notify mac80211 about channel switch
4858 + * @vif: &struct ieee80211_vif pointer from the add_interface callback.
4859 + *
4860 + * After a channel switch announcement was scheduled and the counter in this
4861 + * announcement hit zero, this function must be called by the driver to
4862 + * notify mac80211 that the channel can be changed.
4863 + */
4864 +void ieee80211_csa_finish(struct ieee80211_vif *vif);
4865 +
4866 +/**
4867 + * ieee80211_csa_is_complete - find out if counters reached zero
4868 + * @vif: &struct ieee80211_vif pointer from the add_interface callback.
4869 + *
4870 + * This function returns whether the channel switch counters reached zero.
4871 + */
4872 +bool ieee80211_csa_is_complete(struct ieee80211_vif *vif);
4873 +
4874 +
4875 +/**
4876 * ieee80211_proberesp_get - retrieve a Probe Response template
4877 * @hw: pointer obtained from ieee80211_alloc_hw().
4878 * @vif: &struct ieee80211_vif pointer from the add_interface callback.
4879 --- a/net/mac80211/cfg.c
4880 +++ b/net/mac80211/cfg.c
4881 @@ -854,8 +854,8 @@ static int ieee80211_set_probe_resp(stru
4882 return 0;
4883 }
4884
4885 -static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
4886 - struct cfg80211_beacon_data *params)
4887 +int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
4888 + struct cfg80211_beacon_data *params)
4889 {
4890 struct beacon_data *new, *old;
4891 int new_head_len, new_tail_len;
4892 @@ -1018,6 +1018,12 @@ static int ieee80211_change_beacon(struc
4893
4894 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
4895
4896 + /* don't allow changing the beacon while CSA is in place - offset
4897 + * of channel switch counter may change
4898 + */
4899 + if (sdata->vif.csa_active)
4900 + return -EBUSY;
4901 +
4902 old = rtnl_dereference(sdata->u.ap.beacon);
4903 if (!old)
4904 return -ENOENT;
4905 @@ -1042,6 +1048,10 @@ static int ieee80211_stop_ap(struct wiph
4906 return -ENOENT;
4907 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
4908
4909 + /* abort any running channel switch */
4910 + sdata->vif.csa_active = false;
4911 + cancel_work_sync(&sdata->csa_finalize_work);
4912 +
4913 /* turn off carrier for this interface and dependent VLANs */
4914 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
4915 netif_carrier_off(vlan->dev);
4916 @@ -2784,6 +2794,178 @@ static int ieee80211_start_radar_detecti
4917 return 0;
4918 }
4919
4920 +static struct cfg80211_beacon_data *
4921 +cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
4922 +{
4923 + struct cfg80211_beacon_data *new_beacon;
4924 + u8 *pos;
4925 + int len;
4926 +
4927 + len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
4928 + beacon->proberesp_ies_len + beacon->assocresp_ies_len +
4929 + beacon->probe_resp_len;
4930 +
4931 + new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
4932 + if (!new_beacon)
4933 + return NULL;
4934 +
4935 + pos = (u8 *)(new_beacon + 1);
4936 + if (beacon->head_len) {
4937 + new_beacon->head_len = beacon->head_len;
4938 + new_beacon->head = pos;
4939 + memcpy(pos, beacon->head, beacon->head_len);
4940 + pos += beacon->head_len;
4941 + }
4942 + if (beacon->tail_len) {
4943 + new_beacon->tail_len = beacon->tail_len;
4944 + new_beacon->tail = pos;
4945 + memcpy(pos, beacon->tail, beacon->tail_len);
4946 + pos += beacon->tail_len;
4947 + }
4948 + if (beacon->beacon_ies_len) {
4949 + new_beacon->beacon_ies_len = beacon->beacon_ies_len;
4950 + new_beacon->beacon_ies = pos;
4951 + memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
4952 + pos += beacon->beacon_ies_len;
4953 + }
4954 + if (beacon->proberesp_ies_len) {
4955 + new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
4956 + new_beacon->proberesp_ies = pos;
4957 + memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
4958 + pos += beacon->proberesp_ies_len;
4959 + }
4960 + if (beacon->assocresp_ies_len) {
4961 + new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
4962 + new_beacon->assocresp_ies = pos;
4963 + memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
4964 + pos += beacon->assocresp_ies_len;
4965 + }
4966 + if (beacon->probe_resp_len) {
4967 + new_beacon->probe_resp_len = beacon->probe_resp_len;
4968 + beacon->probe_resp = pos;
4969 + memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
4970 + pos += beacon->probe_resp_len;
4971 + }
4972 +
4973 + return new_beacon;
4974 +}
4975 +
4976 +void ieee80211_csa_finalize_work(struct work_struct *work)
4977 +{
4978 + struct ieee80211_sub_if_data *sdata =
4979 + container_of(work, struct ieee80211_sub_if_data,
4980 + csa_finalize_work);
4981 + struct ieee80211_local *local = sdata->local;
4982 + int err, changed;
4983 +
4984 + if (!ieee80211_sdata_running(sdata))
4985 + return;
4986 +
4987 + if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP))
4988 + return;
4989 +
4990 + sdata->radar_required = sdata->csa_radar_required;
4991 + err = ieee80211_vif_change_channel(sdata, &local->csa_chandef,
4992 + &changed);
4993 + if (WARN_ON(err < 0))
4994 + return;
4995 +
4996 + err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
4997 + if (err < 0)
4998 + return;
4999 +
5000 + changed |= err;
5001 + kfree(sdata->u.ap.next_beacon);
5002 + sdata->u.ap.next_beacon = NULL;
5003 + sdata->vif.csa_active = false;
5004 +
5005 + ieee80211_wake_queues_by_reason(&sdata->local->hw,
5006 + IEEE80211_MAX_QUEUE_MAP,
5007 + IEEE80211_QUEUE_STOP_REASON_CSA);
5008 +
5009 + ieee80211_bss_info_change_notify(sdata, changed);
5010 +
5011 + cfg80211_ch_switch_notify(sdata->dev, &local->csa_chandef);
5012 +}
5013 +
5014 +static int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
5015 + struct cfg80211_csa_settings *params)
5016 +{
5017 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
5018 + struct ieee80211_local *local = sdata->local;
5019 + struct ieee80211_chanctx_conf *chanctx_conf;
5020 + struct ieee80211_chanctx *chanctx;
5021 + int err, num_chanctx;
5022 +
5023 + if (!list_empty(&local->roc_list) || local->scanning)
5024 + return -EBUSY;
5025 +
5026 + if (sdata->wdev.cac_started)
5027 + return -EBUSY;
5028 +
5029 + if (cfg80211_chandef_identical(&params->chandef,
5030 + &sdata->vif.bss_conf.chandef))
5031 + return -EINVAL;
5032 +
5033 + rcu_read_lock();
5034 + chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
5035 + if (!chanctx_conf) {
5036 + rcu_read_unlock();
5037 + return -EBUSY;
5038 + }
5039 +
5040 + /* don't handle for multi-VIF cases */
5041 + chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
5042 + if (chanctx->refcount > 1) {
5043 + rcu_read_unlock();
5044 + return -EBUSY;
5045 + }
5046 + num_chanctx = 0;
5047 + list_for_each_entry_rcu(chanctx, &local->chanctx_list, list)
5048 + num_chanctx++;
5049 + rcu_read_unlock();
5050 +
5051 + if (num_chanctx > 1)
5052 + return -EBUSY;
5053 +
5054 + /* don't allow another channel switch if one is already active. */
5055 + if (sdata->vif.csa_active)
5056 + return -EBUSY;
5057 +
5058 + /* only handle AP for now. */
5059 + switch (sdata->vif.type) {
5060 + case NL80211_IFTYPE_AP:
5061 + break;
5062 + default:
5063 + return -EOPNOTSUPP;
5064 + }
5065 +
5066 + sdata->u.ap.next_beacon = cfg80211_beacon_dup(&params->beacon_after);
5067 + if (!sdata->u.ap.next_beacon)
5068 + return -ENOMEM;
5069 +
5070 + sdata->csa_counter_offset_beacon = params->counter_offset_beacon;
5071 + sdata->csa_counter_offset_presp = params->counter_offset_presp;
5072 + sdata->csa_radar_required = params->radar_required;
5073 +
5074 + if (params->block_tx)
5075 + ieee80211_stop_queues_by_reason(&local->hw,
5076 + IEEE80211_MAX_QUEUE_MAP,
5077 + IEEE80211_QUEUE_STOP_REASON_CSA);
5078 +
5079 + err = ieee80211_assign_beacon(sdata, &params->beacon_csa);
5080 + if (err < 0)
5081 + return err;
5082 +
5083 + local->csa_chandef = params->chandef;
5084 + sdata->vif.csa_active = true;
5085 +
5086 + ieee80211_bss_info_change_notify(sdata, err);
5087 + drv_channel_switch_beacon(sdata, &params->chandef);
5088 +
5089 + return 0;
5090 +}
5091 +
5092 static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
5093 struct ieee80211_channel *chan, bool offchan,
5094 unsigned int wait, const u8 *buf, size_t len,
5095 @@ -3501,4 +3683,5 @@ struct cfg80211_ops mac80211_config_ops
5096 .get_et_strings = ieee80211_get_et_strings,
5097 .get_channel = ieee80211_cfg_get_channel,
5098 .start_radar_detection = ieee80211_start_radar_detection,
5099 + .channel_switch = ieee80211_channel_switch,
5100 };
5101 --- a/net/mac80211/chan.c
5102 +++ b/net/mac80211/chan.c
5103 @@ -410,6 +410,64 @@ int ieee80211_vif_use_channel(struct iee
5104 return ret;
5105 }
5106
5107 +int ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata,
5108 + const struct cfg80211_chan_def *chandef,
5109 + u32 *changed)
5110 +{
5111 + struct ieee80211_local *local = sdata->local;
5112 + struct ieee80211_chanctx_conf *conf;
5113 + struct ieee80211_chanctx *ctx;
5114 + int ret;
5115 + u32 chanctx_changed = 0;
5116 +
5117 + /* should never be called if not performing a channel switch. */
5118 + if (WARN_ON(!sdata->vif.csa_active))
5119 + return -EINVAL;
5120 +
5121 + if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
5122 + IEEE80211_CHAN_DISABLED))
5123 + return -EINVAL;
5124 +
5125 + mutex_lock(&local->chanctx_mtx);
5126 + conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
5127 + lockdep_is_held(&local->chanctx_mtx));
5128 + if (!conf) {
5129 + ret = -EINVAL;
5130 + goto out;
5131 + }
5132 +
5133 + ctx = container_of(conf, struct ieee80211_chanctx, conf);
5134 + if (ctx->refcount != 1) {
5135 + ret = -EINVAL;
5136 + goto out;
5137 + }
5138 +
5139 + if (sdata->vif.bss_conf.chandef.width != chandef->width) {
5140 + chanctx_changed = IEEE80211_CHANCTX_CHANGE_WIDTH;
5141 + *changed |= BSS_CHANGED_BANDWIDTH;
5142 + }
5143 +
5144 + sdata->vif.bss_conf.chandef = *chandef;
5145 + ctx->conf.def = *chandef;
5146 +
5147 + chanctx_changed |= IEEE80211_CHANCTX_CHANGE_CHANNEL;
5148 + drv_change_chanctx(local, ctx, chanctx_changed);
5149 +
5150 + if (!local->use_chanctx) {
5151 + local->_oper_chandef = *chandef;
5152 + ieee80211_hw_config(local, 0);
5153 + }
5154 +
5155 + ieee80211_recalc_chanctx_chantype(local, ctx);
5156 + ieee80211_recalc_smps_chanctx(local, ctx);
5157 + ieee80211_recalc_radar_chanctx(local, ctx);
5158 +
5159 + ret = 0;
5160 + out:
5161 + mutex_unlock(&local->chanctx_mtx);
5162 + return ret;
5163 +}
5164 +
5165 int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata,
5166 const struct cfg80211_chan_def *chandef,
5167 u32 *changed)
5168 --- a/net/mac80211/driver-ops.h
5169 +++ b/net/mac80211/driver-ops.h
5170 @@ -1104,4 +1104,17 @@ static inline void drv_ipv6_addr_change(
5171 }
5172 #endif
5173
5174 +static inline void
5175 +drv_channel_switch_beacon(struct ieee80211_sub_if_data *sdata,
5176 + struct cfg80211_chan_def *chandef)
5177 +{
5178 + struct ieee80211_local *local = sdata->local;
5179 +
5180 + if (local->ops->channel_switch_beacon) {
5181 + trace_drv_channel_switch_beacon(local, sdata, chandef);
5182 + local->ops->channel_switch_beacon(&local->hw, &sdata->vif,
5183 + chandef);
5184 + }
5185 +}
5186 +
5187 #endif /* __MAC80211_DRIVER_OPS */
5188 --- a/net/mac80211/ieee80211_i.h
5189 +++ b/net/mac80211/ieee80211_i.h
5190 @@ -53,9 +53,6 @@ struct ieee80211_local;
5191 * increased memory use (about 2 kB of RAM per entry). */
5192 #define IEEE80211_FRAGMENT_MAX 4
5193
5194 -#define TU_TO_JIFFIES(x) (usecs_to_jiffies((x) * 1024))
5195 -#define TU_TO_EXP_TIME(x) (jiffies + TU_TO_JIFFIES(x))
5196 -
5197 /* power level hasn't been configured (or set to automatic) */
5198 #define IEEE80211_UNSET_POWER_LEVEL INT_MIN
5199
5200 @@ -259,6 +256,8 @@ struct ieee80211_if_ap {
5201 struct beacon_data __rcu *beacon;
5202 struct probe_resp __rcu *probe_resp;
5203
5204 + /* to be used after channel switch. */
5205 + struct cfg80211_beacon_data *next_beacon;
5206 struct list_head vlans;
5207
5208 struct ps_data ps;
5209 @@ -713,6 +712,11 @@ struct ieee80211_sub_if_data {
5210
5211 struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS];
5212
5213 + struct work_struct csa_finalize_work;
5214 + int csa_counter_offset_beacon;
5215 + int csa_counter_offset_presp;
5216 + bool csa_radar_required;
5217 +
5218 /* used to reconfigure hardware SM PS */
5219 struct work_struct recalc_smps;
5220
5221 @@ -1346,6 +1350,9 @@ void ieee80211_roc_notify_destroy(struct
5222 void ieee80211_sw_roc_work(struct work_struct *work);
5223 void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc);
5224
5225 +/* channel switch handling */
5226 +void ieee80211_csa_finalize_work(struct work_struct *work);
5227 +
5228 /* interface handling */
5229 int ieee80211_iface_init(void);
5230 void ieee80211_iface_exit(void);
5231 @@ -1367,6 +1374,8 @@ void ieee80211_del_virtual_monitor(struc
5232
5233 bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata);
5234 void ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata);
5235 +int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
5236 + struct cfg80211_beacon_data *params);
5237
5238 static inline bool ieee80211_sdata_running(struct ieee80211_sub_if_data *sdata)
5239 {
5240 @@ -1627,6 +1636,11 @@ int __must_check
5241 ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata,
5242 const struct cfg80211_chan_def *chandef,
5243 u32 *changed);
5244 +/* NOTE: only use ieee80211_vif_change_channel() for channel switch */
5245 +int __must_check
5246 +ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata,
5247 + const struct cfg80211_chan_def *chandef,
5248 + u32 *changed);
5249 void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata);
5250 void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata);
5251 void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
5252 --- a/net/mac80211/trace.h
5253 +++ b/net/mac80211/trace.h
5254 @@ -1906,6 +1906,32 @@ TRACE_EVENT(api_radar_detected,
5255 )
5256 );
5257
5258 +TRACE_EVENT(drv_channel_switch_beacon,
5259 + TP_PROTO(struct ieee80211_local *local,
5260 + struct ieee80211_sub_if_data *sdata,
5261 + struct cfg80211_chan_def *chandef),
5262 +
5263 + TP_ARGS(local, sdata, chandef),
5264 +
5265 + TP_STRUCT__entry(
5266 + LOCAL_ENTRY
5267 + VIF_ENTRY
5268 + CHANDEF_ENTRY
5269 + ),
5270 +
5271 + TP_fast_assign(
5272 + LOCAL_ASSIGN;
5273 + VIF_ASSIGN;
5274 + CHANDEF_ASSIGN(chandef);
5275 + ),
5276 +
5277 + TP_printk(
5278 + LOCAL_PR_FMT VIF_PR_FMT " channel switch to " CHANDEF_PR_FMT,
5279 + LOCAL_PR_ARG, VIF_PR_ARG, CHANDEF_PR_ARG
5280 + )
5281 +);
5282 +
5283 +
5284 #ifdef CPTCFG_MAC80211_MESSAGE_TRACING
5285 #undef TRACE_SYSTEM
5286 #define TRACE_SYSTEM mac80211_msg
5287 --- a/net/mac80211/tx.c
5288 +++ b/net/mac80211/tx.c
5289 @@ -2326,6 +2326,81 @@ static int ieee80211_beacon_add_tim(stru
5290 return 0;
5291 }
5292
5293 +void ieee80211_csa_finish(struct ieee80211_vif *vif)
5294 +{
5295 + struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5296 +
5297 + ieee80211_queue_work(&sdata->local->hw,
5298 + &sdata->csa_finalize_work);
5299 +}
5300 +EXPORT_SYMBOL(ieee80211_csa_finish);
5301 +
5302 +static void ieee80211_update_csa(struct ieee80211_sub_if_data *sdata,
5303 + struct beacon_data *beacon)
5304 +{
5305 + struct probe_resp *resp;
5306 + int counter_offset_beacon = sdata->csa_counter_offset_beacon;
5307 + int counter_offset_presp = sdata->csa_counter_offset_presp;
5308 +
5309 + /* warn if the driver did not check for/react to csa completeness */
5310 + if (WARN_ON(((u8 *)beacon->tail)[counter_offset_beacon] == 0))
5311 + return;
5312 +
5313 + ((u8 *)beacon->tail)[counter_offset_beacon]--;
5314 +
5315 + if (sdata->vif.type == NL80211_IFTYPE_AP &&
5316 + counter_offset_presp) {
5317 + rcu_read_lock();
5318 + resp = rcu_dereference(sdata->u.ap.probe_resp);
5319 +
5320 + /* if nl80211 accepted the offset, this should not happen. */
5321 + if (WARN_ON(!resp)) {
5322 + rcu_read_unlock();
5323 + return;
5324 + }
5325 + resp->data[counter_offset_presp]--;
5326 + rcu_read_unlock();
5327 + }
5328 +}
5329 +
5330 +bool ieee80211_csa_is_complete(struct ieee80211_vif *vif)
5331 +{
5332 + struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5333 + struct beacon_data *beacon = NULL;
5334 + u8 *beacon_data;
5335 + size_t beacon_data_len;
5336 + int counter_beacon = sdata->csa_counter_offset_beacon;
5337 + int ret = false;
5338 +
5339 + if (!ieee80211_sdata_running(sdata))
5340 + return false;
5341 +
5342 + rcu_read_lock();
5343 + if (vif->type == NL80211_IFTYPE_AP) {
5344 + struct ieee80211_if_ap *ap = &sdata->u.ap;
5345 +
5346 + beacon = rcu_dereference(ap->beacon);
5347 + if (WARN_ON(!beacon || !beacon->tail))
5348 + goto out;
5349 + beacon_data = beacon->tail;
5350 + beacon_data_len = beacon->tail_len;
5351 + } else {
5352 + WARN_ON(1);
5353 + goto out;
5354 + }
5355 +
5356 + if (WARN_ON(counter_beacon > beacon_data_len))
5357 + goto out;
5358 +
5359 + if (beacon_data[counter_beacon] == 0)
5360 + ret = true;
5361 + out:
5362 + rcu_read_unlock();
5363 +
5364 + return ret;
5365 +}
5366 +EXPORT_SYMBOL(ieee80211_csa_is_complete);
5367 +
5368 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
5369 struct ieee80211_vif *vif,
5370 u16 *tim_offset, u16 *tim_length)
5371 @@ -2356,6 +2431,9 @@ struct sk_buff *ieee80211_beacon_get_tim
5372 struct beacon_data *beacon = rcu_dereference(ap->beacon);
5373
5374 if (beacon) {
5375 + if (sdata->vif.csa_active)
5376 + ieee80211_update_csa(sdata, beacon);
5377 +
5378 /*
5379 * headroom, head length,
5380 * tail length and maximum TIM length
5381 --- a/net/wireless/rdev-ops.h
5382 +++ b/net/wireless/rdev-ops.h
5383 @@ -923,4 +923,16 @@ static inline void rdev_crit_proto_stop(
5384 trace_rdev_return_void(&rdev->wiphy);
5385 }
5386
5387 +static inline int rdev_channel_switch(struct cfg80211_registered_device *rdev,
5388 + struct net_device *dev,
5389 + struct cfg80211_csa_settings *params)
5390 +{
5391 + int ret;
5392 +
5393 + trace_rdev_channel_switch(&rdev->wiphy, dev, params);
5394 + ret = rdev->ops->channel_switch(&rdev->wiphy, dev, params);
5395 + trace_rdev_return_int(&rdev->wiphy, ret);
5396 + return ret;
5397 +}
5398 +
5399 #endif /* __CFG80211_RDEV_OPS */
5400 --- a/net/wireless/trace.h
5401 +++ b/net/wireless/trace.h
5402 @@ -1841,6 +1841,39 @@ TRACE_EVENT(rdev_crit_proto_stop,
5403 WIPHY_PR_ARG, WDEV_PR_ARG)
5404 );
5405
5406 +TRACE_EVENT(rdev_channel_switch,
5407 + TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
5408 + struct cfg80211_csa_settings *params),
5409 + TP_ARGS(wiphy, netdev, params),
5410 + TP_STRUCT__entry(
5411 + WIPHY_ENTRY
5412 + NETDEV_ENTRY
5413 + CHAN_DEF_ENTRY
5414 + __field(u16, counter_offset_beacon)
5415 + __field(u16, counter_offset_presp)
5416 + __field(bool, radar_required)
5417 + __field(bool, block_tx)
5418 + __field(u8, count)
5419 + ),
5420 + TP_fast_assign(
5421 + WIPHY_ASSIGN;
5422 + NETDEV_ASSIGN;
5423 + CHAN_DEF_ASSIGN(&params->chandef);
5424 + __entry->counter_offset_beacon = params->counter_offset_beacon;
5425 + __entry->counter_offset_presp = params->counter_offset_presp;
5426 + __entry->radar_required = params->radar_required;
5427 + __entry->block_tx = params->block_tx;
5428 + __entry->count = params->count;
5429 + ),
5430 + TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", " CHAN_DEF_PR_FMT
5431 + ", block_tx: %d, count: %u, radar_required: %d"
5432 + ", counter offsets (beacon/presp): %u/%u",
5433 + WIPHY_PR_ARG, NETDEV_PR_ARG, CHAN_DEF_PR_ARG,
5434 + __entry->block_tx, __entry->count, __entry->radar_required,
5435 + __entry->counter_offset_beacon,
5436 + __entry->counter_offset_presp)
5437 +);
5438 +
5439 /*************************************************************
5440 * cfg80211 exported functions traces *
5441 *************************************************************/
5442 --- a/drivers/net/wireless/ath/ath.h
5443 +++ b/drivers/net/wireless/ath/ath.h
5444 @@ -159,7 +159,7 @@ struct ath_common {
5445
5446 bool btcoex_enabled;
5447 bool disable_ani;
5448 - bool antenna_diversity;
5449 + bool bt_ant_diversity;
5450 };
5451
5452 struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
5453 --- a/drivers/net/wireless/ath/ath9k/antenna.c
5454 +++ b/drivers/net/wireless/ath/ath9k/antenna.c
5455 @@ -16,37 +16,119 @@
5456
5457 #include "ath9k.h"
5458
5459 -static inline bool ath_is_alt_ant_ratio_better(int alt_ratio, int maxdelta,
5460 +/*
5461 + * AR9285
5462 + * ======
5463 + *
5464 + * EEPROM has 2 4-bit fields containing the card configuration.
5465 + *
5466 + * antdiv_ctl1:
5467 + * ------------
5468 + * bb_enable_ant_div_lnadiv : 1
5469 + * bb_ant_div_alt_gaintb : 1
5470 + * bb_ant_div_main_gaintb : 1
5471 + * bb_enable_ant_fast_div : 1
5472 + *
5473 + * antdiv_ctl2:
5474 + * -----------
5475 + * bb_ant_div_alt_lnaconf : 2
5476 + * bb_ant_div_main_lnaconf : 2
5477 + *
5478 + * The EEPROM bits are used as follows:
5479 + * ------------------------------------
5480 + *
5481 + * bb_enable_ant_div_lnadiv - Enable LNA path rx antenna diversity/combining.
5482 + * Set in AR_PHY_MULTICHAIN_GAIN_CTL.
5483 + *
5484 + * bb_ant_div_[alt/main]_gaintb - 0 -> Antenna config Alt/Main uses gaintable 0
5485 + * 1 -> Antenna config Alt/Main uses gaintable 1
5486 + * Set in AR_PHY_MULTICHAIN_GAIN_CTL.
5487 + *
5488 + * bb_enable_ant_fast_div - Enable fast antenna diversity.
5489 + * Set in AR_PHY_CCK_DETECT.
5490 + *
5491 + * bb_ant_div_[alt/main]_lnaconf - Alt/Main LNA diversity/combining input config.
5492 + * Set in AR_PHY_MULTICHAIN_GAIN_CTL.
5493 + * 10=LNA1
5494 + * 01=LNA2
5495 + * 11=LNA1+LNA2
5496 + * 00=LNA1-LNA2
5497 + *
5498 + * AR9485 / AR9565 / AR9331
5499 + * ========================
5500 + *
5501 + * The same bits are present in the EEPROM, but the location in the
5502 + * EEPROM is different (ant_div_control in ar9300_BaseExtension_1).
5503 + *
5504 + * ant_div_alt_lnaconf ==> bit 0~1
5505 + * ant_div_main_lnaconf ==> bit 2~3
5506 + * ant_div_alt_gaintb ==> bit 4
5507 + * ant_div_main_gaintb ==> bit 5
5508 + * enable_ant_div_lnadiv ==> bit 6
5509 + * enable_ant_fast_div ==> bit 7
5510 + */
5511 +
5512 +static inline bool ath_is_alt_ant_ratio_better(struct ath_ant_comb *antcomb,
5513 + int alt_ratio, int maxdelta,
5514 int mindelta, int main_rssi_avg,
5515 int alt_rssi_avg, int pkt_count)
5516 {
5517 - return (((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
5518 - (alt_rssi_avg > main_rssi_avg + maxdelta)) ||
5519 - (alt_rssi_avg > main_rssi_avg + mindelta)) && (pkt_count > 50);
5520 + if (pkt_count <= 50)
5521 + return false;
5522 +
5523 + if (alt_rssi_avg > main_rssi_avg + mindelta)
5524 + return true;
5525 +
5526 + if (alt_ratio >= antcomb->ant_ratio2 &&
5527 + alt_rssi_avg >= antcomb->low_rssi_thresh &&
5528 + (alt_rssi_avg > main_rssi_avg + maxdelta))
5529 + return true;
5530 +
5531 + return false;
5532 }
5533
5534 -static inline bool ath_ant_div_comb_alt_check(u8 div_group, int alt_ratio,
5535 - int curr_main_set, int curr_alt_set,
5536 - int alt_rssi_avg, int main_rssi_avg)
5537 +static inline bool ath_ant_div_comb_alt_check(struct ath_hw_antcomb_conf *conf,
5538 + struct ath_ant_comb *antcomb,
5539 + int alt_ratio, int alt_rssi_avg,
5540 + int main_rssi_avg)
5541 {
5542 - bool result = false;
5543 - switch (div_group) {
5544 + bool result, set1, set2;
5545 +
5546 + result = set1 = set2 = false;
5547 +
5548 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2 &&
5549 + conf->alt_lna_conf == ATH_ANT_DIV_COMB_LNA1)
5550 + set1 = true;
5551 +
5552 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA1 &&
5553 + conf->alt_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5554 + set2 = true;
5555 +
5556 + switch (conf->div_group) {
5557 case 0:
5558 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
5559 result = true;
5560 break;
5561 case 1:
5562 case 2:
5563 - if ((((curr_main_set == ATH_ANT_DIV_COMB_LNA2) &&
5564 - (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) &&
5565 - (alt_rssi_avg >= (main_rssi_avg - 5))) ||
5566 - ((curr_main_set == ATH_ANT_DIV_COMB_LNA1) &&
5567 - (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) &&
5568 - (alt_rssi_avg >= (main_rssi_avg - 2)))) &&
5569 - (alt_rssi_avg >= 4))
5570 + if (alt_rssi_avg < 4 || alt_rssi_avg < antcomb->low_rssi_thresh)
5571 + break;
5572 +
5573 + if ((set1 && (alt_rssi_avg >= (main_rssi_avg - 5))) ||
5574 + (set2 && (alt_rssi_avg >= (main_rssi_avg - 2))) ||
5575 + (alt_ratio > antcomb->ant_ratio))
5576 result = true;
5577 - else
5578 - result = false;
5579 +
5580 + break;
5581 + case 3:
5582 + if (alt_rssi_avg < 4 || alt_rssi_avg < antcomb->low_rssi_thresh)
5583 + break;
5584 +
5585 + if ((set1 && (alt_rssi_avg >= (main_rssi_avg - 3))) ||
5586 + (set2 && (alt_rssi_avg >= (main_rssi_avg + 3))) ||
5587 + (alt_ratio > antcomb->ant_ratio))
5588 + result = true;
5589 +
5590 break;
5591 }
5592
5593 @@ -108,6 +190,74 @@ static void ath_lnaconf_alt_good_scan(st
5594 }
5595 }
5596
5597 +static void ath_ant_set_alt_ratio(struct ath_ant_comb *antcomb,
5598 + struct ath_hw_antcomb_conf *conf)
5599 +{
5600 + /* set alt to the conf with maximun ratio */
5601 + if (antcomb->first_ratio && antcomb->second_ratio) {
5602 + if (antcomb->rssi_second > antcomb->rssi_third) {
5603 + /* first alt*/
5604 + if ((antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
5605 + (antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2))
5606 + /* Set alt LNA1 or LNA2*/
5607 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5608 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5609 + else
5610 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5611 + else
5612 + /* Set alt to A+B or A-B */
5613 + conf->alt_lna_conf =
5614 + antcomb->first_quick_scan_conf;
5615 + } else if ((antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
5616 + (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2)) {
5617 + /* Set alt LNA1 or LNA2 */
5618 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5619 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5620 + else
5621 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5622 + } else {
5623 + /* Set alt to A+B or A-B */
5624 + conf->alt_lna_conf = antcomb->second_quick_scan_conf;
5625 + }
5626 + } else if (antcomb->first_ratio) {
5627 + /* first alt */
5628 + if ((antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
5629 + (antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2))
5630 + /* Set alt LNA1 or LNA2 */
5631 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5632 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5633 + else
5634 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5635 + else
5636 + /* Set alt to A+B or A-B */
5637 + conf->alt_lna_conf = antcomb->first_quick_scan_conf;
5638 + } else if (antcomb->second_ratio) {
5639 + /* second alt */
5640 + if ((antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
5641 + (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2))
5642 + /* Set alt LNA1 or LNA2 */
5643 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5644 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5645 + else
5646 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5647 + else
5648 + /* Set alt to A+B or A-B */
5649 + conf->alt_lna_conf = antcomb->second_quick_scan_conf;
5650 + } else {
5651 + /* main is largest */
5652 + if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
5653 + (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
5654 + /* Set alt LNA1 or LNA2 */
5655 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5656 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5657 + else
5658 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5659 + else
5660 + /* Set alt to A+B or A-B */
5661 + conf->alt_lna_conf = antcomb->main_conf;
5662 + }
5663 +}
5664 +
5665 static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
5666 struct ath_hw_antcomb_conf *div_ant_conf,
5667 int main_rssi_avg, int alt_rssi_avg,
5668 @@ -129,7 +279,7 @@ static void ath_select_ant_div_from_quic
5669
5670 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
5671 /* main is LNA1 */
5672 - if (ath_is_alt_ant_ratio_better(alt_ratio,
5673 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5674 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
5675 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
5676 main_rssi_avg, alt_rssi_avg,
5677 @@ -138,7 +288,7 @@ static void ath_select_ant_div_from_quic
5678 else
5679 antcomb->first_ratio = false;
5680 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
5681 - if (ath_is_alt_ant_ratio_better(alt_ratio,
5682 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5683 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
5684 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
5685 main_rssi_avg, alt_rssi_avg,
5686 @@ -147,11 +297,11 @@ static void ath_select_ant_div_from_quic
5687 else
5688 antcomb->first_ratio = false;
5689 } else {
5690 - if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
5691 - (alt_rssi_avg > main_rssi_avg +
5692 - ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
5693 - (alt_rssi_avg > main_rssi_avg)) &&
5694 - (antcomb->total_pkt_count > 50))
5695 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5696 + ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
5697 + 0,
5698 + main_rssi_avg, alt_rssi_avg,
5699 + antcomb->total_pkt_count))
5700 antcomb->first_ratio = true;
5701 else
5702 antcomb->first_ratio = false;
5703 @@ -164,17 +314,21 @@ static void ath_select_ant_div_from_quic
5704 antcomb->rssi_first = main_rssi_avg;
5705 antcomb->rssi_third = alt_rssi_avg;
5706
5707 - if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1)
5708 + switch(antcomb->second_quick_scan_conf) {
5709 + case ATH_ANT_DIV_COMB_LNA1:
5710 antcomb->rssi_lna1 = alt_rssi_avg;
5711 - else if (antcomb->second_quick_scan_conf ==
5712 - ATH_ANT_DIV_COMB_LNA2)
5713 + break;
5714 + case ATH_ANT_DIV_COMB_LNA2:
5715 antcomb->rssi_lna2 = alt_rssi_avg;
5716 - else if (antcomb->second_quick_scan_conf ==
5717 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) {
5718 + break;
5719 + case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
5720 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)
5721 antcomb->rssi_lna2 = main_rssi_avg;
5722 else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1)
5723 antcomb->rssi_lna1 = main_rssi_avg;
5724 + break;
5725 + default:
5726 + break;
5727 }
5728
5729 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
5730 @@ -184,7 +338,7 @@ static void ath_select_ant_div_from_quic
5731 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5732
5733 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
5734 - if (ath_is_alt_ant_ratio_better(alt_ratio,
5735 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5736 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
5737 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
5738 main_rssi_avg, alt_rssi_avg,
5739 @@ -193,7 +347,7 @@ static void ath_select_ant_div_from_quic
5740 else
5741 antcomb->second_ratio = false;
5742 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
5743 - if (ath_is_alt_ant_ratio_better(alt_ratio,
5744 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5745 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
5746 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
5747 main_rssi_avg, alt_rssi_avg,
5748 @@ -202,105 +356,18 @@ static void ath_select_ant_div_from_quic
5749 else
5750 antcomb->second_ratio = false;
5751 } else {
5752 - if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
5753 - (alt_rssi_avg > main_rssi_avg +
5754 - ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
5755 - (alt_rssi_avg > main_rssi_avg)) &&
5756 - (antcomb->total_pkt_count > 50))
5757 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5758 + ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
5759 + 0,
5760 + main_rssi_avg, alt_rssi_avg,
5761 + antcomb->total_pkt_count))
5762 antcomb->second_ratio = true;
5763 else
5764 antcomb->second_ratio = false;
5765 }
5766
5767 - /* set alt to the conf with maximun ratio */
5768 - if (antcomb->first_ratio && antcomb->second_ratio) {
5769 - if (antcomb->rssi_second > antcomb->rssi_third) {
5770 - /* first alt*/
5771 - if ((antcomb->first_quick_scan_conf ==
5772 - ATH_ANT_DIV_COMB_LNA1) ||
5773 - (antcomb->first_quick_scan_conf ==
5774 - ATH_ANT_DIV_COMB_LNA2))
5775 - /* Set alt LNA1 or LNA2*/
5776 - if (div_ant_conf->main_lna_conf ==
5777 - ATH_ANT_DIV_COMB_LNA2)
5778 - div_ant_conf->alt_lna_conf =
5779 - ATH_ANT_DIV_COMB_LNA1;
5780 - else
5781 - div_ant_conf->alt_lna_conf =
5782 - ATH_ANT_DIV_COMB_LNA2;
5783 - else
5784 - /* Set alt to A+B or A-B */
5785 - div_ant_conf->alt_lna_conf =
5786 - antcomb->first_quick_scan_conf;
5787 - } else if ((antcomb->second_quick_scan_conf ==
5788 - ATH_ANT_DIV_COMB_LNA1) ||
5789 - (antcomb->second_quick_scan_conf ==
5790 - ATH_ANT_DIV_COMB_LNA2)) {
5791 - /* Set alt LNA1 or LNA2 */
5792 - if (div_ant_conf->main_lna_conf ==
5793 - ATH_ANT_DIV_COMB_LNA2)
5794 - div_ant_conf->alt_lna_conf =
5795 - ATH_ANT_DIV_COMB_LNA1;
5796 - else
5797 - div_ant_conf->alt_lna_conf =
5798 - ATH_ANT_DIV_COMB_LNA2;
5799 - } else {
5800 - /* Set alt to A+B or A-B */
5801 - div_ant_conf->alt_lna_conf =
5802 - antcomb->second_quick_scan_conf;
5803 - }
5804 - } else if (antcomb->first_ratio) {
5805 - /* first alt */
5806 - if ((antcomb->first_quick_scan_conf ==
5807 - ATH_ANT_DIV_COMB_LNA1) ||
5808 - (antcomb->first_quick_scan_conf ==
5809 - ATH_ANT_DIV_COMB_LNA2))
5810 - /* Set alt LNA1 or LNA2 */
5811 - if (div_ant_conf->main_lna_conf ==
5812 - ATH_ANT_DIV_COMB_LNA2)
5813 - div_ant_conf->alt_lna_conf =
5814 - ATH_ANT_DIV_COMB_LNA1;
5815 - else
5816 - div_ant_conf->alt_lna_conf =
5817 - ATH_ANT_DIV_COMB_LNA2;
5818 - else
5819 - /* Set alt to A+B or A-B */
5820 - div_ant_conf->alt_lna_conf =
5821 - antcomb->first_quick_scan_conf;
5822 - } else if (antcomb->second_ratio) {
5823 - /* second alt */
5824 - if ((antcomb->second_quick_scan_conf ==
5825 - ATH_ANT_DIV_COMB_LNA1) ||
5826 - (antcomb->second_quick_scan_conf ==
5827 - ATH_ANT_DIV_COMB_LNA2))
5828 - /* Set alt LNA1 or LNA2 */
5829 - if (div_ant_conf->main_lna_conf ==
5830 - ATH_ANT_DIV_COMB_LNA2)
5831 - div_ant_conf->alt_lna_conf =
5832 - ATH_ANT_DIV_COMB_LNA1;
5833 - else
5834 - div_ant_conf->alt_lna_conf =
5835 - ATH_ANT_DIV_COMB_LNA2;
5836 - else
5837 - /* Set alt to A+B or A-B */
5838 - div_ant_conf->alt_lna_conf =
5839 - antcomb->second_quick_scan_conf;
5840 - } else {
5841 - /* main is largest */
5842 - if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
5843 - (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
5844 - /* Set alt LNA1 or LNA2 */
5845 - if (div_ant_conf->main_lna_conf ==
5846 - ATH_ANT_DIV_COMB_LNA2)
5847 - div_ant_conf->alt_lna_conf =
5848 - ATH_ANT_DIV_COMB_LNA1;
5849 - else
5850 - div_ant_conf->alt_lna_conf =
5851 - ATH_ANT_DIV_COMB_LNA2;
5852 - else
5853 - /* Set alt to A+B or A-B */
5854 - div_ant_conf->alt_lna_conf = antcomb->main_conf;
5855 - }
5856 + ath_ant_set_alt_ratio(antcomb, div_ant_conf);
5857 +
5858 break;
5859 default:
5860 break;
5861 @@ -430,8 +497,7 @@ static void ath_ant_div_conf_fast_divbia
5862 ant_conf->fast_div_bias = 0x1;
5863 break;
5864 case 0x10: /* LNA2 A-B */
5865 - if (!(antcomb->scan) &&
5866 - (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
5867 + if (!antcomb->scan && (alt_ratio > antcomb->ant_ratio))
5868 ant_conf->fast_div_bias = 0x1;
5869 else
5870 ant_conf->fast_div_bias = 0x2;
5871 @@ -440,15 +506,13 @@ static void ath_ant_div_conf_fast_divbia
5872 ant_conf->fast_div_bias = 0x1;
5873 break;
5874 case 0x13: /* LNA2 A+B */
5875 - if (!(antcomb->scan) &&
5876 - (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
5877 + if (!antcomb->scan && (alt_ratio > antcomb->ant_ratio))
5878 ant_conf->fast_div_bias = 0x1;
5879 else
5880 ant_conf->fast_div_bias = 0x2;
5881 break;
5882 case 0x20: /* LNA1 A-B */
5883 - if (!(antcomb->scan) &&
5884 - (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
5885 + if (!antcomb->scan && (alt_ratio > antcomb->ant_ratio))
5886 ant_conf->fast_div_bias = 0x1;
5887 else
5888 ant_conf->fast_div_bias = 0x2;
5889 @@ -457,8 +521,7 @@ static void ath_ant_div_conf_fast_divbia
5890 ant_conf->fast_div_bias = 0x1;
5891 break;
5892 case 0x23: /* LNA1 A+B */
5893 - if (!(antcomb->scan) &&
5894 - (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
5895 + if (!antcomb->scan && (alt_ratio > antcomb->ant_ratio))
5896 ant_conf->fast_div_bias = 0x1;
5897 else
5898 ant_conf->fast_div_bias = 0x2;
5899 @@ -475,6 +538,9 @@ static void ath_ant_div_conf_fast_divbia
5900 default:
5901 break;
5902 }
5903 +
5904 + if (antcomb->fast_div_bias)
5905 + ant_conf->fast_div_bias = antcomb->fast_div_bias;
5906 } else if (ant_conf->div_group == 3) {
5907 switch ((ant_conf->main_lna_conf << 4) |
5908 ant_conf->alt_lna_conf) {
5909 @@ -540,6 +606,138 @@ static void ath_ant_div_conf_fast_divbia
5910 }
5911 }
5912
5913 +static void ath_ant_try_scan(struct ath_ant_comb *antcomb,
5914 + struct ath_hw_antcomb_conf *conf,
5915 + int curr_alt_set, int alt_rssi_avg,
5916 + int main_rssi_avg)
5917 +{
5918 + switch (curr_alt_set) {
5919 + case ATH_ANT_DIV_COMB_LNA2:
5920 + antcomb->rssi_lna2 = alt_rssi_avg;
5921 + antcomb->rssi_lna1 = main_rssi_avg;
5922 + antcomb->scan = true;
5923 + /* set to A+B */
5924 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5925 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
5926 + break;
5927 + case ATH_ANT_DIV_COMB_LNA1:
5928 + antcomb->rssi_lna1 = alt_rssi_avg;
5929 + antcomb->rssi_lna2 = main_rssi_avg;
5930 + antcomb->scan = true;
5931 + /* set to A+B */
5932 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5933 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
5934 + break;
5935 + case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
5936 + antcomb->rssi_add = alt_rssi_avg;
5937 + antcomb->scan = true;
5938 + /* set to A-B */
5939 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
5940 + break;
5941 + case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
5942 + antcomb->rssi_sub = alt_rssi_avg;
5943 + antcomb->scan = false;
5944 + if (antcomb->rssi_lna2 >
5945 + (antcomb->rssi_lna1 + ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
5946 + /* use LNA2 as main LNA */
5947 + if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
5948 + (antcomb->rssi_add > antcomb->rssi_sub)) {
5949 + /* set to A+B */
5950 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5951 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
5952 + } else if (antcomb->rssi_sub >
5953 + antcomb->rssi_lna1) {
5954 + /* set to A-B */
5955 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5956 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
5957 + } else {
5958 + /* set to LNA1 */
5959 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5960 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5961 + }
5962 + } else {
5963 + /* use LNA1 as main LNA */
5964 + if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
5965 + (antcomb->rssi_add > antcomb->rssi_sub)) {
5966 + /* set to A+B */
5967 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5968 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
5969 + } else if (antcomb->rssi_sub >
5970 + antcomb->rssi_lna1) {
5971 + /* set to A-B */
5972 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5973 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
5974 + } else {
5975 + /* set to LNA2 */
5976 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5977 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5978 + }
5979 + }
5980 + break;
5981 + default:
5982 + break;
5983 + }
5984 +}
5985 +
5986 +static bool ath_ant_try_switch(struct ath_hw_antcomb_conf *div_ant_conf,
5987 + struct ath_ant_comb *antcomb,
5988 + int alt_ratio, int alt_rssi_avg,
5989 + int main_rssi_avg, int curr_main_set,
5990 + int curr_alt_set)
5991 +{
5992 + bool ret = false;
5993 +
5994 + if (ath_ant_div_comb_alt_check(div_ant_conf, antcomb, alt_ratio,
5995 + alt_rssi_avg, main_rssi_avg)) {
5996 + if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
5997 + /*
5998 + * Switch main and alt LNA.
5999 + */
6000 + div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
6001 + div_ant_conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
6002 + } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
6003 + div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
6004 + div_ant_conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
6005 + }
6006 +
6007 + ret = true;
6008 + } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
6009 + (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
6010 + /*
6011 + Set alt to another LNA.
6012 + */
6013 + if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
6014 + div_ant_conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
6015 + else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
6016 + div_ant_conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
6017 +
6018 + ret = true;
6019 + }
6020 +
6021 + return ret;
6022 +}
6023 +
6024 +static bool ath_ant_short_scan_check(struct ath_ant_comb *antcomb)
6025 +{
6026 + int alt_ratio;
6027 +
6028 + if (!antcomb->scan || !antcomb->alt_good)
6029 + return false;
6030 +
6031 + if (time_after(jiffies, antcomb->scan_start_time +
6032 + msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
6033 + return true;
6034 +
6035 + if (antcomb->total_pkt_count == ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
6036 + alt_ratio = ((antcomb->alt_recv_cnt * 100) /
6037 + antcomb->total_pkt_count);
6038 + if (alt_ratio < antcomb->ant_ratio)
6039 + return true;
6040 + }
6041 +
6042 + return false;
6043 +}
6044 +
6045 void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs)
6046 {
6047 struct ath_hw_antcomb_conf div_ant_conf;
6048 @@ -549,41 +747,46 @@ void ath_ant_comb_scan(struct ath_softc
6049 int main_rssi = rs->rs_rssi_ctl0;
6050 int alt_rssi = rs->rs_rssi_ctl1;
6051 int rx_ant_conf, main_ant_conf;
6052 - bool short_scan = false;
6053 + bool short_scan = false, ret;
6054
6055 rx_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_CURRENT_SHIFT) &
6056 ATH_ANT_RX_MASK;
6057 main_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_MAIN_SHIFT) &
6058 ATH_ANT_RX_MASK;
6059
6060 + if (alt_rssi >= antcomb->low_rssi_thresh) {
6061 + antcomb->ant_ratio = ATH_ANT_DIV_COMB_ALT_ANT_RATIO;
6062 + antcomb->ant_ratio2 = ATH_ANT_DIV_COMB_ALT_ANT_RATIO2;
6063 + } else {
6064 + antcomb->ant_ratio = ATH_ANT_DIV_COMB_ALT_ANT_RATIO_LOW_RSSI;
6065 + antcomb->ant_ratio2 = ATH_ANT_DIV_COMB_ALT_ANT_RATIO2_LOW_RSSI;
6066 + }
6067 +
6068 /* Record packet only when both main_rssi and alt_rssi is positive */
6069 if (main_rssi > 0 && alt_rssi > 0) {
6070 antcomb->total_pkt_count++;
6071 antcomb->main_total_rssi += main_rssi;
6072 antcomb->alt_total_rssi += alt_rssi;
6073 +
6074 if (main_ant_conf == rx_ant_conf)
6075 antcomb->main_recv_cnt++;
6076 else
6077 antcomb->alt_recv_cnt++;
6078 }
6079
6080 - /* Short scan check */
6081 - if (antcomb->scan && antcomb->alt_good) {
6082 - if (time_after(jiffies, antcomb->scan_start_time +
6083 - msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
6084 - short_scan = true;
6085 - else
6086 - if (antcomb->total_pkt_count ==
6087 - ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
6088 - alt_ratio = ((antcomb->alt_recv_cnt * 100) /
6089 - antcomb->total_pkt_count);
6090 - if (alt_ratio < ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
6091 - short_scan = true;
6092 - }
6093 + if (main_ant_conf == rx_ant_conf) {
6094 + ANT_STAT_INC(ANT_MAIN, recv_cnt);
6095 + ANT_LNA_INC(ANT_MAIN, rx_ant_conf);
6096 + } else {
6097 + ANT_STAT_INC(ANT_ALT, recv_cnt);
6098 + ANT_LNA_INC(ANT_ALT, rx_ant_conf);
6099 }
6100
6101 + /* Short scan check */
6102 + short_scan = ath_ant_short_scan_check(antcomb);
6103 +
6104 if (((antcomb->total_pkt_count < ATH_ANT_DIV_COMB_MAX_PKTCOUNT) ||
6105 - rs->rs_moreaggr) && !short_scan)
6106 + rs->rs_moreaggr) && !short_scan)
6107 return;
6108
6109 if (antcomb->total_pkt_count) {
6110 @@ -595,15 +798,13 @@ void ath_ant_comb_scan(struct ath_softc
6111 antcomb->total_pkt_count);
6112 }
6113
6114 -
6115 ath9k_hw_antdiv_comb_conf_get(sc->sc_ah, &div_ant_conf);
6116 curr_alt_set = div_ant_conf.alt_lna_conf;
6117 curr_main_set = div_ant_conf.main_lna_conf;
6118 -
6119 antcomb->count++;
6120
6121 if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) {
6122 - if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
6123 + if (alt_ratio > antcomb->ant_ratio) {
6124 ath_lnaconf_alt_good_scan(antcomb, div_ant_conf,
6125 main_rssi_avg);
6126 antcomb->alt_good = true;
6127 @@ -617,153 +818,47 @@ void ath_ant_comb_scan(struct ath_softc
6128 }
6129
6130 if (!antcomb->scan) {
6131 - if (ath_ant_div_comb_alt_check(div_ant_conf.div_group,
6132 - alt_ratio, curr_main_set, curr_alt_set,
6133 - alt_rssi_avg, main_rssi_avg)) {
6134 - if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
6135 - /* Switch main and alt LNA */
6136 - div_ant_conf.main_lna_conf =
6137 - ATH_ANT_DIV_COMB_LNA2;
6138 - div_ant_conf.alt_lna_conf =
6139 - ATH_ANT_DIV_COMB_LNA1;
6140 - } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
6141 - div_ant_conf.main_lna_conf =
6142 - ATH_ANT_DIV_COMB_LNA1;
6143 - div_ant_conf.alt_lna_conf =
6144 - ATH_ANT_DIV_COMB_LNA2;
6145 - }
6146 -
6147 - goto div_comb_done;
6148 - } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
6149 - (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
6150 - /* Set alt to another LNA */
6151 - if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
6152 - div_ant_conf.alt_lna_conf =
6153 - ATH_ANT_DIV_COMB_LNA1;
6154 - else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
6155 - div_ant_conf.alt_lna_conf =
6156 - ATH_ANT_DIV_COMB_LNA2;
6157 -
6158 - goto div_comb_done;
6159 - }
6160 -
6161 - if ((alt_rssi_avg < (main_rssi_avg +
6162 - div_ant_conf.lna1_lna2_delta)))
6163 + ret = ath_ant_try_switch(&div_ant_conf, antcomb, alt_ratio,
6164 + alt_rssi_avg, main_rssi_avg,
6165 + curr_main_set, curr_alt_set);
6166 + if (ret)
6167 goto div_comb_done;
6168 }
6169
6170 + if (!antcomb->scan &&
6171 + (alt_rssi_avg < (main_rssi_avg + div_ant_conf.lna1_lna2_delta)))
6172 + goto div_comb_done;
6173 +
6174 if (!antcomb->scan_not_start) {
6175 - switch (curr_alt_set) {
6176 - case ATH_ANT_DIV_COMB_LNA2:
6177 - antcomb->rssi_lna2 = alt_rssi_avg;
6178 - antcomb->rssi_lna1 = main_rssi_avg;
6179 - antcomb->scan = true;
6180 - /* set to A+B */
6181 - div_ant_conf.main_lna_conf =
6182 - ATH_ANT_DIV_COMB_LNA1;
6183 - div_ant_conf.alt_lna_conf =
6184 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
6185 - break;
6186 - case ATH_ANT_DIV_COMB_LNA1:
6187 - antcomb->rssi_lna1 = alt_rssi_avg;
6188 - antcomb->rssi_lna2 = main_rssi_avg;
6189 - antcomb->scan = true;
6190 - /* set to A+B */
6191 - div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
6192 - div_ant_conf.alt_lna_conf =
6193 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
6194 - break;
6195 - case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
6196 - antcomb->rssi_add = alt_rssi_avg;
6197 - antcomb->scan = true;
6198 - /* set to A-B */
6199 - div_ant_conf.alt_lna_conf =
6200 - ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
6201 - break;
6202 - case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
6203 - antcomb->rssi_sub = alt_rssi_avg;
6204 - antcomb->scan = false;
6205 - if (antcomb->rssi_lna2 >
6206 - (antcomb->rssi_lna1 +
6207 - ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
6208 - /* use LNA2 as main LNA */
6209 - if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
6210 - (antcomb->rssi_add > antcomb->rssi_sub)) {
6211 - /* set to A+B */
6212 - div_ant_conf.main_lna_conf =
6213 - ATH_ANT_DIV_COMB_LNA2;
6214 - div_ant_conf.alt_lna_conf =
6215 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
6216 - } else if (antcomb->rssi_sub >
6217 - antcomb->rssi_lna1) {
6218 - /* set to A-B */
6219 - div_ant_conf.main_lna_conf =
6220 - ATH_ANT_DIV_COMB_LNA2;
6221 - div_ant_conf.alt_lna_conf =
6222 - ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
6223 - } else {
6224 - /* set to LNA1 */
6225 - div_ant_conf.main_lna_conf =
6226 - ATH_ANT_DIV_COMB_LNA2;
6227 - div_ant_conf.alt_lna_conf =
6228 - ATH_ANT_DIV_COMB_LNA1;
6229 - }
6230 - } else {
6231 - /* use LNA1 as main LNA */
6232 - if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
6233 - (antcomb->rssi_add > antcomb->rssi_sub)) {
6234 - /* set to A+B */
6235 - div_ant_conf.main_lna_conf =
6236 - ATH_ANT_DIV_COMB_LNA1;
6237 - div_ant_conf.alt_lna_conf =
6238 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
6239 - } else if (antcomb->rssi_sub >
6240 - antcomb->rssi_lna1) {
6241 - /* set to A-B */
6242 - div_ant_conf.main_lna_conf =
6243 - ATH_ANT_DIV_COMB_LNA1;
6244 - div_ant_conf.alt_lna_conf =
6245 - ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
6246 - } else {
6247 - /* set to LNA2 */
6248 - div_ant_conf.main_lna_conf =
6249 - ATH_ANT_DIV_COMB_LNA1;
6250 - div_ant_conf.alt_lna_conf =
6251 - ATH_ANT_DIV_COMB_LNA2;
6252 - }
6253 - }
6254 - break;
6255 - default:
6256 - break;
6257 - }
6258 + ath_ant_try_scan(antcomb, &div_ant_conf, curr_alt_set,
6259 + alt_rssi_avg, main_rssi_avg);
6260 } else {
6261 if (!antcomb->alt_good) {
6262 antcomb->scan_not_start = false;
6263 /* Set alt to another LNA */
6264 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) {
6265 div_ant_conf.main_lna_conf =
6266 - ATH_ANT_DIV_COMB_LNA2;
6267 + ATH_ANT_DIV_COMB_LNA2;
6268 div_ant_conf.alt_lna_conf =
6269 - ATH_ANT_DIV_COMB_LNA1;
6270 + ATH_ANT_DIV_COMB_LNA1;
6271 } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) {
6272 div_ant_conf.main_lna_conf =
6273 - ATH_ANT_DIV_COMB_LNA1;
6274 + ATH_ANT_DIV_COMB_LNA1;
6275 div_ant_conf.alt_lna_conf =
6276 - ATH_ANT_DIV_COMB_LNA2;
6277 + ATH_ANT_DIV_COMB_LNA2;
6278 }
6279 goto div_comb_done;
6280 }
6281 + ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
6282 + main_rssi_avg, alt_rssi_avg,
6283 + alt_ratio);
6284 + antcomb->quick_scan_cnt++;
6285 }
6286
6287 - ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
6288 - main_rssi_avg, alt_rssi_avg,
6289 - alt_ratio);
6290 -
6291 - antcomb->quick_scan_cnt++;
6292 -
6293 div_comb_done:
6294 ath_ant_div_conf_fast_divbias(&div_ant_conf, antcomb, alt_ratio);
6295 ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf);
6296 + ath9k_debug_stat_ant(sc, &div_ant_conf, main_rssi_avg, alt_rssi_avg);
6297
6298 antcomb->scan_start_time = jiffies;
6299 antcomb->total_pkt_count = 0;
6300 @@ -772,26 +867,3 @@ div_comb_done:
6301 antcomb->main_recv_cnt = 0;
6302 antcomb->alt_recv_cnt = 0;
6303 }
6304 -
6305 -void ath_ant_comb_update(struct ath_softc *sc)
6306 -{
6307 - struct ath_hw *ah = sc->sc_ah;
6308 - struct ath_common *common = ath9k_hw_common(ah);
6309 - struct ath_hw_antcomb_conf div_ant_conf;
6310 - u8 lna_conf;
6311 -
6312 - ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
6313 -
6314 - if (sc->ant_rx == 1)
6315 - lna_conf = ATH_ANT_DIV_COMB_LNA1;
6316 - else
6317 - lna_conf = ATH_ANT_DIV_COMB_LNA2;
6318 -
6319 - div_ant_conf.main_lna_conf = lna_conf;
6320 - div_ant_conf.alt_lna_conf = lna_conf;
6321 -
6322 - ath9k_hw_antdiv_comb_conf_set(ah, &div_ant_conf);
6323 -
6324 - if (common->antenna_diversity)
6325 - ath9k_hw_antctrl_shared_chain_lnadiv(ah, true);
6326 -}
6327 --- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
6328 +++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
6329 @@ -610,7 +610,15 @@ static void ar5008_hw_override_ini(struc
6330 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
6331
6332 if (AR_SREV_9280_20_OR_LATER(ah)) {
6333 - val = REG_READ(ah, AR_PCU_MISC_MODE2);
6334 + /*
6335 + * For AR9280 and above, there is a new feature that allows
6336 + * Multicast search based on both MAC Address and Key ID.
6337 + * By default, this feature is enabled. But since the driver
6338 + * is not using this feature, we switch it off; otherwise
6339 + * multicast search based on MAC addr only will fail.
6340 + */
6341 + val = REG_READ(ah, AR_PCU_MISC_MODE2) &
6342 + (~AR_ADHOC_MCAST_KEYID_ENABLE);
6343
6344 if (!AR_SREV_9271(ah))
6345 val &= ~AR_PCU_MISC_MODE2_HWWAR1;
6346 --- a/drivers/net/wireless/ath/ath9k/ar9002_phy.c
6347 +++ b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
6348 @@ -555,6 +555,69 @@ static void ar9002_hw_antdiv_comb_conf_s
6349 REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regval);
6350 }
6351
6352 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
6353 +
6354 +static void ar9002_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable)
6355 +{
6356 + struct ath_btcoex_hw *btcoex = &ah->btcoex_hw;
6357 + u8 antdiv_ctrl1, antdiv_ctrl2;
6358 + u32 regval;
6359 +
6360 + if (enable) {
6361 + antdiv_ctrl1 = ATH_BT_COEX_ANTDIV_CONTROL1_ENABLE;
6362 + antdiv_ctrl2 = ATH_BT_COEX_ANTDIV_CONTROL2_ENABLE;
6363 +
6364 + /*
6365 + * Don't disable BT ant to allow BB to control SWCOM.
6366 + */
6367 + btcoex->bt_coex_mode2 &= (~(AR_BT_DISABLE_BT_ANT));
6368 + REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex->bt_coex_mode2);
6369 +
6370 + REG_WRITE(ah, AR_PHY_SWITCH_COM, ATH_BT_COEX_ANT_DIV_SWITCH_COM);
6371 + REG_RMW(ah, AR_PHY_SWITCH_CHAIN_0, 0, 0xf0000000);
6372 + } else {
6373 + /*
6374 + * Disable antenna diversity, use LNA1 only.
6375 + */
6376 + antdiv_ctrl1 = ATH_BT_COEX_ANTDIV_CONTROL1_FIXED_A;
6377 + antdiv_ctrl2 = ATH_BT_COEX_ANTDIV_CONTROL2_FIXED_A;
6378 +
6379 + /*
6380 + * Disable BT Ant. to allow concurrent BT and WLAN receive.
6381 + */
6382 + btcoex->bt_coex_mode2 |= AR_BT_DISABLE_BT_ANT;
6383 + REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex->bt_coex_mode2);
6384 +
6385 + /*
6386 + * Program SWCOM table to make sure RF switch always parks
6387 + * at BT side.
6388 + */
6389 + REG_WRITE(ah, AR_PHY_SWITCH_COM, 0);
6390 + REG_RMW(ah, AR_PHY_SWITCH_CHAIN_0, 0, 0xf0000000);
6391 + }
6392 +
6393 + regval = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
6394 + regval &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL));
6395 + /*
6396 + * Clear ant_fast_div_bias [14:9] since for WB195,
6397 + * the main LNA is always LNA1.
6398 + */
6399 + regval &= (~(AR_PHY_9285_FAST_DIV_BIAS));
6400 + regval |= SM(antdiv_ctrl1, AR_PHY_9285_ANT_DIV_CTL);
6401 + regval |= SM(antdiv_ctrl2, AR_PHY_9285_ANT_DIV_ALT_LNACONF);
6402 + regval |= SM((antdiv_ctrl2 >> 2), AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
6403 + regval |= SM((antdiv_ctrl1 >> 1), AR_PHY_9285_ANT_DIV_ALT_GAINTB);
6404 + regval |= SM((antdiv_ctrl1 >> 2), AR_PHY_9285_ANT_DIV_MAIN_GAINTB);
6405 + REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regval);
6406 +
6407 + regval = REG_READ(ah, AR_PHY_CCK_DETECT);
6408 + regval &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
6409 + regval |= SM((antdiv_ctrl1 >> 3), AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
6410 + REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
6411 +}
6412 +
6413 +#endif
6414 +
6415 static void ar9002_hw_spectral_scan_config(struct ath_hw *ah,
6416 struct ath_spec_scan *param)
6417 {
6418 @@ -634,5 +697,9 @@ void ar9002_hw_attach_phy_ops(struct ath
6419 ops->spectral_scan_trigger = ar9002_hw_spectral_scan_trigger;
6420 ops->spectral_scan_wait = ar9002_hw_spectral_scan_wait;
6421
6422 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
6423 + ops->set_bt_ant_diversity = ar9002_hw_set_bt_ant_diversity;
6424 +#endif
6425 +
6426 ar9002_hw_set_nf_limits(ah);
6427 }
6428 --- a/drivers/net/wireless/ath/ath9k/ar9002_phy.h
6429 +++ b/drivers/net/wireless/ath/ath9k/ar9002_phy.h
6430 @@ -317,13 +317,15 @@
6431 #define AR_PHY_9285_ANT_DIV_ALT_GAINTB_S 29
6432 #define AR_PHY_9285_ANT_DIV_MAIN_GAINTB 0x40000000
6433 #define AR_PHY_9285_ANT_DIV_MAIN_GAINTB_S 30
6434 -#define AR_PHY_9285_ANT_DIV_LNA1 2
6435 -#define AR_PHY_9285_ANT_DIV_LNA2 1
6436 -#define AR_PHY_9285_ANT_DIV_LNA1_PLUS_LNA2 3
6437 -#define AR_PHY_9285_ANT_DIV_LNA1_MINUS_LNA2 0
6438 #define AR_PHY_9285_ANT_DIV_GAINTB_0 0
6439 #define AR_PHY_9285_ANT_DIV_GAINTB_1 1
6440
6441 +#define ATH_BT_COEX_ANTDIV_CONTROL1_ENABLE 0x0b
6442 +#define ATH_BT_COEX_ANTDIV_CONTROL2_ENABLE 0x09
6443 +#define ATH_BT_COEX_ANTDIV_CONTROL1_FIXED_A 0x04
6444 +#define ATH_BT_COEX_ANTDIV_CONTROL2_FIXED_A 0x09
6445 +#define ATH_BT_COEX_ANT_DIV_SWITCH_COM 0x66666666
6446 +
6447 #define AR_PHY_EXT_CCA0 0x99b8
6448 #define AR_PHY_EXT_CCA0_THRESH62 0x000000FF
6449 #define AR_PHY_EXT_CCA0_THRESH62_S 0
6450 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
6451 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
6452 @@ -3541,13 +3541,12 @@ static u16 ar9003_switch_com_spdt_get(st
6453 return le16_to_cpu(ar9003_modal_header(ah, is2ghz)->switchcomspdt);
6454 }
6455
6456 -
6457 -static u32 ar9003_hw_ant_ctrl_common_get(struct ath_hw *ah, bool is2ghz)
6458 +u32 ar9003_hw_ant_ctrl_common_get(struct ath_hw *ah, bool is2ghz)
6459 {
6460 return le32_to_cpu(ar9003_modal_header(ah, is2ghz)->antCtrlCommon);
6461 }
6462
6463 -static u32 ar9003_hw_ant_ctrl_common_2_get(struct ath_hw *ah, bool is2ghz)
6464 +u32 ar9003_hw_ant_ctrl_common_2_get(struct ath_hw *ah, bool is2ghz)
6465 {
6466 return le32_to_cpu(ar9003_modal_header(ah, is2ghz)->antCtrlCommon2);
6467 }
6468 @@ -3561,6 +3560,7 @@ static u16 ar9003_hw_ant_ctrl_chain_get(
6469
6470 static void ar9003_hw_ant_ctrl_apply(struct ath_hw *ah, bool is2ghz)
6471 {
6472 + struct ath_common *common = ath9k_hw_common(ah);
6473 struct ath9k_hw_capabilities *pCap = &ah->caps;
6474 int chain;
6475 u32 regval, value, gpio;
6476 @@ -3614,6 +3614,11 @@ static void ar9003_hw_ant_ctrl_apply(str
6477 }
6478
6479 value = ar9003_hw_ant_ctrl_common_2_get(ah, is2ghz);
6480 + if (AR_SREV_9485(ah) && common->bt_ant_diversity) {
6481 + regval &= ~AR_SWITCH_TABLE_COM2_ALL;
6482 + regval |= ah->config.ant_ctrl_comm2g_switch_enable;
6483 +
6484 + }
6485 REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2, AR_SWITCH_TABLE_COM2_ALL, value);
6486
6487 if ((AR_SREV_9462(ah)) && (ah->rxchainmask == 0x2)) {
6488 @@ -3645,8 +3650,11 @@ static void ar9003_hw_ant_ctrl_apply(str
6489 regval &= (~AR_PHY_ANT_DIV_LNADIV);
6490 regval |= ((value >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S;
6491
6492 + if (AR_SREV_9485(ah) && common->bt_ant_diversity)
6493 + regval |= AR_ANT_DIV_ENABLE;
6494 +
6495 if (AR_SREV_9565(ah)) {
6496 - if (ah->shared_chain_lnadiv) {
6497 + if (common->bt_ant_diversity) {
6498 regval |= (1 << AR_PHY_ANT_SW_RX_PROT_S);
6499 } else {
6500 regval &= ~(1 << AR_PHY_ANT_DIV_LNADIV_S);
6501 @@ -3656,10 +3664,14 @@ static void ar9003_hw_ant_ctrl_apply(str
6502
6503 REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
6504
6505 - /*enable fast_div */
6506 + /* enable fast_div */
6507 regval = REG_READ(ah, AR_PHY_CCK_DETECT);
6508 regval &= (~AR_FAST_DIV_ENABLE);
6509 regval |= ((value >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
6510 +
6511 + if (AR_SREV_9485(ah) && common->bt_ant_diversity)
6512 + regval |= AR_FAST_DIV_ENABLE;
6513 +
6514 REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
6515
6516 if (pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
6517 @@ -3673,9 +3685,9 @@ static void ar9003_hw_ant_ctrl_apply(str
6518 AR_PHY_ANT_DIV_ALT_GAINTB |
6519 AR_PHY_ANT_DIV_MAIN_GAINTB));
6520 /* by default use LNA1 for the main antenna */
6521 - regval |= (AR_PHY_ANT_DIV_LNA1 <<
6522 + regval |= (ATH_ANT_DIV_COMB_LNA1 <<
6523 AR_PHY_ANT_DIV_MAIN_LNACONF_S);
6524 - regval |= (AR_PHY_ANT_DIV_LNA2 <<
6525 + regval |= (ATH_ANT_DIV_COMB_LNA2 <<
6526 AR_PHY_ANT_DIV_ALT_LNACONF_S);
6527 REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
6528 }
6529 @@ -3813,6 +3825,11 @@ static void ar9003_hw_atten_apply(struct
6530 else
6531 value = ar9003_hw_atten_chain_get_margin(ah, i, chan);
6532
6533 + if (ah->config.alt_mingainidx)
6534 + REG_RMW_FIELD(ah, AR_PHY_EXT_ATTEN_CTL_0,
6535 + AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,
6536 + value);
6537 +
6538 REG_RMW_FIELD(ah, ext_atten_reg[i],
6539 AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,
6540 value);
6541 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
6542 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
6543 @@ -334,6 +334,8 @@ struct ar9300_eeprom {
6544
6545 s32 ar9003_hw_get_tx_gain_idx(struct ath_hw *ah);
6546 s32 ar9003_hw_get_rx_gain_idx(struct ath_hw *ah);
6547 +u32 ar9003_hw_ant_ctrl_common_get(struct ath_hw *ah, bool is2ghz);
6548 +u32 ar9003_hw_ant_ctrl_common_2_get(struct ath_hw *ah, bool is2ghz);
6549
6550 u8 *ar9003_get_spur_chan_ptr(struct ath_hw *ah, bool is_2ghz);
6551
6552 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
6553 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
6554 @@ -148,6 +148,8 @@
6555 #define AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S 28
6556 #define AR_PHY_EXT_CCA_THRESH62 0x007F0000
6557 #define AR_PHY_EXT_CCA_THRESH62_S 16
6558 +#define AR_PHY_EXTCHN_PWRTHR1_ANT_DIV_ALT_ANT_MINGAINIDX 0x0000FF00
6559 +#define AR_PHY_EXTCHN_PWRTHR1_ANT_DIV_ALT_ANT_MINGAINIDX_S 8
6560 #define AR_PHY_EXT_MINCCA_PWR 0x01FF0000
6561 #define AR_PHY_EXT_MINCCA_PWR_S 16
6562 #define AR_PHY_EXT_CYCPWR_THR1 0x0000FE00L
6563 @@ -296,11 +298,6 @@
6564 #define AR_PHY_ANT_DIV_MAIN_GAINTB 0x40000000
6565 #define AR_PHY_ANT_DIV_MAIN_GAINTB_S 30
6566
6567 -#define AR_PHY_ANT_DIV_LNA1_MINUS_LNA2 0x0
6568 -#define AR_PHY_ANT_DIV_LNA2 0x1
6569 -#define AR_PHY_ANT_DIV_LNA1 0x2
6570 -#define AR_PHY_ANT_DIV_LNA1_PLUS_LNA2 0x3
6571 -
6572 #define AR_PHY_EXTCHN_PWRTHR1 (AR_AGC_BASE + 0x2c)
6573 #define AR_PHY_EXT_CHN_WIN (AR_AGC_BASE + 0x30)
6574 #define AR_PHY_20_40_DET_THR (AR_AGC_BASE + 0x34)
6575 --- a/drivers/net/wireless/ath/ath9k/debug.h
6576 +++ b/drivers/net/wireless/ath/ath9k/debug.h
6577 @@ -28,9 +28,13 @@ struct fft_sample_tlv;
6578 #ifdef CPTCFG_ATH9K_DEBUGFS
6579 #define TX_STAT_INC(q, c) sc->debug.stats.txstats[q].c++
6580 #define RESET_STAT_INC(sc, type) sc->debug.stats.reset[type]++
6581 +#define ANT_STAT_INC(i, c) sc->debug.stats.ant_stats[i].c++
6582 +#define ANT_LNA_INC(i, c) sc->debug.stats.ant_stats[i].lna_recv_cnt[c]++;
6583 #else
6584 #define TX_STAT_INC(q, c) do { } while (0)
6585 #define RESET_STAT_INC(sc, type) do { } while (0)
6586 +#define ANT_STAT_INC(i, c) do { } while (0)
6587 +#define ANT_LNA_INC(i, c) do { } while (0)
6588 #endif
6589
6590 enum ath_reset_type {
6591 @@ -243,11 +247,22 @@ struct ath_rx_stats {
6592 u32 rx_spectral;
6593 };
6594
6595 +#define ANT_MAIN 0
6596 +#define ANT_ALT 1
6597 +
6598 +struct ath_antenna_stats {
6599 + u32 recv_cnt;
6600 + u32 rssi_avg;
6601 + u32 lna_recv_cnt[4];
6602 + u32 lna_attempt_cnt[4];
6603 +};
6604 +
6605 struct ath_stats {
6606 struct ath_interrupt_stats istats;
6607 struct ath_tx_stats txstats[ATH9K_NUM_TX_QUEUES];
6608 struct ath_rx_stats rxstats;
6609 struct ath_dfs_stats dfs_stats;
6610 + struct ath_antenna_stats ant_stats[2];
6611 u32 reset[__RESET_TYPE_MAX];
6612 };
6613
6614 @@ -281,10 +296,11 @@ void ath9k_sta_remove_debugfs(struct iee
6615 struct ieee80211_vif *vif,
6616 struct ieee80211_sta *sta,
6617 struct dentry *dir);
6618 -
6619 void ath_debug_send_fft_sample(struct ath_softc *sc,
6620 struct fft_sample_tlv *fft_sample);
6621 -
6622 +void ath9k_debug_stat_ant(struct ath_softc *sc,
6623 + struct ath_hw_antcomb_conf *div_ant_conf,
6624 + int main_rssi_avg, int alt_rssi_avg);
6625 #else
6626
6627 #define RX_STAT_INC(c) /* NOP */
6628 @@ -297,12 +313,10 @@ static inline int ath9k_init_debug(struc
6629 static inline void ath9k_deinit_debug(struct ath_softc *sc)
6630 {
6631 }
6632 -
6633 static inline void ath_debug_stat_interrupt(struct ath_softc *sc,
6634 enum ath9k_int status)
6635 {
6636 }
6637 -
6638 static inline void ath_debug_stat_tx(struct ath_softc *sc,
6639 struct ath_buf *bf,
6640 struct ath_tx_status *ts,
6641 @@ -310,11 +324,16 @@ static inline void ath_debug_stat_tx(str
6642 unsigned int flags)
6643 {
6644 }
6645 -
6646 static inline void ath_debug_stat_rx(struct ath_softc *sc,
6647 struct ath_rx_status *rs)
6648 {
6649 }
6650 +static inline void ath9k_debug_stat_ant(struct ath_softc *sc,
6651 + struct ath_hw_antcomb_conf *div_ant_conf,
6652 + int main_rssi_avg, int alt_rssi_avg)
6653 +{
6654 +
6655 +}
6656
6657 #endif /* CPTCFG_ATH9K_DEBUGFS */
6658
6659 --- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c
6660 +++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
6661 @@ -812,6 +812,7 @@ static void ath9k_hw_4k_set_gain(struct
6662 static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
6663 struct ath9k_channel *chan)
6664 {
6665 + struct ath9k_hw_capabilities *pCap = &ah->caps;
6666 struct modal_eep_4k_header *pModal;
6667 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
6668 struct base_eep_header_4k *pBase = &eep->baseEepHeader;
6669 @@ -858,6 +859,24 @@ static void ath9k_hw_4k_set_board_values
6670
6671 REG_WRITE(ah, AR_PHY_CCK_DETECT, regVal);
6672 regVal = REG_READ(ah, AR_PHY_CCK_DETECT);
6673 +
6674 + if (pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
6675 + /*
6676 + * If diversity combining is enabled,
6677 + * set MAIN to LNA1 and ALT to LNA2 initially.
6678 + */
6679 + regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
6680 + regVal &= (~(AR_PHY_9285_ANT_DIV_MAIN_LNACONF |
6681 + AR_PHY_9285_ANT_DIV_ALT_LNACONF));
6682 +
6683 + regVal |= (ATH_ANT_DIV_COMB_LNA1 <<
6684 + AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S);
6685 + regVal |= (ATH_ANT_DIV_COMB_LNA2 <<
6686 + AR_PHY_9285_ANT_DIV_ALT_LNACONF_S);
6687 + regVal &= (~(AR_PHY_9285_FAST_DIV_BIAS));
6688 + regVal |= (0 << AR_PHY_9285_FAST_DIV_BIAS_S);
6689 + REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal);
6690 + }
6691 }
6692
6693 if (pModal->version >= 2) {
6694 --- a/drivers/net/wireless/ath/ath9k/hw-ops.h
6695 +++ b/drivers/net/wireless/ath/ath9k/hw-ops.h
6696 @@ -78,13 +78,16 @@ static inline void ath9k_hw_antdiv_comb_
6697 ath9k_hw_ops(ah)->antdiv_comb_conf_set(ah, antconf);
6698 }
6699
6700 -static inline void ath9k_hw_antctrl_shared_chain_lnadiv(struct ath_hw *ah,
6701 - bool enable)
6702 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
6703 +
6704 +static inline void ath9k_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable)
6705 {
6706 - if (ath9k_hw_ops(ah)->antctrl_shared_chain_lnadiv)
6707 - ath9k_hw_ops(ah)->antctrl_shared_chain_lnadiv(ah, enable);
6708 + if (ath9k_hw_ops(ah)->set_bt_ant_diversity)
6709 + ath9k_hw_ops(ah)->set_bt_ant_diversity(ah, enable);
6710 }
6711
6712 +#endif
6713 +
6714 /* Private hardware call ops */
6715
6716 /* PHY ops */
6717 --- a/drivers/net/wireless/ath/ath9k/hw.c
6718 +++ b/drivers/net/wireless/ath/ath9k/hw.c
6719 @@ -450,7 +450,6 @@ static void ath9k_hw_init_config(struct
6720 ah->config.ack_6mb = 0x0;
6721 ah->config.cwm_ignore_extcca = 0;
6722 ah->config.pcie_clock_req = 0;
6723 - ah->config.pcie_waen = 0;
6724 ah->config.analog_shiftreg = 1;
6725
6726 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
6727 @@ -1069,7 +1068,7 @@ void ath9k_hw_init_global_settings(struc
6728 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
6729 tx_lat += 11;
6730
6731 - sifstime *= 2;
6732 + sifstime = 32;
6733 ack_offset = 16;
6734 slottime = 13;
6735 } else if (IS_CHAN_QUARTER_RATE(chan)) {
6736 @@ -1079,7 +1078,7 @@ void ath9k_hw_init_global_settings(struc
6737 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
6738 tx_lat += 22;
6739
6740 - sifstime *= 4;
6741 + sifstime = 64;
6742 ack_offset = 32;
6743 slottime = 21;
6744 } else {
6745 @@ -1116,7 +1115,6 @@ void ath9k_hw_init_global_settings(struc
6746 ctstimeout += 48 - sifstime - ah->slottime;
6747 }
6748
6749 -
6750 ath9k_hw_set_sifs_time(ah, sifstime);
6751 ath9k_hw_setslottime(ah, slottime);
6752 ath9k_hw_set_ack_timeout(ah, acktimeout);
6753 @@ -1496,16 +1494,18 @@ static bool ath9k_hw_channel_change(stru
6754 struct ath9k_channel *chan)
6755 {
6756 struct ath_common *common = ath9k_hw_common(ah);
6757 + struct ath9k_hw_capabilities *pCap = &ah->caps;
6758 + bool band_switch = false, mode_diff = false;
6759 + u8 ini_reloaded = 0;
6760 u32 qnum;
6761 int r;
6762 - bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
6763 - bool band_switch, mode_diff;
6764 - u8 ini_reloaded;
6765 -
6766 - band_switch = (chan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ)) !=
6767 - (ah->curchan->channelFlags & (CHANNEL_2GHZ |
6768 - CHANNEL_5GHZ));
6769 - mode_diff = (chan->chanmode != ah->curchan->chanmode);
6770 +
6771 + if (pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) {
6772 + u32 cur = ah->curchan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ);
6773 + u32 new = chan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ);
6774 + band_switch = (cur != new);
6775 + mode_diff = (chan->chanmode != ah->curchan->chanmode);
6776 + }
6777
6778 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
6779 if (ath9k_hw_numtxpending(ah, qnum)) {
6780 @@ -1520,11 +1520,12 @@ static bool ath9k_hw_channel_change(stru
6781 return false;
6782 }
6783
6784 - if (edma && (band_switch || mode_diff)) {
6785 + if (band_switch || mode_diff) {
6786 ath9k_hw_mark_phy_inactive(ah);
6787 udelay(5);
6788
6789 - ath9k_hw_init_pll(ah, NULL);
6790 + if (band_switch)
6791 + ath9k_hw_init_pll(ah, chan);
6792
6793 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
6794 ath_err(common, "Failed to do fast channel change\n");
6795 @@ -1541,22 +1542,21 @@ static bool ath9k_hw_channel_change(stru
6796 }
6797 ath9k_hw_set_clockrate(ah);
6798 ath9k_hw_apply_txpower(ah, chan, false);
6799 - ath9k_hw_rfbus_done(ah);
6800
6801 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
6802 ath9k_hw_set_delta_slope(ah, chan);
6803
6804 ath9k_hw_spur_mitigate_freq(ah, chan);
6805
6806 - if (edma && (band_switch || mode_diff)) {
6807 - ah->ah_flags |= AH_FASTCC;
6808 - if (band_switch || ini_reloaded)
6809 - ah->eep_ops->set_board_values(ah, chan);
6810 + if (band_switch || ini_reloaded)
6811 + ah->eep_ops->set_board_values(ah, chan);
6812
6813 - ath9k_hw_init_bb(ah, chan);
6814 + ath9k_hw_init_bb(ah, chan);
6815 + ath9k_hw_rfbus_done(ah);
6816
6817 - if (band_switch || ini_reloaded)
6818 - ath9k_hw_init_cal(ah, chan);
6819 + if (band_switch || ini_reloaded) {
6820 + ah->ah_flags |= AH_FASTCC;
6821 + ath9k_hw_init_cal(ah, chan);
6822 ah->ah_flags &= ~AH_FASTCC;
6823 }
6824
6825 @@ -1778,16 +1778,11 @@ static void ath9k_hw_init_desc(struct at
6826 /*
6827 * Fast channel change:
6828 * (Change synthesizer based on channel freq without resetting chip)
6829 - *
6830 - * Don't do FCC when
6831 - * - Flag is not set
6832 - * - Chip is just coming out of full sleep
6833 - * - Channel to be set is same as current channel
6834 - * - Channel flags are different, (eg.,moving from 2GHz to 5GHz channel)
6835 */
6836 static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
6837 {
6838 struct ath_common *common = ath9k_hw_common(ah);
6839 + struct ath9k_hw_capabilities *pCap = &ah->caps;
6840 int ret;
6841
6842 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
6843 @@ -1806,9 +1801,21 @@ static int ath9k_hw_do_fastcc(struct ath
6844 (CHANNEL_HALF | CHANNEL_QUARTER))
6845 goto fail;
6846
6847 - if ((chan->channelFlags & CHANNEL_ALL) !=
6848 - (ah->curchan->channelFlags & CHANNEL_ALL))
6849 - goto fail;
6850 + /*
6851 + * If cross-band fcc is not supoprted, bail out if
6852 + * either channelFlags or chanmode differ.
6853 + *
6854 + * chanmode will be different if the HT operating mode
6855 + * changes because of CSA.
6856 + */
6857 + if (!(pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH)) {
6858 + if ((chan->channelFlags & CHANNEL_ALL) !=
6859 + (ah->curchan->channelFlags & CHANNEL_ALL))
6860 + goto fail;
6861 +
6862 + if (chan->chanmode != ah->curchan->chanmode)
6863 + goto fail;
6864 + }
6865
6866 if (!ath9k_hw_check_alive(ah))
6867 goto fail;
6868 @@ -2047,7 +2054,7 @@ int ath9k_hw_reset(struct ath_hw *ah, st
6869
6870 ath9k_hw_apply_gpio_override(ah);
6871
6872 - if (AR_SREV_9565(ah) && ah->shared_chain_lnadiv)
6873 + if (AR_SREV_9565(ah) && common->bt_ant_diversity)
6874 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON);
6875
6876 return 0;
6877 @@ -2550,34 +2557,28 @@ int ath9k_hw_fill_cap_info(struct ath_hw
6878 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
6879 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
6880
6881 - if (AR_SREV_9285(ah))
6882 + if (AR_SREV_9285(ah)) {
6883 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
6884 ant_div_ctl1 =
6885 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
6886 - if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
6887 + if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1)) {
6888 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
6889 + ath_info(common, "Enable LNA combining\n");
6890 + }
6891 }
6892 + }
6893 +
6894 if (AR_SREV_9300_20_OR_LATER(ah)) {
6895 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
6896 pCap->hw_caps |= ATH9K_HW_CAP_APM;
6897 }
6898
6899 -
6900 if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
6901 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
6902 - /*
6903 - * enable the diversity-combining algorithm only when
6904 - * both enable_lna_div and enable_fast_div are set
6905 - * Table for Diversity
6906 - * ant_div_alt_lnaconf bit 0-1
6907 - * ant_div_main_lnaconf bit 2-3
6908 - * ant_div_alt_gaintb bit 4
6909 - * ant_div_main_gaintb bit 5
6910 - * enable_ant_div_lnadiv bit 6
6911 - * enable_ant_fast_div bit 7
6912 - */
6913 - if ((ant_div_ctl1 >> 0x6) == 0x3)
6914 + if ((ant_div_ctl1 >> 0x6) == 0x3) {
6915 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
6916 + ath_info(common, "Enable LNA combining\n");
6917 + }
6918 }
6919
6920 if (ath9k_hw_dfs_tested(ah))
6921 @@ -2610,6 +2611,13 @@ int ath9k_hw_fill_cap_info(struct ath_hw
6922 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
6923 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
6924
6925 + /*
6926 + * Fast channel change across bands is available
6927 + * only for AR9462 and AR9565.
6928 + */
6929 + if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
6930 + pCap->hw_caps |= ATH9K_HW_CAP_FCC_BAND_SWITCH;
6931 +
6932 return 0;
6933 }
6934
6935 --- a/drivers/net/wireless/ath/ath9k/hw.h
6936 +++ b/drivers/net/wireless/ath/ath9k/hw.h
6937 @@ -247,6 +247,8 @@ enum ath9k_hw_caps {
6938 ATH9K_HW_CAP_DFS = BIT(16),
6939 ATH9K_HW_WOW_DEVICE_CAPABLE = BIT(17),
6940 ATH9K_HW_CAP_PAPRD = BIT(18),
6941 + ATH9K_HW_CAP_FCC_BAND_SWITCH = BIT(19),
6942 + ATH9K_HW_CAP_BT_ANT_DIV = BIT(20),
6943 };
6944
6945 /*
6946 @@ -309,8 +311,11 @@ struct ath9k_ops_config {
6947 u16 ani_poll_interval; /* ANI poll interval in ms */
6948
6949 /* Platform specific config */
6950 + u32 aspm_l1_fix;
6951 u32 xlna_gpio;
6952 + u32 ant_ctrl_comm2g_switch_enable;
6953 bool xatten_margin_cfg;
6954 + bool alt_mingainidx;
6955 };
6956
6957 enum ath9k_int {
6958 @@ -716,11 +721,14 @@ struct ath_hw_ops {
6959 struct ath_hw_antcomb_conf *antconf);
6960 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
6961 struct ath_hw_antcomb_conf *antconf);
6962 - void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
6963 void (*spectral_scan_config)(struct ath_hw *ah,
6964 struct ath_spec_scan *param);
6965 void (*spectral_scan_trigger)(struct ath_hw *ah);
6966 void (*spectral_scan_wait)(struct ath_hw *ah);
6967 +
6968 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
6969 + void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
6970 +#endif
6971 };
6972
6973 struct ath_nf_limits {
6974 @@ -765,7 +773,6 @@ struct ath_hw {
6975 bool aspm_enabled;
6976 bool is_monitoring;
6977 bool need_an_top2_fixup;
6978 - bool shared_chain_lnadiv;
6979 u16 tx_trig_level;
6980
6981 u32 nf_regs[6];
6982 --- a/drivers/net/wireless/ath/ath9k/pci.c
6983 +++ b/drivers/net/wireless/ath/ath9k/pci.c
6984 @@ -29,6 +29,60 @@ static DEFINE_PCI_DEVICE_TABLE(ath_pci_i
6985 { PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI */
6986 { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */
6987 { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
6988 +
6989 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
6990 + 0x002A,
6991 + PCI_VENDOR_ID_AZWAVE,
6992 + 0x1C71),
6993 + .driver_data = ATH9K_PCI_D3_L1_WAR },
6994 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
6995 + 0x002A,
6996 + PCI_VENDOR_ID_FOXCONN,
6997 + 0xE01F),
6998 + .driver_data = ATH9K_PCI_D3_L1_WAR },
6999 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7000 + 0x002A,
7001 + 0x11AD, /* LITEON */
7002 + 0x6632),
7003 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7004 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7005 + 0x002A,
7006 + 0x11AD, /* LITEON */
7007 + 0x6642),
7008 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7009 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7010 + 0x002A,
7011 + PCI_VENDOR_ID_QMI,
7012 + 0x0306),
7013 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7014 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7015 + 0x002A,
7016 + 0x185F, /* WNC */
7017 + 0x309D),
7018 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7019 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7020 + 0x002A,
7021 + 0x10CF, /* Fujitsu */
7022 + 0x147C),
7023 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7024 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7025 + 0x002A,
7026 + 0x10CF, /* Fujitsu */
7027 + 0x147D),
7028 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7029 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7030 + 0x002A,
7031 + 0x10CF, /* Fujitsu */
7032 + 0x1536),
7033 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7034 +
7035 + /* AR9285 card for Asus */
7036 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7037 + 0x002B,
7038 + PCI_VENDOR_ID_AZWAVE,
7039 + 0x2C37),
7040 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7041 +
7042 { PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */
7043 { PCI_VDEVICE(ATHEROS, 0x002C) }, /* PCI-E 802.11n bonded out */
7044 { PCI_VDEVICE(ATHEROS, 0x002D) }, /* PCI */
7045 @@ -40,29 +94,106 @@ static DEFINE_PCI_DEVICE_TABLE(ath_pci_i
7046 0x0032,
7047 PCI_VENDOR_ID_AZWAVE,
7048 0x2086),
7049 - .driver_data = ATH9K_PCI_CUS198 },
7050 + .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
7051 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7052 0x0032,
7053 PCI_VENDOR_ID_AZWAVE,
7054 0x1237),
7055 - .driver_data = ATH9K_PCI_CUS198 },
7056 + .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
7057 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7058 0x0032,
7059 PCI_VENDOR_ID_AZWAVE,
7060 0x2126),
7061 - .driver_data = ATH9K_PCI_CUS198 },
7062 + .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
7063 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7064 + 0x0032,
7065 + PCI_VENDOR_ID_AZWAVE,
7066 + 0x126A),
7067 + .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
7068
7069 /* PCI-E CUS230 */
7070 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7071 0x0032,
7072 PCI_VENDOR_ID_AZWAVE,
7073 0x2152),
7074 - .driver_data = ATH9K_PCI_CUS230 },
7075 + .driver_data = ATH9K_PCI_CUS230 | ATH9K_PCI_BT_ANT_DIV },
7076 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7077 0x0032,
7078 PCI_VENDOR_ID_FOXCONN,
7079 0xE075),
7080 - .driver_data = ATH9K_PCI_CUS230 },
7081 + .driver_data = ATH9K_PCI_CUS230 | ATH9K_PCI_BT_ANT_DIV },
7082 +
7083 + /* WB225 */
7084 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7085 + 0x0032,
7086 + PCI_VENDOR_ID_ATHEROS,
7087 + 0x3119),
7088 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7089 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7090 + 0x0032,
7091 + PCI_VENDOR_ID_ATHEROS,
7092 + 0x3122),
7093 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7094 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7095 + 0x0032,
7096 + 0x185F, /* WNC */
7097 + 0x3119),
7098 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7099 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7100 + 0x0032,
7101 + 0x185F, /* WNC */
7102 + 0x3027),
7103 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7104 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7105 + 0x0032,
7106 + PCI_VENDOR_ID_SAMSUNG,
7107 + 0x4105),
7108 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7109 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7110 + 0x0032,
7111 + PCI_VENDOR_ID_SAMSUNG,
7112 + 0x4106),
7113 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7114 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7115 + 0x0032,
7116 + PCI_VENDOR_ID_SAMSUNG,
7117 + 0x410D),
7118 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7119 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7120 + 0x0032,
7121 + PCI_VENDOR_ID_SAMSUNG,
7122 + 0x410E),
7123 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7124 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7125 + 0x0032,
7126 + PCI_VENDOR_ID_SAMSUNG,
7127 + 0x410F),
7128 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7129 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7130 + 0x0032,
7131 + PCI_VENDOR_ID_SAMSUNG,
7132 + 0xC706),
7133 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7134 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7135 + 0x0032,
7136 + PCI_VENDOR_ID_SAMSUNG,
7137 + 0xC680),
7138 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7139 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7140 + 0x0032,
7141 + PCI_VENDOR_ID_SAMSUNG,
7142 + 0xC708),
7143 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7144 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7145 + 0x0032,
7146 + PCI_VENDOR_ID_LENOVO,
7147 + 0x3218),
7148 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7149 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7150 + 0x0032,
7151 + PCI_VENDOR_ID_LENOVO,
7152 + 0x3219),
7153 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7154
7155 { PCI_VDEVICE(ATHEROS, 0x0032) }, /* PCI-E AR9485 */
7156 { PCI_VDEVICE(ATHEROS, 0x0033) }, /* PCI-E AR9580 */
7157 @@ -229,6 +360,22 @@ static void ath_pci_aspm_init(struct ath
7158 return;
7159 }
7160
7161 + /*
7162 + * 0x70c - Ack Frequency Register.
7163 + *
7164 + * Bits 27:29 - DEFAULT_L1_ENTRANCE_LATENCY.
7165 + *
7166 + * 000 : 1 us
7167 + * 001 : 2 us
7168 + * 010 : 4 us
7169 + * 011 : 8 us
7170 + * 100 : 16 us
7171 + * 101 : 32 us
7172 + * 110/111 : 64 us
7173 + */
7174 + if (AR_SREV_9462(ah))
7175 + pci_read_config_dword(pdev, 0x70c, &ah->config.aspm_l1_fix);
7176 +
7177 pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &aspm);
7178 if (aspm & (PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1)) {
7179 ah->aspm_enabled = true;
7180 --- a/drivers/net/wireless/ath/ath9k/phy.h
7181 +++ b/drivers/net/wireless/ath/ath9k/phy.h
7182 @@ -48,4 +48,11 @@
7183 #define AR_PHY_PLL_CONTROL 0x16180
7184 #define AR_PHY_PLL_MODE 0x16184
7185
7186 +enum ath9k_ant_div_comb_lna_conf {
7187 + ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2,
7188 + ATH_ANT_DIV_COMB_LNA2,
7189 + ATH_ANT_DIV_COMB_LNA1,
7190 + ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2,
7191 +};
7192 +
7193 #endif
7194 --- a/drivers/net/wireless/iwlwifi/mvm/time-event.c
7195 +++ b/drivers/net/wireless/iwlwifi/mvm/time-event.c
7196 @@ -73,7 +73,6 @@
7197 #include "iwl-prph.h"
7198
7199 /* A TimeUnit is 1024 microsecond */
7200 -#define TU_TO_JIFFIES(_tu) (usecs_to_jiffies((_tu) * 1024))
7201 #define MSEC_TO_TU(_msec) (_msec*1000/1024)
7202
7203 /*
7204 @@ -191,8 +190,7 @@ static void iwl_mvm_te_handle_notif(stru
7205 iwl_mvm_te_clear_data(mvm, te_data);
7206 } else if (le32_to_cpu(notif->action) & TE_NOTIF_HOST_EVENT_START) {
7207 te_data->running = true;
7208 - te_data->end_jiffies = jiffies +
7209 - TU_TO_JIFFIES(te_data->duration);
7210 + te_data->end_jiffies = TU_TO_EXP_TIME(te_data->duration);
7211
7212 if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
7213 set_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
7214 @@ -329,8 +327,7 @@ void iwl_mvm_protect_session(struct iwl_
7215 lockdep_assert_held(&mvm->mutex);
7216
7217 if (te_data->running &&
7218 - time_after(te_data->end_jiffies,
7219 - jiffies + TU_TO_JIFFIES(min_duration))) {
7220 + time_after(te_data->end_jiffies, TU_TO_EXP_TIME(min_duration))) {
7221 IWL_DEBUG_TE(mvm, "We have enough time in the current TE: %u\n",
7222 jiffies_to_msecs(te_data->end_jiffies - jiffies));
7223 return;
7224 --- a/include/linux/ieee80211.h
7225 +++ b/include/linux/ieee80211.h
7226 @@ -2279,4 +2279,8 @@ static inline bool ieee80211_check_tim(c
7227 return !!(tim->virtual_map[index] & mask);
7228 }
7229
7230 +/* convert time units */
7231 +#define TU_TO_JIFFIES(x) (usecs_to_jiffies((x) * 1024))
7232 +#define TU_TO_EXP_TIME(x) (jiffies + TU_TO_JIFFIES(x))
7233 +
7234 #endif /* LINUX_IEEE80211_H */
7235 --- a/net/mac80211/rate.c
7236 +++ b/net/mac80211/rate.c
7237 @@ -210,7 +210,7 @@ static bool rc_no_data_or_no_ack_use_min
7238 !ieee80211_is_data(fc);
7239 }
7240
7241 -static void rc_send_low_broadcast(s8 *idx, u32 basic_rates,
7242 +static void rc_send_low_basicrate(s8 *idx, u32 basic_rates,
7243 struct ieee80211_supported_band *sband)
7244 {
7245 u8 i;
7246 @@ -272,28 +272,37 @@ static void __rate_control_send_low(stru
7247 }
7248
7249
7250 -bool rate_control_send_low(struct ieee80211_sta *sta,
7251 +bool rate_control_send_low(struct ieee80211_sta *pubsta,
7252 void *priv_sta,
7253 struct ieee80211_tx_rate_control *txrc)
7254 {
7255 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
7256 struct ieee80211_supported_band *sband = txrc->sband;
7257 + struct sta_info *sta;
7258 int mcast_rate;
7259 + bool use_basicrate = false;
7260
7261 - if (!sta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) {
7262 - __rate_control_send_low(txrc->hw, sband, sta, info);
7263 + if (!pubsta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) {
7264 + __rate_control_send_low(txrc->hw, sband, pubsta, info);
7265
7266 - if (!sta && txrc->bss) {
7267 + if (!pubsta && txrc->bss) {
7268 mcast_rate = txrc->bss_conf->mcast_rate[sband->band];
7269 if (mcast_rate > 0) {
7270 info->control.rates[0].idx = mcast_rate - 1;
7271 return true;
7272 }
7273 + use_basicrate = true;
7274 + } else if (pubsta) {
7275 + sta = container_of(pubsta, struct sta_info, sta);
7276 + if (ieee80211_vif_is_mesh(&sta->sdata->vif))
7277 + use_basicrate = true;
7278 + }
7279
7280 - rc_send_low_broadcast(&info->control.rates[0].idx,
7281 + if (use_basicrate)
7282 + rc_send_low_basicrate(&info->control.rates[0].idx,
7283 txrc->bss_conf->basic_rates,
7284 sband);
7285 - }
7286 +
7287 return true;
7288 }
7289 return false;
7290 --- a/drivers/net/wireless/ath/ath9k/Kconfig
7291 +++ b/drivers/net/wireless/ath/ath9k/Kconfig
7292 @@ -60,7 +60,7 @@ config ATH9K_AHB
7293
7294 config ATH9K_DEBUGFS
7295 bool "Atheros ath9k debugging"
7296 - depends on ATH9K
7297 + depends on ATH9K && DEBUG_FS
7298 select MAC80211_DEBUGFS
7299 depends on RELAY
7300 ---help---
7301 --- a/drivers/net/wireless/ath/ath9k/ar9002_hw.c
7302 +++ b/drivers/net/wireless/ath/ath9k/ar9002_hw.c
7303 @@ -269,13 +269,12 @@ static void ar9002_hw_configpcipowersave
7304 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
7305 val |= AR_WA_D3_L1_DISABLE;
7306 } else {
7307 - if (((AR_SREV_9285(ah) ||
7308 - AR_SREV_9271(ah) ||
7309 - AR_SREV_9287(ah)) &&
7310 - (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
7311 - (AR_SREV_9280(ah) &&
7312 - (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
7313 - val |= AR_WA_D3_L1_DISABLE;
7314 + if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) {
7315 + if (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)
7316 + val |= AR_WA_D3_L1_DISABLE;
7317 + } else if (AR_SREV_9280(ah)) {
7318 + if (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE)
7319 + val |= AR_WA_D3_L1_DISABLE;
7320 }
7321 }
7322
7323 @@ -297,24 +296,18 @@ static void ar9002_hw_configpcipowersave
7324 } else {
7325 if (ah->config.pcie_waen) {
7326 val = ah->config.pcie_waen;
7327 - if (!power_off)
7328 - val &= (~AR_WA_D3_L1_DISABLE);
7329 + val &= (~AR_WA_D3_L1_DISABLE);
7330 } else {
7331 - if (AR_SREV_9285(ah) ||
7332 - AR_SREV_9271(ah) ||
7333 - AR_SREV_9287(ah)) {
7334 + if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) {
7335 val = AR9285_WA_DEFAULT;
7336 - if (!power_off)
7337 - val &= (~AR_WA_D3_L1_DISABLE);
7338 - }
7339 - else if (AR_SREV_9280(ah)) {
7340 + val &= (~AR_WA_D3_L1_DISABLE);
7341 + } else if (AR_SREV_9280(ah)) {
7342 /*
7343 * For AR9280 chips, bit 22 of 0x4004
7344 * needs to be set.
7345 */
7346 val = AR9280_WA_DEFAULT;
7347 - if (!power_off)
7348 - val &= (~AR_WA_D3_L1_DISABLE);
7349 + val &= (~AR_WA_D3_L1_DISABLE);
7350 } else {
7351 val = AR_WA_DEFAULT;
7352 }
7353 --- a/drivers/net/wireless/ath/ath9k/ar9003_hw.c
7354 +++ b/drivers/net/wireless/ath/ath9k/ar9003_hw.c
7355 @@ -153,7 +153,7 @@ static void ar9003_hw_init_mode_regs(str
7356 if (!ah->is_clk_25mhz)
7357 INIT_INI_ARRAY(&ah->iniAdditional,
7358 ar9340_1p0_radio_core_40M);
7359 - } else if (AR_SREV_9485_11(ah)) {
7360 + } else if (AR_SREV_9485_11_OR_LATER(ah)) {
7361 /* mac */
7362 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
7363 ar9485_1_1_mac_core);
7364 @@ -424,7 +424,7 @@ static void ar9003_tx_gain_table_mode0(s
7365 else if (AR_SREV_9340(ah))
7366 INIT_INI_ARRAY(&ah->iniModesTxGain,
7367 ar9340Modes_lowest_ob_db_tx_gain_table_1p0);
7368 - else if (AR_SREV_9485_11(ah))
7369 + else if (AR_SREV_9485_11_OR_LATER(ah))
7370 INIT_INI_ARRAY(&ah->iniModesTxGain,
7371 ar9485_modes_lowest_ob_db_tx_gain_1_1);
7372 else if (AR_SREV_9550(ah))
7373 @@ -458,7 +458,7 @@ static void ar9003_tx_gain_table_mode1(s
7374 else if (AR_SREV_9340(ah))
7375 INIT_INI_ARRAY(&ah->iniModesTxGain,
7376 ar9340Modes_high_ob_db_tx_gain_table_1p0);
7377 - else if (AR_SREV_9485_11(ah))
7378 + else if (AR_SREV_9485_11_OR_LATER(ah))
7379 INIT_INI_ARRAY(&ah->iniModesTxGain,
7380 ar9485Modes_high_ob_db_tx_gain_1_1);
7381 else if (AR_SREV_9580(ah))
7382 @@ -492,7 +492,7 @@ static void ar9003_tx_gain_table_mode2(s
7383 else if (AR_SREV_9340(ah))
7384 INIT_INI_ARRAY(&ah->iniModesTxGain,
7385 ar9340Modes_low_ob_db_tx_gain_table_1p0);
7386 - else if (AR_SREV_9485_11(ah))
7387 + else if (AR_SREV_9485_11_OR_LATER(ah))
7388 INIT_INI_ARRAY(&ah->iniModesTxGain,
7389 ar9485Modes_low_ob_db_tx_gain_1_1);
7390 else if (AR_SREV_9580(ah))
7391 @@ -517,7 +517,7 @@ static void ar9003_tx_gain_table_mode3(s
7392 else if (AR_SREV_9340(ah))
7393 INIT_INI_ARRAY(&ah->iniModesTxGain,
7394 ar9340Modes_high_power_tx_gain_table_1p0);
7395 - else if (AR_SREV_9485_11(ah))
7396 + else if (AR_SREV_9485_11_OR_LATER(ah))
7397 INIT_INI_ARRAY(&ah->iniModesTxGain,
7398 ar9485Modes_high_power_tx_gain_1_1);
7399 else if (AR_SREV_9580(ah))
7400 @@ -552,7 +552,7 @@ static void ar9003_tx_gain_table_mode4(s
7401
7402 static void ar9003_tx_gain_table_mode5(struct ath_hw *ah)
7403 {
7404 - if (AR_SREV_9485_11(ah))
7405 + if (AR_SREV_9485_11_OR_LATER(ah))
7406 INIT_INI_ARRAY(&ah->iniModesTxGain,
7407 ar9485Modes_green_ob_db_tx_gain_1_1);
7408 else if (AR_SREV_9340(ah))
7409 @@ -571,7 +571,7 @@ static void ar9003_tx_gain_table_mode6(s
7410 if (AR_SREV_9340(ah))
7411 INIT_INI_ARRAY(&ah->iniModesTxGain,
7412 ar9340Modes_low_ob_db_and_spur_tx_gain_table_1p0);
7413 - else if (AR_SREV_9485_11(ah))
7414 + else if (AR_SREV_9485_11_OR_LATER(ah))
7415 INIT_INI_ARRAY(&ah->iniModesTxGain,
7416 ar9485Modes_green_spur_ob_db_tx_gain_1_1);
7417 else if (AR_SREV_9580(ah))
7418 @@ -611,7 +611,7 @@ static void ar9003_rx_gain_table_mode0(s
7419 else if (AR_SREV_9340(ah))
7420 INIT_INI_ARRAY(&ah->iniModesRxGain,
7421 ar9340Common_rx_gain_table_1p0);
7422 - else if (AR_SREV_9485_11(ah))
7423 + else if (AR_SREV_9485_11_OR_LATER(ah))
7424 INIT_INI_ARRAY(&ah->iniModesRxGain,
7425 ar9485_common_rx_gain_1_1);
7426 else if (AR_SREV_9550(ah)) {
7427 @@ -644,7 +644,7 @@ static void ar9003_rx_gain_table_mode1(s
7428 else if (AR_SREV_9340(ah))
7429 INIT_INI_ARRAY(&ah->iniModesRxGain,
7430 ar9340Common_wo_xlna_rx_gain_table_1p0);
7431 - else if (AR_SREV_9485_11(ah))
7432 + else if (AR_SREV_9485_11_OR_LATER(ah))
7433 INIT_INI_ARRAY(&ah->iniModesRxGain,
7434 ar9485Common_wo_xlna_rx_gain_1_1);
7435 else if (AR_SREV_9462_21(ah))
7436 @@ -745,16 +745,25 @@ static void ar9003_hw_init_mode_gain_reg
7437 static void ar9003_hw_configpcipowersave(struct ath_hw *ah,
7438 bool power_off)
7439 {
7440 + /*
7441 + * Increase L1 Entry Latency. Some WB222 boards don't have
7442 + * this change in eeprom/OTP.
7443 + *
7444 + */
7445 + if (AR_SREV_9462(ah)) {
7446 + u32 val = ah->config.aspm_l1_fix;
7447 + if ((val & 0xff000000) == 0x17000000) {
7448 + val &= 0x00ffffff;
7449 + val |= 0x27000000;
7450 + REG_WRITE(ah, 0x570c, val);
7451 + }
7452 + }
7453 +
7454 /* Nothing to do on restore for 11N */
7455 if (!power_off /* !restore */) {
7456 /* set bit 19 to allow forcing of pcie core into L1 state */
7457 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
7458 -
7459 - /* Several PCIe massages to ensure proper behaviour */
7460 - if (ah->config.pcie_waen)
7461 - REG_WRITE(ah, AR_WA, ah->config.pcie_waen);
7462 - else
7463 - REG_WRITE(ah, AR_WA, ah->WARegVal);
7464 + REG_WRITE(ah, AR_WA, ah->WARegVal);
7465 }
7466
7467 /*
7468 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
7469 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
7470 @@ -491,6 +491,7 @@ int ath9k_hw_process_rxdesc_edma(struct
7471 rxs->rs_rate = MS(rxsp->status1, AR_RxRate);
7472 rxs->rs_more = (rxsp->status2 & AR_RxMore) ? 1 : 0;
7473
7474 + rxs->rs_firstaggr = (rxsp->status11 & AR_RxFirstAggr) ? 1 : 0;
7475 rxs->rs_isaggr = (rxsp->status11 & AR_RxAggr) ? 1 : 0;
7476 rxs->rs_moreaggr = (rxsp->status11 & AR_RxMoreAggr) ? 1 : 0;
7477 rxs->rs_antenna = (MS(rxsp->status4, AR_RxAntenna) & 0x7);
7478 --- a/drivers/net/wireless/ath/ath9k/common.c
7479 +++ b/drivers/net/wireless/ath/ath9k/common.c
7480 @@ -49,37 +49,40 @@ int ath9k_cmn_get_hw_crypto_keytype(stru
7481 }
7482 EXPORT_SYMBOL(ath9k_cmn_get_hw_crypto_keytype);
7483
7484 -static u32 ath9k_get_extchanmode(struct ieee80211_channel *chan,
7485 - enum nl80211_channel_type channel_type)
7486 +static u32 ath9k_get_extchanmode(struct cfg80211_chan_def *chandef)
7487 {
7488 u32 chanmode = 0;
7489
7490 - switch (chan->band) {
7491 + switch (chandef->chan->band) {
7492 case IEEE80211_BAND_2GHZ:
7493 - switch (channel_type) {
7494 - case NL80211_CHAN_NO_HT:
7495 - case NL80211_CHAN_HT20:
7496 + switch (chandef->width) {
7497 + case NL80211_CHAN_WIDTH_20_NOHT:
7498 + case NL80211_CHAN_WIDTH_20:
7499 chanmode = CHANNEL_G_HT20;
7500 break;
7501 - case NL80211_CHAN_HT40PLUS:
7502 - chanmode = CHANNEL_G_HT40PLUS;
7503 + case NL80211_CHAN_WIDTH_40:
7504 + if (chandef->center_freq1 > chandef->chan->center_freq)
7505 + chanmode = CHANNEL_G_HT40PLUS;
7506 + else
7507 + chanmode = CHANNEL_G_HT40MINUS;
7508 break;
7509 - case NL80211_CHAN_HT40MINUS:
7510 - chanmode = CHANNEL_G_HT40MINUS;
7511 + default:
7512 break;
7513 }
7514 break;
7515 case IEEE80211_BAND_5GHZ:
7516 - switch (channel_type) {
7517 - case NL80211_CHAN_NO_HT:
7518 - case NL80211_CHAN_HT20:
7519 + switch (chandef->width) {
7520 + case NL80211_CHAN_WIDTH_20_NOHT:
7521 + case NL80211_CHAN_WIDTH_20:
7522 chanmode = CHANNEL_A_HT20;
7523 break;
7524 - case NL80211_CHAN_HT40PLUS:
7525 - chanmode = CHANNEL_A_HT40PLUS;
7526 + case NL80211_CHAN_WIDTH_40:
7527 + if (chandef->center_freq1 > chandef->chan->center_freq)
7528 + chanmode = CHANNEL_A_HT40PLUS;
7529 + else
7530 + chanmode = CHANNEL_A_HT40MINUS;
7531 break;
7532 - case NL80211_CHAN_HT40MINUS:
7533 - chanmode = CHANNEL_A_HT40MINUS;
7534 + default:
7535 break;
7536 }
7537 break;
7538 @@ -94,13 +97,12 @@ static u32 ath9k_get_extchanmode(struct
7539 * Update internal channel flags.
7540 */
7541 void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan,
7542 - struct ieee80211_channel *chan,
7543 - enum nl80211_channel_type channel_type)
7544 + struct cfg80211_chan_def *chandef)
7545 {
7546 - ichan->channel = chan->center_freq;
7547 - ichan->chan = chan;
7548 + ichan->channel = chandef->chan->center_freq;
7549 + ichan->chan = chandef->chan;
7550
7551 - if (chan->band == IEEE80211_BAND_2GHZ) {
7552 + if (chandef->chan->band == IEEE80211_BAND_2GHZ) {
7553 ichan->chanmode = CHANNEL_G;
7554 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM;
7555 } else {
7556 @@ -108,8 +110,22 @@ void ath9k_cmn_update_ichannel(struct at
7557 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
7558 }
7559
7560 - if (channel_type != NL80211_CHAN_NO_HT)
7561 - ichan->chanmode = ath9k_get_extchanmode(chan, channel_type);
7562 + switch (chandef->width) {
7563 + case NL80211_CHAN_WIDTH_5:
7564 + ichan->channelFlags |= CHANNEL_QUARTER;
7565 + break;
7566 + case NL80211_CHAN_WIDTH_10:
7567 + ichan->channelFlags |= CHANNEL_HALF;
7568 + break;
7569 + case NL80211_CHAN_WIDTH_20_NOHT:
7570 + break;
7571 + case NL80211_CHAN_WIDTH_20:
7572 + case NL80211_CHAN_WIDTH_40:
7573 + ichan->chanmode = ath9k_get_extchanmode(chandef);
7574 + break;
7575 + default:
7576 + WARN_ON(1);
7577 + }
7578 }
7579 EXPORT_SYMBOL(ath9k_cmn_update_ichannel);
7580
7581 @@ -125,8 +141,7 @@ struct ath9k_channel *ath9k_cmn_get_curc
7582
7583 chan_idx = curchan->hw_value;
7584 channel = &ah->channels[chan_idx];
7585 - ath9k_cmn_update_ichannel(channel, curchan,
7586 - cfg80211_get_chandef_type(&hw->conf.chandef));
7587 + ath9k_cmn_update_ichannel(channel, &hw->conf.chandef);
7588
7589 return channel;
7590 }
7591 --- a/drivers/net/wireless/ath/ath9k/common.h
7592 +++ b/drivers/net/wireless/ath/ath9k/common.h
7593 @@ -44,8 +44,7 @@
7594
7595 int ath9k_cmn_get_hw_crypto_keytype(struct sk_buff *skb);
7596 void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan,
7597 - struct ieee80211_channel *chan,
7598 - enum nl80211_channel_type channel_type);
7599 + struct cfg80211_chan_def *chandef);
7600 struct ath9k_channel *ath9k_cmn_get_curchannel(struct ieee80211_hw *hw,
7601 struct ath_hw *ah);
7602 int ath9k_cmn_count_streams(unsigned int chainmask, int max);
7603 --- a/drivers/net/wireless/ath/ath9k/hif_usb.c
7604 +++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
7605 @@ -115,10 +115,10 @@ static int hif_usb_send_regout(struct hi
7606 cmd->skb = skb;
7607 cmd->hif_dev = hif_dev;
7608
7609 - usb_fill_bulk_urb(urb, hif_dev->udev,
7610 - usb_sndbulkpipe(hif_dev->udev, USB_REG_OUT_PIPE),
7611 + usb_fill_int_urb(urb, hif_dev->udev,
7612 + usb_sndintpipe(hif_dev->udev, USB_REG_OUT_PIPE),
7613 skb->data, skb->len,
7614 - hif_usb_regout_cb, cmd);
7615 + hif_usb_regout_cb, cmd, 1);
7616
7617 usb_anchor_urb(urb, &hif_dev->regout_submitted);
7618 ret = usb_submit_urb(urb, GFP_KERNEL);
7619 @@ -723,11 +723,11 @@ static void ath9k_hif_usb_reg_in_cb(stru
7620 return;
7621 }
7622
7623 - usb_fill_bulk_urb(urb, hif_dev->udev,
7624 - usb_rcvbulkpipe(hif_dev->udev,
7625 + usb_fill_int_urb(urb, hif_dev->udev,
7626 + usb_rcvintpipe(hif_dev->udev,
7627 USB_REG_IN_PIPE),
7628 nskb->data, MAX_REG_IN_BUF_SIZE,
7629 - ath9k_hif_usb_reg_in_cb, nskb);
7630 + ath9k_hif_usb_reg_in_cb, nskb, 1);
7631 }
7632
7633 resubmit:
7634 @@ -909,11 +909,11 @@ static int ath9k_hif_usb_alloc_reg_in_ur
7635 goto err_skb;
7636 }
7637
7638 - usb_fill_bulk_urb(urb, hif_dev->udev,
7639 - usb_rcvbulkpipe(hif_dev->udev,
7640 + usb_fill_int_urb(urb, hif_dev->udev,
7641 + usb_rcvintpipe(hif_dev->udev,
7642 USB_REG_IN_PIPE),
7643 skb->data, MAX_REG_IN_BUF_SIZE,
7644 - ath9k_hif_usb_reg_in_cb, skb);
7645 + ath9k_hif_usb_reg_in_cb, skb, 1);
7646
7647 /* Anchor URB */
7648 usb_anchor_urb(urb, &hif_dev->reg_in_submitted);
7649 @@ -1031,9 +1031,7 @@ static int ath9k_hif_usb_download_fw(str
7650
7651 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev)
7652 {
7653 - struct usb_host_interface *alt = &hif_dev->interface->altsetting[0];
7654 - struct usb_endpoint_descriptor *endp;
7655 - int ret, idx;
7656 + int ret;
7657
7658 ret = ath9k_hif_usb_download_fw(hif_dev);
7659 if (ret) {
7660 @@ -1043,20 +1041,6 @@ static int ath9k_hif_usb_dev_init(struct
7661 return ret;
7662 }
7663
7664 - /* On downloading the firmware to the target, the USB descriptor of EP4
7665 - * is 'patched' to change the type of the endpoint to Bulk. This will
7666 - * bring down CPU usage during the scan period.
7667 - */
7668 - for (idx = 0; idx < alt->desc.bNumEndpoints; idx++) {
7669 - endp = &alt->endpoint[idx].desc;
7670 - if ((endp->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
7671 - == USB_ENDPOINT_XFER_INT) {
7672 - endp->bmAttributes &= ~USB_ENDPOINT_XFERTYPE_MASK;
7673 - endp->bmAttributes |= USB_ENDPOINT_XFER_BULK;
7674 - endp->bInterval = 0;
7675 - }
7676 - }
7677 -
7678 /* Alloc URBs */
7679 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
7680 if (ret) {
7681 @@ -1268,7 +1252,7 @@ static void ath9k_hif_usb_reboot(struct
7682 if (!buf)
7683 return;
7684
7685 - ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, USB_REG_OUT_PIPE),
7686 + ret = usb_interrupt_msg(udev, usb_sndintpipe(udev, USB_REG_OUT_PIPE),
7687 buf, 4, NULL, HZ);
7688 if (ret)
7689 dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n");
7690 --- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
7691 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
7692 @@ -1203,16 +1203,13 @@ static int ath9k_htc_config(struct ieee8
7693
7694 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || chip_reset) {
7695 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
7696 - enum nl80211_channel_type channel_type =
7697 - cfg80211_get_chandef_type(&hw->conf.chandef);
7698 int pos = curchan->hw_value;
7699
7700 ath_dbg(common, CONFIG, "Set channel: %d MHz\n",
7701 curchan->center_freq);
7702
7703 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
7704 - hw->conf.chandef.chan,
7705 - channel_type);
7706 + &hw->conf.chandef);
7707
7708 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
7709 ath_err(common, "Unable to set channel\n");
7710 --- a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
7711 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
7712 @@ -448,6 +448,7 @@ static void ath9k_htc_tx_process(struct
7713 struct ieee80211_conf *cur_conf = &priv->hw->conf;
7714 bool txok;
7715 int slot;
7716 + int hdrlen, padsize;
7717
7718 slot = strip_drv_header(priv, skb);
7719 if (slot < 0) {
7720 @@ -504,6 +505,15 @@ send_mac80211:
7721
7722 ath9k_htc_tx_clear_slot(priv, slot);
7723
7724 + /* Remove padding before handing frame back to mac80211 */
7725 + hdrlen = ieee80211_get_hdrlen_from_skb(skb);
7726 +
7727 + padsize = hdrlen & 3;
7728 + if (padsize && skb->len > hdrlen + padsize) {
7729 + memmove(skb->data + padsize, skb->data, hdrlen);
7730 + skb_pull(skb, padsize);
7731 + }
7732 +
7733 /* Send status to mac80211 */
7734 ieee80211_tx_status(priv->hw, skb);
7735 }
7736 --- a/drivers/net/wireless/ath/ath9k/link.c
7737 +++ b/drivers/net/wireless/ath/ath9k/link.c
7738 @@ -41,7 +41,7 @@ void ath_tx_complete_poll_work(struct wo
7739 txq->axq_tx_inprogress = true;
7740 }
7741 }
7742 - ath_txq_unlock_complete(sc, txq);
7743 + ath_txq_unlock(sc, txq);
7744 }
7745
7746 if (needreset) {
7747 --- a/drivers/net/wireless/ath/ath9k/mac.c
7748 +++ b/drivers/net/wireless/ath/ath9k/mac.c
7749 @@ -583,9 +583,9 @@ int ath9k_hw_rxprocdesc(struct ath_hw *a
7750 rs->rs_rate = MS(ads.ds_rxstatus0, AR_RxRate);
7751 rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
7752
7753 + rs->rs_firstaggr = (ads.ds_rxstatus8 & AR_RxFirstAggr) ? 1 : 0;
7754 rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
7755 - rs->rs_moreaggr =
7756 - (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
7757 + rs->rs_moreaggr = (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
7758 rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
7759
7760 /* directly mapped flags for ieee80211_rx_status */
7761 --- a/drivers/net/wireless/ath/ath9k/mac.h
7762 +++ b/drivers/net/wireless/ath/ath9k/mac.h
7763 @@ -140,6 +140,7 @@ struct ath_rx_status {
7764 int8_t rs_rssi_ext1;
7765 int8_t rs_rssi_ext2;
7766 u8 rs_isaggr;
7767 + u8 rs_firstaggr;
7768 u8 rs_moreaggr;
7769 u8 rs_num_delims;
7770 u8 rs_flags;
7771 @@ -569,6 +570,7 @@ struct ar5416_desc {
7772 #define AR_RxAggr 0x00020000
7773 #define AR_PostDelimCRCErr 0x00040000
7774 #define AR_RxStatusRsvd71 0x3ff80000
7775 +#define AR_RxFirstAggr 0x20000000
7776 #define AR_DecryptBusyErr 0x40000000
7777 #define AR_KeyMiss 0x80000000
7778
7779 --- a/drivers/net/wireless/ath/ath9k/rc.c
7780 +++ b/drivers/net/wireless/ath/ath9k/rc.c
7781 @@ -1324,8 +1324,8 @@ static void ath_rate_update(void *priv,
7782 ath_rc_init(sc, priv_sta);
7783
7784 ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG,
7785 - "Operating HT Bandwidth changed to: %d\n",
7786 - cfg80211_get_chandef_type(&sc->hw->conf.chandef));
7787 + "Operating Bandwidth changed to: %d\n",
7788 + sc->hw->conf.chandef.width);
7789 }
7790 }
7791
7792 --- a/drivers/net/wireless/ath/ath9k/reg.h
7793 +++ b/drivers/net/wireless/ath/ath9k/reg.h
7794 @@ -893,9 +893,9 @@
7795
7796 #define AR_SREV_9485(_ah) \
7797 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9485))
7798 -#define AR_SREV_9485_11(_ah) \
7799 - (AR_SREV_9485(_ah) && \
7800 - ((_ah)->hw_version.macRev == AR_SREV_REVISION_9485_11))
7801 +#define AR_SREV_9485_11_OR_LATER(_ah) \
7802 + (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9485) && \
7803 + ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9485_11))
7804 #define AR_SREV_9485_OR_LATER(_ah) \
7805 (((_ah)->hw_version.macVersion >= AR_SREV_VERSION_9485))
7806