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