mac80211: add AP inactivity handling / probing fixes to improve stability
[openwrt/svn-archive/archive.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 @@ -3332,7 +3514,7 @@ static int ieee80211_probe_client(struct
5114 return -EINVAL;
5115 }
5116 band = chanctx_conf->def.chan->band;
5117 - sta = sta_info_get(sdata, peer);
5118 + sta = sta_info_get_bss(sdata, peer);
5119 if (sta) {
5120 qos = test_sta_flag(sta, WLAN_STA_WME);
5121 } else {
5122 @@ -3501,4 +3683,5 @@ struct cfg80211_ops mac80211_config_ops
5123 .get_et_strings = ieee80211_get_et_strings,
5124 .get_channel = ieee80211_cfg_get_channel,
5125 .start_radar_detection = ieee80211_start_radar_detection,
5126 + .channel_switch = ieee80211_channel_switch,
5127 };
5128 --- a/net/mac80211/chan.c
5129 +++ b/net/mac80211/chan.c
5130 @@ -410,6 +410,64 @@ int ieee80211_vif_use_channel(struct iee
5131 return ret;
5132 }
5133
5134 +int ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata,
5135 + const struct cfg80211_chan_def *chandef,
5136 + u32 *changed)
5137 +{
5138 + struct ieee80211_local *local = sdata->local;
5139 + struct ieee80211_chanctx_conf *conf;
5140 + struct ieee80211_chanctx *ctx;
5141 + int ret;
5142 + u32 chanctx_changed = 0;
5143 +
5144 + /* should never be called if not performing a channel switch. */
5145 + if (WARN_ON(!sdata->vif.csa_active))
5146 + return -EINVAL;
5147 +
5148 + if (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
5149 + IEEE80211_CHAN_DISABLED))
5150 + return -EINVAL;
5151 +
5152 + mutex_lock(&local->chanctx_mtx);
5153 + conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
5154 + lockdep_is_held(&local->chanctx_mtx));
5155 + if (!conf) {
5156 + ret = -EINVAL;
5157 + goto out;
5158 + }
5159 +
5160 + ctx = container_of(conf, struct ieee80211_chanctx, conf);
5161 + if (ctx->refcount != 1) {
5162 + ret = -EINVAL;
5163 + goto out;
5164 + }
5165 +
5166 + if (sdata->vif.bss_conf.chandef.width != chandef->width) {
5167 + chanctx_changed = IEEE80211_CHANCTX_CHANGE_WIDTH;
5168 + *changed |= BSS_CHANGED_BANDWIDTH;
5169 + }
5170 +
5171 + sdata->vif.bss_conf.chandef = *chandef;
5172 + ctx->conf.def = *chandef;
5173 +
5174 + chanctx_changed |= IEEE80211_CHANCTX_CHANGE_CHANNEL;
5175 + drv_change_chanctx(local, ctx, chanctx_changed);
5176 +
5177 + if (!local->use_chanctx) {
5178 + local->_oper_chandef = *chandef;
5179 + ieee80211_hw_config(local, 0);
5180 + }
5181 +
5182 + ieee80211_recalc_chanctx_chantype(local, ctx);
5183 + ieee80211_recalc_smps_chanctx(local, ctx);
5184 + ieee80211_recalc_radar_chanctx(local, ctx);
5185 +
5186 + ret = 0;
5187 + out:
5188 + mutex_unlock(&local->chanctx_mtx);
5189 + return ret;
5190 +}
5191 +
5192 int ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata,
5193 const struct cfg80211_chan_def *chandef,
5194 u32 *changed)
5195 --- a/net/mac80211/driver-ops.h
5196 +++ b/net/mac80211/driver-ops.h
5197 @@ -1104,4 +1104,17 @@ static inline void drv_ipv6_addr_change(
5198 }
5199 #endif
5200
5201 +static inline void
5202 +drv_channel_switch_beacon(struct ieee80211_sub_if_data *sdata,
5203 + struct cfg80211_chan_def *chandef)
5204 +{
5205 + struct ieee80211_local *local = sdata->local;
5206 +
5207 + if (local->ops->channel_switch_beacon) {
5208 + trace_drv_channel_switch_beacon(local, sdata, chandef);
5209 + local->ops->channel_switch_beacon(&local->hw, &sdata->vif,
5210 + chandef);
5211 + }
5212 +}
5213 +
5214 #endif /* __MAC80211_DRIVER_OPS */
5215 --- a/net/mac80211/ieee80211_i.h
5216 +++ b/net/mac80211/ieee80211_i.h
5217 @@ -53,9 +53,6 @@ struct ieee80211_local;
5218 * increased memory use (about 2 kB of RAM per entry). */
5219 #define IEEE80211_FRAGMENT_MAX 4
5220
5221 -#define TU_TO_JIFFIES(x) (usecs_to_jiffies((x) * 1024))
5222 -#define TU_TO_EXP_TIME(x) (jiffies + TU_TO_JIFFIES(x))
5223 -
5224 /* power level hasn't been configured (or set to automatic) */
5225 #define IEEE80211_UNSET_POWER_LEVEL INT_MIN
5226
5227 @@ -259,6 +256,8 @@ struct ieee80211_if_ap {
5228 struct beacon_data __rcu *beacon;
5229 struct probe_resp __rcu *probe_resp;
5230
5231 + /* to be used after channel switch. */
5232 + struct cfg80211_beacon_data *next_beacon;
5233 struct list_head vlans;
5234
5235 struct ps_data ps;
5236 @@ -713,6 +712,11 @@ struct ieee80211_sub_if_data {
5237
5238 struct ieee80211_tx_queue_params tx_conf[IEEE80211_NUM_ACS];
5239
5240 + struct work_struct csa_finalize_work;
5241 + int csa_counter_offset_beacon;
5242 + int csa_counter_offset_presp;
5243 + bool csa_radar_required;
5244 +
5245 /* used to reconfigure hardware SM PS */
5246 struct work_struct recalc_smps;
5247
5248 @@ -1346,6 +1350,9 @@ void ieee80211_roc_notify_destroy(struct
5249 void ieee80211_sw_roc_work(struct work_struct *work);
5250 void ieee80211_handle_roc_started(struct ieee80211_roc_work *roc);
5251
5252 +/* channel switch handling */
5253 +void ieee80211_csa_finalize_work(struct work_struct *work);
5254 +
5255 /* interface handling */
5256 int ieee80211_iface_init(void);
5257 void ieee80211_iface_exit(void);
5258 @@ -1367,6 +1374,8 @@ void ieee80211_del_virtual_monitor(struc
5259
5260 bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata);
5261 void ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata);
5262 +int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
5263 + struct cfg80211_beacon_data *params);
5264
5265 static inline bool ieee80211_sdata_running(struct ieee80211_sub_if_data *sdata)
5266 {
5267 @@ -1627,6 +1636,11 @@ int __must_check
5268 ieee80211_vif_change_bandwidth(struct ieee80211_sub_if_data *sdata,
5269 const struct cfg80211_chan_def *chandef,
5270 u32 *changed);
5271 +/* NOTE: only use ieee80211_vif_change_channel() for channel switch */
5272 +int __must_check
5273 +ieee80211_vif_change_channel(struct ieee80211_sub_if_data *sdata,
5274 + const struct cfg80211_chan_def *chandef,
5275 + u32 *changed);
5276 void ieee80211_vif_release_channel(struct ieee80211_sub_if_data *sdata);
5277 void ieee80211_vif_vlan_copy_chanctx(struct ieee80211_sub_if_data *sdata);
5278 void ieee80211_vif_copy_chanctx_to_vlans(struct ieee80211_sub_if_data *sdata,
5279 --- a/net/mac80211/trace.h
5280 +++ b/net/mac80211/trace.h
5281 @@ -1906,6 +1906,32 @@ TRACE_EVENT(api_radar_detected,
5282 )
5283 );
5284
5285 +TRACE_EVENT(drv_channel_switch_beacon,
5286 + TP_PROTO(struct ieee80211_local *local,
5287 + struct ieee80211_sub_if_data *sdata,
5288 + struct cfg80211_chan_def *chandef),
5289 +
5290 + TP_ARGS(local, sdata, chandef),
5291 +
5292 + TP_STRUCT__entry(
5293 + LOCAL_ENTRY
5294 + VIF_ENTRY
5295 + CHANDEF_ENTRY
5296 + ),
5297 +
5298 + TP_fast_assign(
5299 + LOCAL_ASSIGN;
5300 + VIF_ASSIGN;
5301 + CHANDEF_ASSIGN(chandef);
5302 + ),
5303 +
5304 + TP_printk(
5305 + LOCAL_PR_FMT VIF_PR_FMT " channel switch to " CHANDEF_PR_FMT,
5306 + LOCAL_PR_ARG, VIF_PR_ARG, CHANDEF_PR_ARG
5307 + )
5308 +);
5309 +
5310 +
5311 #ifdef CPTCFG_MAC80211_MESSAGE_TRACING
5312 #undef TRACE_SYSTEM
5313 #define TRACE_SYSTEM mac80211_msg
5314 --- a/net/mac80211/tx.c
5315 +++ b/net/mac80211/tx.c
5316 @@ -1101,7 +1101,8 @@ ieee80211_tx_prepare(struct ieee80211_su
5317 tx->sta = rcu_dereference(sdata->u.vlan.sta);
5318 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr)
5319 return TX_DROP;
5320 - } else if (info->flags & IEEE80211_TX_CTL_INJECTED ||
5321 + } else if (info->flags & (IEEE80211_TX_CTL_INJECTED |
5322 + IEEE80211_TX_INTFL_NL80211_FRAME_TX) ||
5323 tx->sdata->control_port_protocol == tx->skb->protocol) {
5324 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
5325 }
5326 @@ -2326,6 +2327,81 @@ static int ieee80211_beacon_add_tim(stru
5327 return 0;
5328 }
5329
5330 +void ieee80211_csa_finish(struct ieee80211_vif *vif)
5331 +{
5332 + struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5333 +
5334 + ieee80211_queue_work(&sdata->local->hw,
5335 + &sdata->csa_finalize_work);
5336 +}
5337 +EXPORT_SYMBOL(ieee80211_csa_finish);
5338 +
5339 +static void ieee80211_update_csa(struct ieee80211_sub_if_data *sdata,
5340 + struct beacon_data *beacon)
5341 +{
5342 + struct probe_resp *resp;
5343 + int counter_offset_beacon = sdata->csa_counter_offset_beacon;
5344 + int counter_offset_presp = sdata->csa_counter_offset_presp;
5345 +
5346 + /* warn if the driver did not check for/react to csa completeness */
5347 + if (WARN_ON(((u8 *)beacon->tail)[counter_offset_beacon] == 0))
5348 + return;
5349 +
5350 + ((u8 *)beacon->tail)[counter_offset_beacon]--;
5351 +
5352 + if (sdata->vif.type == NL80211_IFTYPE_AP &&
5353 + counter_offset_presp) {
5354 + rcu_read_lock();
5355 + resp = rcu_dereference(sdata->u.ap.probe_resp);
5356 +
5357 + /* if nl80211 accepted the offset, this should not happen. */
5358 + if (WARN_ON(!resp)) {
5359 + rcu_read_unlock();
5360 + return;
5361 + }
5362 + resp->data[counter_offset_presp]--;
5363 + rcu_read_unlock();
5364 + }
5365 +}
5366 +
5367 +bool ieee80211_csa_is_complete(struct ieee80211_vif *vif)
5368 +{
5369 + struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
5370 + struct beacon_data *beacon = NULL;
5371 + u8 *beacon_data;
5372 + size_t beacon_data_len;
5373 + int counter_beacon = sdata->csa_counter_offset_beacon;
5374 + int ret = false;
5375 +
5376 + if (!ieee80211_sdata_running(sdata))
5377 + return false;
5378 +
5379 + rcu_read_lock();
5380 + if (vif->type == NL80211_IFTYPE_AP) {
5381 + struct ieee80211_if_ap *ap = &sdata->u.ap;
5382 +
5383 + beacon = rcu_dereference(ap->beacon);
5384 + if (WARN_ON(!beacon || !beacon->tail))
5385 + goto out;
5386 + beacon_data = beacon->tail;
5387 + beacon_data_len = beacon->tail_len;
5388 + } else {
5389 + WARN_ON(1);
5390 + goto out;
5391 + }
5392 +
5393 + if (WARN_ON(counter_beacon > beacon_data_len))
5394 + goto out;
5395 +
5396 + if (beacon_data[counter_beacon] == 0)
5397 + ret = true;
5398 + out:
5399 + rcu_read_unlock();
5400 +
5401 + return ret;
5402 +}
5403 +EXPORT_SYMBOL(ieee80211_csa_is_complete);
5404 +
5405 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
5406 struct ieee80211_vif *vif,
5407 u16 *tim_offset, u16 *tim_length)
5408 @@ -2356,6 +2432,9 @@ struct sk_buff *ieee80211_beacon_get_tim
5409 struct beacon_data *beacon = rcu_dereference(ap->beacon);
5410
5411 if (beacon) {
5412 + if (sdata->vif.csa_active)
5413 + ieee80211_update_csa(sdata, beacon);
5414 +
5415 /*
5416 * headroom, head length,
5417 * tail length and maximum TIM length
5418 --- a/net/wireless/rdev-ops.h
5419 +++ b/net/wireless/rdev-ops.h
5420 @@ -923,4 +923,16 @@ static inline void rdev_crit_proto_stop(
5421 trace_rdev_return_void(&rdev->wiphy);
5422 }
5423
5424 +static inline int rdev_channel_switch(struct cfg80211_registered_device *rdev,
5425 + struct net_device *dev,
5426 + struct cfg80211_csa_settings *params)
5427 +{
5428 + int ret;
5429 +
5430 + trace_rdev_channel_switch(&rdev->wiphy, dev, params);
5431 + ret = rdev->ops->channel_switch(&rdev->wiphy, dev, params);
5432 + trace_rdev_return_int(&rdev->wiphy, ret);
5433 + return ret;
5434 +}
5435 +
5436 #endif /* __CFG80211_RDEV_OPS */
5437 --- a/net/wireless/trace.h
5438 +++ b/net/wireless/trace.h
5439 @@ -1841,6 +1841,39 @@ TRACE_EVENT(rdev_crit_proto_stop,
5440 WIPHY_PR_ARG, WDEV_PR_ARG)
5441 );
5442
5443 +TRACE_EVENT(rdev_channel_switch,
5444 + TP_PROTO(struct wiphy *wiphy, struct net_device *netdev,
5445 + struct cfg80211_csa_settings *params),
5446 + TP_ARGS(wiphy, netdev, params),
5447 + TP_STRUCT__entry(
5448 + WIPHY_ENTRY
5449 + NETDEV_ENTRY
5450 + CHAN_DEF_ENTRY
5451 + __field(u16, counter_offset_beacon)
5452 + __field(u16, counter_offset_presp)
5453 + __field(bool, radar_required)
5454 + __field(bool, block_tx)
5455 + __field(u8, count)
5456 + ),
5457 + TP_fast_assign(
5458 + WIPHY_ASSIGN;
5459 + NETDEV_ASSIGN;
5460 + CHAN_DEF_ASSIGN(&params->chandef);
5461 + __entry->counter_offset_beacon = params->counter_offset_beacon;
5462 + __entry->counter_offset_presp = params->counter_offset_presp;
5463 + __entry->radar_required = params->radar_required;
5464 + __entry->block_tx = params->block_tx;
5465 + __entry->count = params->count;
5466 + ),
5467 + TP_printk(WIPHY_PR_FMT ", " NETDEV_PR_FMT ", " CHAN_DEF_PR_FMT
5468 + ", block_tx: %d, count: %u, radar_required: %d"
5469 + ", counter offsets (beacon/presp): %u/%u",
5470 + WIPHY_PR_ARG, NETDEV_PR_ARG, CHAN_DEF_PR_ARG,
5471 + __entry->block_tx, __entry->count, __entry->radar_required,
5472 + __entry->counter_offset_beacon,
5473 + __entry->counter_offset_presp)
5474 +);
5475 +
5476 /*************************************************************
5477 * cfg80211 exported functions traces *
5478 *************************************************************/
5479 --- a/drivers/net/wireless/ath/ath.h
5480 +++ b/drivers/net/wireless/ath/ath.h
5481 @@ -159,7 +159,7 @@ struct ath_common {
5482
5483 bool btcoex_enabled;
5484 bool disable_ani;
5485 - bool antenna_diversity;
5486 + bool bt_ant_diversity;
5487 };
5488
5489 struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
5490 --- a/drivers/net/wireless/ath/ath9k/antenna.c
5491 +++ b/drivers/net/wireless/ath/ath9k/antenna.c
5492 @@ -16,37 +16,119 @@
5493
5494 #include "ath9k.h"
5495
5496 -static inline bool ath_is_alt_ant_ratio_better(int alt_ratio, int maxdelta,
5497 +/*
5498 + * AR9285
5499 + * ======
5500 + *
5501 + * EEPROM has 2 4-bit fields containing the card configuration.
5502 + *
5503 + * antdiv_ctl1:
5504 + * ------------
5505 + * bb_enable_ant_div_lnadiv : 1
5506 + * bb_ant_div_alt_gaintb : 1
5507 + * bb_ant_div_main_gaintb : 1
5508 + * bb_enable_ant_fast_div : 1
5509 + *
5510 + * antdiv_ctl2:
5511 + * -----------
5512 + * bb_ant_div_alt_lnaconf : 2
5513 + * bb_ant_div_main_lnaconf : 2
5514 + *
5515 + * The EEPROM bits are used as follows:
5516 + * ------------------------------------
5517 + *
5518 + * bb_enable_ant_div_lnadiv - Enable LNA path rx antenna diversity/combining.
5519 + * Set in AR_PHY_MULTICHAIN_GAIN_CTL.
5520 + *
5521 + * bb_ant_div_[alt/main]_gaintb - 0 -> Antenna config Alt/Main uses gaintable 0
5522 + * 1 -> Antenna config Alt/Main uses gaintable 1
5523 + * Set in AR_PHY_MULTICHAIN_GAIN_CTL.
5524 + *
5525 + * bb_enable_ant_fast_div - Enable fast antenna diversity.
5526 + * Set in AR_PHY_CCK_DETECT.
5527 + *
5528 + * bb_ant_div_[alt/main]_lnaconf - Alt/Main LNA diversity/combining input config.
5529 + * Set in AR_PHY_MULTICHAIN_GAIN_CTL.
5530 + * 10=LNA1
5531 + * 01=LNA2
5532 + * 11=LNA1+LNA2
5533 + * 00=LNA1-LNA2
5534 + *
5535 + * AR9485 / AR9565 / AR9331
5536 + * ========================
5537 + *
5538 + * The same bits are present in the EEPROM, but the location in the
5539 + * EEPROM is different (ant_div_control in ar9300_BaseExtension_1).
5540 + *
5541 + * ant_div_alt_lnaconf ==> bit 0~1
5542 + * ant_div_main_lnaconf ==> bit 2~3
5543 + * ant_div_alt_gaintb ==> bit 4
5544 + * ant_div_main_gaintb ==> bit 5
5545 + * enable_ant_div_lnadiv ==> bit 6
5546 + * enable_ant_fast_div ==> bit 7
5547 + */
5548 +
5549 +static inline bool ath_is_alt_ant_ratio_better(struct ath_ant_comb *antcomb,
5550 + int alt_ratio, int maxdelta,
5551 int mindelta, int main_rssi_avg,
5552 int alt_rssi_avg, int pkt_count)
5553 {
5554 - return (((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
5555 - (alt_rssi_avg > main_rssi_avg + maxdelta)) ||
5556 - (alt_rssi_avg > main_rssi_avg + mindelta)) && (pkt_count > 50);
5557 + if (pkt_count <= 50)
5558 + return false;
5559 +
5560 + if (alt_rssi_avg > main_rssi_avg + mindelta)
5561 + return true;
5562 +
5563 + if (alt_ratio >= antcomb->ant_ratio2 &&
5564 + alt_rssi_avg >= antcomb->low_rssi_thresh &&
5565 + (alt_rssi_avg > main_rssi_avg + maxdelta))
5566 + return true;
5567 +
5568 + return false;
5569 }
5570
5571 -static inline bool ath_ant_div_comb_alt_check(u8 div_group, int alt_ratio,
5572 - int curr_main_set, int curr_alt_set,
5573 - int alt_rssi_avg, int main_rssi_avg)
5574 +static inline bool ath_ant_div_comb_alt_check(struct ath_hw_antcomb_conf *conf,
5575 + struct ath_ant_comb *antcomb,
5576 + int alt_ratio, int alt_rssi_avg,
5577 + int main_rssi_avg)
5578 {
5579 - bool result = false;
5580 - switch (div_group) {
5581 + bool result, set1, set2;
5582 +
5583 + result = set1 = set2 = false;
5584 +
5585 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2 &&
5586 + conf->alt_lna_conf == ATH_ANT_DIV_COMB_LNA1)
5587 + set1 = true;
5588 +
5589 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA1 &&
5590 + conf->alt_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5591 + set2 = true;
5592 +
5593 + switch (conf->div_group) {
5594 case 0:
5595 if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
5596 result = true;
5597 break;
5598 case 1:
5599 case 2:
5600 - if ((((curr_main_set == ATH_ANT_DIV_COMB_LNA2) &&
5601 - (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) &&
5602 - (alt_rssi_avg >= (main_rssi_avg - 5))) ||
5603 - ((curr_main_set == ATH_ANT_DIV_COMB_LNA1) &&
5604 - (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) &&
5605 - (alt_rssi_avg >= (main_rssi_avg - 2)))) &&
5606 - (alt_rssi_avg >= 4))
5607 + if (alt_rssi_avg < 4 || alt_rssi_avg < antcomb->low_rssi_thresh)
5608 + break;
5609 +
5610 + if ((set1 && (alt_rssi_avg >= (main_rssi_avg - 5))) ||
5611 + (set2 && (alt_rssi_avg >= (main_rssi_avg - 2))) ||
5612 + (alt_ratio > antcomb->ant_ratio))
5613 result = true;
5614 - else
5615 - result = false;
5616 +
5617 + break;
5618 + case 3:
5619 + if (alt_rssi_avg < 4 || alt_rssi_avg < antcomb->low_rssi_thresh)
5620 + break;
5621 +
5622 + if ((set1 && (alt_rssi_avg >= (main_rssi_avg - 3))) ||
5623 + (set2 && (alt_rssi_avg >= (main_rssi_avg + 3))) ||
5624 + (alt_ratio > antcomb->ant_ratio))
5625 + result = true;
5626 +
5627 break;
5628 }
5629
5630 @@ -108,6 +190,74 @@ static void ath_lnaconf_alt_good_scan(st
5631 }
5632 }
5633
5634 +static void ath_ant_set_alt_ratio(struct ath_ant_comb *antcomb,
5635 + struct ath_hw_antcomb_conf *conf)
5636 +{
5637 + /* set alt to the conf with maximun ratio */
5638 + if (antcomb->first_ratio && antcomb->second_ratio) {
5639 + if (antcomb->rssi_second > antcomb->rssi_third) {
5640 + /* first alt*/
5641 + if ((antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
5642 + (antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2))
5643 + /* Set alt LNA1 or LNA2*/
5644 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5645 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5646 + else
5647 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5648 + else
5649 + /* Set alt to A+B or A-B */
5650 + conf->alt_lna_conf =
5651 + antcomb->first_quick_scan_conf;
5652 + } else if ((antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
5653 + (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2)) {
5654 + /* Set alt LNA1 or LNA2 */
5655 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5656 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5657 + else
5658 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5659 + } else {
5660 + /* Set alt to A+B or A-B */
5661 + conf->alt_lna_conf = antcomb->second_quick_scan_conf;
5662 + }
5663 + } else if (antcomb->first_ratio) {
5664 + /* first alt */
5665 + if ((antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
5666 + (antcomb->first_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2))
5667 + /* Set alt LNA1 or LNA2 */
5668 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5669 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5670 + else
5671 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5672 + else
5673 + /* Set alt to A+B or A-B */
5674 + conf->alt_lna_conf = antcomb->first_quick_scan_conf;
5675 + } else if (antcomb->second_ratio) {
5676 + /* second alt */
5677 + if ((antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1) ||
5678 + (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA2))
5679 + /* Set alt LNA1 or LNA2 */
5680 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5681 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5682 + else
5683 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5684 + else
5685 + /* Set alt to A+B or A-B */
5686 + conf->alt_lna_conf = antcomb->second_quick_scan_conf;
5687 + } else {
5688 + /* main is largest */
5689 + if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
5690 + (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
5691 + /* Set alt LNA1 or LNA2 */
5692 + if (conf->main_lna_conf == ATH_ANT_DIV_COMB_LNA2)
5693 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5694 + else
5695 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5696 + else
5697 + /* Set alt to A+B or A-B */
5698 + conf->alt_lna_conf = antcomb->main_conf;
5699 + }
5700 +}
5701 +
5702 static void ath_select_ant_div_from_quick_scan(struct ath_ant_comb *antcomb,
5703 struct ath_hw_antcomb_conf *div_ant_conf,
5704 int main_rssi_avg, int alt_rssi_avg,
5705 @@ -129,7 +279,7 @@ static void ath_select_ant_div_from_quic
5706
5707 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
5708 /* main is LNA1 */
5709 - if (ath_is_alt_ant_ratio_better(alt_ratio,
5710 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5711 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
5712 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
5713 main_rssi_avg, alt_rssi_avg,
5714 @@ -138,7 +288,7 @@ static void ath_select_ant_div_from_quic
5715 else
5716 antcomb->first_ratio = false;
5717 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
5718 - if (ath_is_alt_ant_ratio_better(alt_ratio,
5719 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5720 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
5721 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
5722 main_rssi_avg, alt_rssi_avg,
5723 @@ -147,11 +297,11 @@ static void ath_select_ant_div_from_quic
5724 else
5725 antcomb->first_ratio = false;
5726 } else {
5727 - if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
5728 - (alt_rssi_avg > main_rssi_avg +
5729 - ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
5730 - (alt_rssi_avg > main_rssi_avg)) &&
5731 - (antcomb->total_pkt_count > 50))
5732 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5733 + ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
5734 + 0,
5735 + main_rssi_avg, alt_rssi_avg,
5736 + antcomb->total_pkt_count))
5737 antcomb->first_ratio = true;
5738 else
5739 antcomb->first_ratio = false;
5740 @@ -164,17 +314,21 @@ static void ath_select_ant_div_from_quic
5741 antcomb->rssi_first = main_rssi_avg;
5742 antcomb->rssi_third = alt_rssi_avg;
5743
5744 - if (antcomb->second_quick_scan_conf == ATH_ANT_DIV_COMB_LNA1)
5745 + switch(antcomb->second_quick_scan_conf) {
5746 + case ATH_ANT_DIV_COMB_LNA1:
5747 antcomb->rssi_lna1 = alt_rssi_avg;
5748 - else if (antcomb->second_quick_scan_conf ==
5749 - ATH_ANT_DIV_COMB_LNA2)
5750 + break;
5751 + case ATH_ANT_DIV_COMB_LNA2:
5752 antcomb->rssi_lna2 = alt_rssi_avg;
5753 - else if (antcomb->second_quick_scan_conf ==
5754 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2) {
5755 + break;
5756 + case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
5757 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2)
5758 antcomb->rssi_lna2 = main_rssi_avg;
5759 else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1)
5760 antcomb->rssi_lna1 = main_rssi_avg;
5761 + break;
5762 + default:
5763 + break;
5764 }
5765
5766 if (antcomb->rssi_lna2 > antcomb->rssi_lna1 +
5767 @@ -184,7 +338,7 @@ static void ath_select_ant_div_from_quic
5768 div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5769
5770 if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) {
5771 - if (ath_is_alt_ant_ratio_better(alt_ratio,
5772 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5773 ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
5774 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
5775 main_rssi_avg, alt_rssi_avg,
5776 @@ -193,7 +347,7 @@ static void ath_select_ant_div_from_quic
5777 else
5778 antcomb->second_ratio = false;
5779 } else if (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2) {
5780 - if (ath_is_alt_ant_ratio_better(alt_ratio,
5781 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5782 ATH_ANT_DIV_COMB_LNA1_DELTA_MID,
5783 ATH_ANT_DIV_COMB_LNA1_DELTA_LOW,
5784 main_rssi_avg, alt_rssi_avg,
5785 @@ -202,105 +356,18 @@ static void ath_select_ant_div_from_quic
5786 else
5787 antcomb->second_ratio = false;
5788 } else {
5789 - if ((((alt_ratio >= ATH_ANT_DIV_COMB_ALT_ANT_RATIO2) &&
5790 - (alt_rssi_avg > main_rssi_avg +
5791 - ATH_ANT_DIV_COMB_LNA1_DELTA_HI)) ||
5792 - (alt_rssi_avg > main_rssi_avg)) &&
5793 - (antcomb->total_pkt_count > 50))
5794 + if (ath_is_alt_ant_ratio_better(antcomb, alt_ratio,
5795 + ATH_ANT_DIV_COMB_LNA1_DELTA_HI,
5796 + 0,
5797 + main_rssi_avg, alt_rssi_avg,
5798 + antcomb->total_pkt_count))
5799 antcomb->second_ratio = true;
5800 else
5801 antcomb->second_ratio = false;
5802 }
5803
5804 - /* set alt to the conf with maximun ratio */
5805 - if (antcomb->first_ratio && antcomb->second_ratio) {
5806 - if (antcomb->rssi_second > antcomb->rssi_third) {
5807 - /* first alt*/
5808 - if ((antcomb->first_quick_scan_conf ==
5809 - ATH_ANT_DIV_COMB_LNA1) ||
5810 - (antcomb->first_quick_scan_conf ==
5811 - ATH_ANT_DIV_COMB_LNA2))
5812 - /* Set alt LNA1 or LNA2*/
5813 - if (div_ant_conf->main_lna_conf ==
5814 - ATH_ANT_DIV_COMB_LNA2)
5815 - div_ant_conf->alt_lna_conf =
5816 - ATH_ANT_DIV_COMB_LNA1;
5817 - else
5818 - div_ant_conf->alt_lna_conf =
5819 - ATH_ANT_DIV_COMB_LNA2;
5820 - else
5821 - /* Set alt to A+B or A-B */
5822 - div_ant_conf->alt_lna_conf =
5823 - antcomb->first_quick_scan_conf;
5824 - } else if ((antcomb->second_quick_scan_conf ==
5825 - ATH_ANT_DIV_COMB_LNA1) ||
5826 - (antcomb->second_quick_scan_conf ==
5827 - ATH_ANT_DIV_COMB_LNA2)) {
5828 - /* Set alt LNA1 or LNA2 */
5829 - if (div_ant_conf->main_lna_conf ==
5830 - ATH_ANT_DIV_COMB_LNA2)
5831 - div_ant_conf->alt_lna_conf =
5832 - ATH_ANT_DIV_COMB_LNA1;
5833 - else
5834 - div_ant_conf->alt_lna_conf =
5835 - ATH_ANT_DIV_COMB_LNA2;
5836 - } else {
5837 - /* Set alt to A+B or A-B */
5838 - div_ant_conf->alt_lna_conf =
5839 - antcomb->second_quick_scan_conf;
5840 - }
5841 - } else if (antcomb->first_ratio) {
5842 - /* first alt */
5843 - if ((antcomb->first_quick_scan_conf ==
5844 - ATH_ANT_DIV_COMB_LNA1) ||
5845 - (antcomb->first_quick_scan_conf ==
5846 - ATH_ANT_DIV_COMB_LNA2))
5847 - /* Set alt LNA1 or LNA2 */
5848 - if (div_ant_conf->main_lna_conf ==
5849 - ATH_ANT_DIV_COMB_LNA2)
5850 - div_ant_conf->alt_lna_conf =
5851 - ATH_ANT_DIV_COMB_LNA1;
5852 - else
5853 - div_ant_conf->alt_lna_conf =
5854 - ATH_ANT_DIV_COMB_LNA2;
5855 - else
5856 - /* Set alt to A+B or A-B */
5857 - div_ant_conf->alt_lna_conf =
5858 - antcomb->first_quick_scan_conf;
5859 - } else if (antcomb->second_ratio) {
5860 - /* second alt */
5861 - if ((antcomb->second_quick_scan_conf ==
5862 - ATH_ANT_DIV_COMB_LNA1) ||
5863 - (antcomb->second_quick_scan_conf ==
5864 - ATH_ANT_DIV_COMB_LNA2))
5865 - /* Set alt LNA1 or LNA2 */
5866 - if (div_ant_conf->main_lna_conf ==
5867 - ATH_ANT_DIV_COMB_LNA2)
5868 - div_ant_conf->alt_lna_conf =
5869 - ATH_ANT_DIV_COMB_LNA1;
5870 - else
5871 - div_ant_conf->alt_lna_conf =
5872 - ATH_ANT_DIV_COMB_LNA2;
5873 - else
5874 - /* Set alt to A+B or A-B */
5875 - div_ant_conf->alt_lna_conf =
5876 - antcomb->second_quick_scan_conf;
5877 - } else {
5878 - /* main is largest */
5879 - if ((antcomb->main_conf == ATH_ANT_DIV_COMB_LNA1) ||
5880 - (antcomb->main_conf == ATH_ANT_DIV_COMB_LNA2))
5881 - /* Set alt LNA1 or LNA2 */
5882 - if (div_ant_conf->main_lna_conf ==
5883 - ATH_ANT_DIV_COMB_LNA2)
5884 - div_ant_conf->alt_lna_conf =
5885 - ATH_ANT_DIV_COMB_LNA1;
5886 - else
5887 - div_ant_conf->alt_lna_conf =
5888 - ATH_ANT_DIV_COMB_LNA2;
5889 - else
5890 - /* Set alt to A+B or A-B */
5891 - div_ant_conf->alt_lna_conf = antcomb->main_conf;
5892 - }
5893 + ath_ant_set_alt_ratio(antcomb, div_ant_conf);
5894 +
5895 break;
5896 default:
5897 break;
5898 @@ -430,8 +497,7 @@ static void ath_ant_div_conf_fast_divbia
5899 ant_conf->fast_div_bias = 0x1;
5900 break;
5901 case 0x10: /* LNA2 A-B */
5902 - if (!(antcomb->scan) &&
5903 - (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
5904 + if (!antcomb->scan && (alt_ratio > antcomb->ant_ratio))
5905 ant_conf->fast_div_bias = 0x1;
5906 else
5907 ant_conf->fast_div_bias = 0x2;
5908 @@ -440,15 +506,13 @@ static void ath_ant_div_conf_fast_divbia
5909 ant_conf->fast_div_bias = 0x1;
5910 break;
5911 case 0x13: /* LNA2 A+B */
5912 - if (!(antcomb->scan) &&
5913 - (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
5914 + if (!antcomb->scan && (alt_ratio > antcomb->ant_ratio))
5915 ant_conf->fast_div_bias = 0x1;
5916 else
5917 ant_conf->fast_div_bias = 0x2;
5918 break;
5919 case 0x20: /* LNA1 A-B */
5920 - if (!(antcomb->scan) &&
5921 - (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
5922 + if (!antcomb->scan && (alt_ratio > antcomb->ant_ratio))
5923 ant_conf->fast_div_bias = 0x1;
5924 else
5925 ant_conf->fast_div_bias = 0x2;
5926 @@ -457,8 +521,7 @@ static void ath_ant_div_conf_fast_divbia
5927 ant_conf->fast_div_bias = 0x1;
5928 break;
5929 case 0x23: /* LNA1 A+B */
5930 - if (!(antcomb->scan) &&
5931 - (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO))
5932 + if (!antcomb->scan && (alt_ratio > antcomb->ant_ratio))
5933 ant_conf->fast_div_bias = 0x1;
5934 else
5935 ant_conf->fast_div_bias = 0x2;
5936 @@ -475,6 +538,9 @@ static void ath_ant_div_conf_fast_divbia
5937 default:
5938 break;
5939 }
5940 +
5941 + if (antcomb->fast_div_bias)
5942 + ant_conf->fast_div_bias = antcomb->fast_div_bias;
5943 } else if (ant_conf->div_group == 3) {
5944 switch ((ant_conf->main_lna_conf << 4) |
5945 ant_conf->alt_lna_conf) {
5946 @@ -540,6 +606,138 @@ static void ath_ant_div_conf_fast_divbia
5947 }
5948 }
5949
5950 +static void ath_ant_try_scan(struct ath_ant_comb *antcomb,
5951 + struct ath_hw_antcomb_conf *conf,
5952 + int curr_alt_set, int alt_rssi_avg,
5953 + int main_rssi_avg)
5954 +{
5955 + switch (curr_alt_set) {
5956 + case ATH_ANT_DIV_COMB_LNA2:
5957 + antcomb->rssi_lna2 = alt_rssi_avg;
5958 + antcomb->rssi_lna1 = main_rssi_avg;
5959 + antcomb->scan = true;
5960 + /* set to A+B */
5961 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5962 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
5963 + break;
5964 + case ATH_ANT_DIV_COMB_LNA1:
5965 + antcomb->rssi_lna1 = alt_rssi_avg;
5966 + antcomb->rssi_lna2 = main_rssi_avg;
5967 + antcomb->scan = true;
5968 + /* set to A+B */
5969 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5970 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
5971 + break;
5972 + case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
5973 + antcomb->rssi_add = alt_rssi_avg;
5974 + antcomb->scan = true;
5975 + /* set to A-B */
5976 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
5977 + break;
5978 + case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
5979 + antcomb->rssi_sub = alt_rssi_avg;
5980 + antcomb->scan = false;
5981 + if (antcomb->rssi_lna2 >
5982 + (antcomb->rssi_lna1 + ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
5983 + /* use LNA2 as main LNA */
5984 + if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
5985 + (antcomb->rssi_add > antcomb->rssi_sub)) {
5986 + /* set to A+B */
5987 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5988 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
5989 + } else if (antcomb->rssi_sub >
5990 + antcomb->rssi_lna1) {
5991 + /* set to A-B */
5992 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5993 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
5994 + } else {
5995 + /* set to LNA1 */
5996 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
5997 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
5998 + }
5999 + } else {
6000 + /* use LNA1 as main LNA */
6001 + if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
6002 + (antcomb->rssi_add > antcomb->rssi_sub)) {
6003 + /* set to A+B */
6004 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
6005 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
6006 + } else if (antcomb->rssi_sub >
6007 + antcomb->rssi_lna1) {
6008 + /* set to A-B */
6009 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
6010 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
6011 + } else {
6012 + /* set to LNA2 */
6013 + conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
6014 + conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
6015 + }
6016 + }
6017 + break;
6018 + default:
6019 + break;
6020 + }
6021 +}
6022 +
6023 +static bool ath_ant_try_switch(struct ath_hw_antcomb_conf *div_ant_conf,
6024 + struct ath_ant_comb *antcomb,
6025 + int alt_ratio, int alt_rssi_avg,
6026 + int main_rssi_avg, int curr_main_set,
6027 + int curr_alt_set)
6028 +{
6029 + bool ret = false;
6030 +
6031 + if (ath_ant_div_comb_alt_check(div_ant_conf, antcomb, alt_ratio,
6032 + alt_rssi_avg, main_rssi_avg)) {
6033 + if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
6034 + /*
6035 + * Switch main and alt LNA.
6036 + */
6037 + div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
6038 + div_ant_conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
6039 + } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
6040 + div_ant_conf->main_lna_conf = ATH_ANT_DIV_COMB_LNA1;
6041 + div_ant_conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
6042 + }
6043 +
6044 + ret = true;
6045 + } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
6046 + (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
6047 + /*
6048 + Set alt to another LNA.
6049 + */
6050 + if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
6051 + div_ant_conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA1;
6052 + else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
6053 + div_ant_conf->alt_lna_conf = ATH_ANT_DIV_COMB_LNA2;
6054 +
6055 + ret = true;
6056 + }
6057 +
6058 + return ret;
6059 +}
6060 +
6061 +static bool ath_ant_short_scan_check(struct ath_ant_comb *antcomb)
6062 +{
6063 + int alt_ratio;
6064 +
6065 + if (!antcomb->scan || !antcomb->alt_good)
6066 + return false;
6067 +
6068 + if (time_after(jiffies, antcomb->scan_start_time +
6069 + msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
6070 + return true;
6071 +
6072 + if (antcomb->total_pkt_count == ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
6073 + alt_ratio = ((antcomb->alt_recv_cnt * 100) /
6074 + antcomb->total_pkt_count);
6075 + if (alt_ratio < antcomb->ant_ratio)
6076 + return true;
6077 + }
6078 +
6079 + return false;
6080 +}
6081 +
6082 void ath_ant_comb_scan(struct ath_softc *sc, struct ath_rx_status *rs)
6083 {
6084 struct ath_hw_antcomb_conf div_ant_conf;
6085 @@ -549,41 +747,46 @@ void ath_ant_comb_scan(struct ath_softc
6086 int main_rssi = rs->rs_rssi_ctl0;
6087 int alt_rssi = rs->rs_rssi_ctl1;
6088 int rx_ant_conf, main_ant_conf;
6089 - bool short_scan = false;
6090 + bool short_scan = false, ret;
6091
6092 rx_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_CURRENT_SHIFT) &
6093 ATH_ANT_RX_MASK;
6094 main_ant_conf = (rs->rs_rssi_ctl2 >> ATH_ANT_RX_MAIN_SHIFT) &
6095 ATH_ANT_RX_MASK;
6096
6097 + if (alt_rssi >= antcomb->low_rssi_thresh) {
6098 + antcomb->ant_ratio = ATH_ANT_DIV_COMB_ALT_ANT_RATIO;
6099 + antcomb->ant_ratio2 = ATH_ANT_DIV_COMB_ALT_ANT_RATIO2;
6100 + } else {
6101 + antcomb->ant_ratio = ATH_ANT_DIV_COMB_ALT_ANT_RATIO_LOW_RSSI;
6102 + antcomb->ant_ratio2 = ATH_ANT_DIV_COMB_ALT_ANT_RATIO2_LOW_RSSI;
6103 + }
6104 +
6105 /* Record packet only when both main_rssi and alt_rssi is positive */
6106 if (main_rssi > 0 && alt_rssi > 0) {
6107 antcomb->total_pkt_count++;
6108 antcomb->main_total_rssi += main_rssi;
6109 antcomb->alt_total_rssi += alt_rssi;
6110 +
6111 if (main_ant_conf == rx_ant_conf)
6112 antcomb->main_recv_cnt++;
6113 else
6114 antcomb->alt_recv_cnt++;
6115 }
6116
6117 - /* Short scan check */
6118 - if (antcomb->scan && antcomb->alt_good) {
6119 - if (time_after(jiffies, antcomb->scan_start_time +
6120 - msecs_to_jiffies(ATH_ANT_DIV_COMB_SHORT_SCAN_INTR)))
6121 - short_scan = true;
6122 - else
6123 - if (antcomb->total_pkt_count ==
6124 - ATH_ANT_DIV_COMB_SHORT_SCAN_PKTCOUNT) {
6125 - alt_ratio = ((antcomb->alt_recv_cnt * 100) /
6126 - antcomb->total_pkt_count);
6127 - if (alt_ratio < ATH_ANT_DIV_COMB_ALT_ANT_RATIO)
6128 - short_scan = true;
6129 - }
6130 + if (main_ant_conf == rx_ant_conf) {
6131 + ANT_STAT_INC(ANT_MAIN, recv_cnt);
6132 + ANT_LNA_INC(ANT_MAIN, rx_ant_conf);
6133 + } else {
6134 + ANT_STAT_INC(ANT_ALT, recv_cnt);
6135 + ANT_LNA_INC(ANT_ALT, rx_ant_conf);
6136 }
6137
6138 + /* Short scan check */
6139 + short_scan = ath_ant_short_scan_check(antcomb);
6140 +
6141 if (((antcomb->total_pkt_count < ATH_ANT_DIV_COMB_MAX_PKTCOUNT) ||
6142 - rs->rs_moreaggr) && !short_scan)
6143 + rs->rs_moreaggr) && !short_scan)
6144 return;
6145
6146 if (antcomb->total_pkt_count) {
6147 @@ -595,15 +798,13 @@ void ath_ant_comb_scan(struct ath_softc
6148 antcomb->total_pkt_count);
6149 }
6150
6151 -
6152 ath9k_hw_antdiv_comb_conf_get(sc->sc_ah, &div_ant_conf);
6153 curr_alt_set = div_ant_conf.alt_lna_conf;
6154 curr_main_set = div_ant_conf.main_lna_conf;
6155 -
6156 antcomb->count++;
6157
6158 if (antcomb->count == ATH_ANT_DIV_COMB_MAX_COUNT) {
6159 - if (alt_ratio > ATH_ANT_DIV_COMB_ALT_ANT_RATIO) {
6160 + if (alt_ratio > antcomb->ant_ratio) {
6161 ath_lnaconf_alt_good_scan(antcomb, div_ant_conf,
6162 main_rssi_avg);
6163 antcomb->alt_good = true;
6164 @@ -617,153 +818,47 @@ void ath_ant_comb_scan(struct ath_softc
6165 }
6166
6167 if (!antcomb->scan) {
6168 - if (ath_ant_div_comb_alt_check(div_ant_conf.div_group,
6169 - alt_ratio, curr_main_set, curr_alt_set,
6170 - alt_rssi_avg, main_rssi_avg)) {
6171 - if (curr_alt_set == ATH_ANT_DIV_COMB_LNA2) {
6172 - /* Switch main and alt LNA */
6173 - div_ant_conf.main_lna_conf =
6174 - ATH_ANT_DIV_COMB_LNA2;
6175 - div_ant_conf.alt_lna_conf =
6176 - ATH_ANT_DIV_COMB_LNA1;
6177 - } else if (curr_alt_set == ATH_ANT_DIV_COMB_LNA1) {
6178 - div_ant_conf.main_lna_conf =
6179 - ATH_ANT_DIV_COMB_LNA1;
6180 - div_ant_conf.alt_lna_conf =
6181 - ATH_ANT_DIV_COMB_LNA2;
6182 - }
6183 -
6184 - goto div_comb_done;
6185 - } else if ((curr_alt_set != ATH_ANT_DIV_COMB_LNA1) &&
6186 - (curr_alt_set != ATH_ANT_DIV_COMB_LNA2)) {
6187 - /* Set alt to another LNA */
6188 - if (curr_main_set == ATH_ANT_DIV_COMB_LNA2)
6189 - div_ant_conf.alt_lna_conf =
6190 - ATH_ANT_DIV_COMB_LNA1;
6191 - else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1)
6192 - div_ant_conf.alt_lna_conf =
6193 - ATH_ANT_DIV_COMB_LNA2;
6194 -
6195 - goto div_comb_done;
6196 - }
6197 -
6198 - if ((alt_rssi_avg < (main_rssi_avg +
6199 - div_ant_conf.lna1_lna2_delta)))
6200 + ret = ath_ant_try_switch(&div_ant_conf, antcomb, alt_ratio,
6201 + alt_rssi_avg, main_rssi_avg,
6202 + curr_main_set, curr_alt_set);
6203 + if (ret)
6204 goto div_comb_done;
6205 }
6206
6207 + if (!antcomb->scan &&
6208 + (alt_rssi_avg < (main_rssi_avg + div_ant_conf.lna1_lna2_delta)))
6209 + goto div_comb_done;
6210 +
6211 if (!antcomb->scan_not_start) {
6212 - switch (curr_alt_set) {
6213 - case ATH_ANT_DIV_COMB_LNA2:
6214 - antcomb->rssi_lna2 = alt_rssi_avg;
6215 - antcomb->rssi_lna1 = main_rssi_avg;
6216 - antcomb->scan = true;
6217 - /* set to A+B */
6218 - div_ant_conf.main_lna_conf =
6219 - ATH_ANT_DIV_COMB_LNA1;
6220 - div_ant_conf.alt_lna_conf =
6221 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
6222 - break;
6223 - case ATH_ANT_DIV_COMB_LNA1:
6224 - antcomb->rssi_lna1 = alt_rssi_avg;
6225 - antcomb->rssi_lna2 = main_rssi_avg;
6226 - antcomb->scan = true;
6227 - /* set to A+B */
6228 - div_ant_conf.main_lna_conf = ATH_ANT_DIV_COMB_LNA2;
6229 - div_ant_conf.alt_lna_conf =
6230 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
6231 - break;
6232 - case ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2:
6233 - antcomb->rssi_add = alt_rssi_avg;
6234 - antcomb->scan = true;
6235 - /* set to A-B */
6236 - div_ant_conf.alt_lna_conf =
6237 - ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
6238 - break;
6239 - case ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2:
6240 - antcomb->rssi_sub = alt_rssi_avg;
6241 - antcomb->scan = false;
6242 - if (antcomb->rssi_lna2 >
6243 - (antcomb->rssi_lna1 +
6244 - ATH_ANT_DIV_COMB_LNA1_LNA2_SWITCH_DELTA)) {
6245 - /* use LNA2 as main LNA */
6246 - if ((antcomb->rssi_add > antcomb->rssi_lna1) &&
6247 - (antcomb->rssi_add > antcomb->rssi_sub)) {
6248 - /* set to A+B */
6249 - div_ant_conf.main_lna_conf =
6250 - ATH_ANT_DIV_COMB_LNA2;
6251 - div_ant_conf.alt_lna_conf =
6252 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
6253 - } else if (antcomb->rssi_sub >
6254 - antcomb->rssi_lna1) {
6255 - /* set to A-B */
6256 - div_ant_conf.main_lna_conf =
6257 - ATH_ANT_DIV_COMB_LNA2;
6258 - div_ant_conf.alt_lna_conf =
6259 - ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
6260 - } else {
6261 - /* set to LNA1 */
6262 - div_ant_conf.main_lna_conf =
6263 - ATH_ANT_DIV_COMB_LNA2;
6264 - div_ant_conf.alt_lna_conf =
6265 - ATH_ANT_DIV_COMB_LNA1;
6266 - }
6267 - } else {
6268 - /* use LNA1 as main LNA */
6269 - if ((antcomb->rssi_add > antcomb->rssi_lna2) &&
6270 - (antcomb->rssi_add > antcomb->rssi_sub)) {
6271 - /* set to A+B */
6272 - div_ant_conf.main_lna_conf =
6273 - ATH_ANT_DIV_COMB_LNA1;
6274 - div_ant_conf.alt_lna_conf =
6275 - ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2;
6276 - } else if (antcomb->rssi_sub >
6277 - antcomb->rssi_lna1) {
6278 - /* set to A-B */
6279 - div_ant_conf.main_lna_conf =
6280 - ATH_ANT_DIV_COMB_LNA1;
6281 - div_ant_conf.alt_lna_conf =
6282 - ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2;
6283 - } else {
6284 - /* set to LNA2 */
6285 - div_ant_conf.main_lna_conf =
6286 - ATH_ANT_DIV_COMB_LNA1;
6287 - div_ant_conf.alt_lna_conf =
6288 - ATH_ANT_DIV_COMB_LNA2;
6289 - }
6290 - }
6291 - break;
6292 - default:
6293 - break;
6294 - }
6295 + ath_ant_try_scan(antcomb, &div_ant_conf, curr_alt_set,
6296 + alt_rssi_avg, main_rssi_avg);
6297 } else {
6298 if (!antcomb->alt_good) {
6299 antcomb->scan_not_start = false;
6300 /* Set alt to another LNA */
6301 if (curr_main_set == ATH_ANT_DIV_COMB_LNA2) {
6302 div_ant_conf.main_lna_conf =
6303 - ATH_ANT_DIV_COMB_LNA2;
6304 + ATH_ANT_DIV_COMB_LNA2;
6305 div_ant_conf.alt_lna_conf =
6306 - ATH_ANT_DIV_COMB_LNA1;
6307 + ATH_ANT_DIV_COMB_LNA1;
6308 } else if (curr_main_set == ATH_ANT_DIV_COMB_LNA1) {
6309 div_ant_conf.main_lna_conf =
6310 - ATH_ANT_DIV_COMB_LNA1;
6311 + ATH_ANT_DIV_COMB_LNA1;
6312 div_ant_conf.alt_lna_conf =
6313 - ATH_ANT_DIV_COMB_LNA2;
6314 + ATH_ANT_DIV_COMB_LNA2;
6315 }
6316 goto div_comb_done;
6317 }
6318 + ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
6319 + main_rssi_avg, alt_rssi_avg,
6320 + alt_ratio);
6321 + antcomb->quick_scan_cnt++;
6322 }
6323
6324 - ath_select_ant_div_from_quick_scan(antcomb, &div_ant_conf,
6325 - main_rssi_avg, alt_rssi_avg,
6326 - alt_ratio);
6327 -
6328 - antcomb->quick_scan_cnt++;
6329 -
6330 div_comb_done:
6331 ath_ant_div_conf_fast_divbias(&div_ant_conf, antcomb, alt_ratio);
6332 ath9k_hw_antdiv_comb_conf_set(sc->sc_ah, &div_ant_conf);
6333 + ath9k_debug_stat_ant(sc, &div_ant_conf, main_rssi_avg, alt_rssi_avg);
6334
6335 antcomb->scan_start_time = jiffies;
6336 antcomb->total_pkt_count = 0;
6337 @@ -772,26 +867,3 @@ div_comb_done:
6338 antcomb->main_recv_cnt = 0;
6339 antcomb->alt_recv_cnt = 0;
6340 }
6341 -
6342 -void ath_ant_comb_update(struct ath_softc *sc)
6343 -{
6344 - struct ath_hw *ah = sc->sc_ah;
6345 - struct ath_common *common = ath9k_hw_common(ah);
6346 - struct ath_hw_antcomb_conf div_ant_conf;
6347 - u8 lna_conf;
6348 -
6349 - ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
6350 -
6351 - if (sc->ant_rx == 1)
6352 - lna_conf = ATH_ANT_DIV_COMB_LNA1;
6353 - else
6354 - lna_conf = ATH_ANT_DIV_COMB_LNA2;
6355 -
6356 - div_ant_conf.main_lna_conf = lna_conf;
6357 - div_ant_conf.alt_lna_conf = lna_conf;
6358 -
6359 - ath9k_hw_antdiv_comb_conf_set(ah, &div_ant_conf);
6360 -
6361 - if (common->antenna_diversity)
6362 - ath9k_hw_antctrl_shared_chain_lnadiv(ah, true);
6363 -}
6364 --- a/drivers/net/wireless/ath/ath9k/ar5008_phy.c
6365 +++ b/drivers/net/wireless/ath/ath9k/ar5008_phy.c
6366 @@ -610,7 +610,15 @@ static void ar5008_hw_override_ini(struc
6367 REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
6368
6369 if (AR_SREV_9280_20_OR_LATER(ah)) {
6370 - val = REG_READ(ah, AR_PCU_MISC_MODE2);
6371 + /*
6372 + * For AR9280 and above, there is a new feature that allows
6373 + * Multicast search based on both MAC Address and Key ID.
6374 + * By default, this feature is enabled. But since the driver
6375 + * is not using this feature, we switch it off; otherwise
6376 + * multicast search based on MAC addr only will fail.
6377 + */
6378 + val = REG_READ(ah, AR_PCU_MISC_MODE2) &
6379 + (~AR_ADHOC_MCAST_KEYID_ENABLE);
6380
6381 if (!AR_SREV_9271(ah))
6382 val &= ~AR_PCU_MISC_MODE2_HWWAR1;
6383 --- a/drivers/net/wireless/ath/ath9k/ar9002_phy.c
6384 +++ b/drivers/net/wireless/ath/ath9k/ar9002_phy.c
6385 @@ -555,6 +555,69 @@ static void ar9002_hw_antdiv_comb_conf_s
6386 REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regval);
6387 }
6388
6389 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
6390 +
6391 +static void ar9002_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable)
6392 +{
6393 + struct ath_btcoex_hw *btcoex = &ah->btcoex_hw;
6394 + u8 antdiv_ctrl1, antdiv_ctrl2;
6395 + u32 regval;
6396 +
6397 + if (enable) {
6398 + antdiv_ctrl1 = ATH_BT_COEX_ANTDIV_CONTROL1_ENABLE;
6399 + antdiv_ctrl2 = ATH_BT_COEX_ANTDIV_CONTROL2_ENABLE;
6400 +
6401 + /*
6402 + * Don't disable BT ant to allow BB to control SWCOM.
6403 + */
6404 + btcoex->bt_coex_mode2 &= (~(AR_BT_DISABLE_BT_ANT));
6405 + REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex->bt_coex_mode2);
6406 +
6407 + REG_WRITE(ah, AR_PHY_SWITCH_COM, ATH_BT_COEX_ANT_DIV_SWITCH_COM);
6408 + REG_RMW(ah, AR_PHY_SWITCH_CHAIN_0, 0, 0xf0000000);
6409 + } else {
6410 + /*
6411 + * Disable antenna diversity, use LNA1 only.
6412 + */
6413 + antdiv_ctrl1 = ATH_BT_COEX_ANTDIV_CONTROL1_FIXED_A;
6414 + antdiv_ctrl2 = ATH_BT_COEX_ANTDIV_CONTROL2_FIXED_A;
6415 +
6416 + /*
6417 + * Disable BT Ant. to allow concurrent BT and WLAN receive.
6418 + */
6419 + btcoex->bt_coex_mode2 |= AR_BT_DISABLE_BT_ANT;
6420 + REG_WRITE(ah, AR_BT_COEX_MODE2, btcoex->bt_coex_mode2);
6421 +
6422 + /*
6423 + * Program SWCOM table to make sure RF switch always parks
6424 + * at BT side.
6425 + */
6426 + REG_WRITE(ah, AR_PHY_SWITCH_COM, 0);
6427 + REG_RMW(ah, AR_PHY_SWITCH_CHAIN_0, 0, 0xf0000000);
6428 + }
6429 +
6430 + regval = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
6431 + regval &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL));
6432 + /*
6433 + * Clear ant_fast_div_bias [14:9] since for WB195,
6434 + * the main LNA is always LNA1.
6435 + */
6436 + regval &= (~(AR_PHY_9285_FAST_DIV_BIAS));
6437 + regval |= SM(antdiv_ctrl1, AR_PHY_9285_ANT_DIV_CTL);
6438 + regval |= SM(antdiv_ctrl2, AR_PHY_9285_ANT_DIV_ALT_LNACONF);
6439 + regval |= SM((antdiv_ctrl2 >> 2), AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
6440 + regval |= SM((antdiv_ctrl1 >> 1), AR_PHY_9285_ANT_DIV_ALT_GAINTB);
6441 + regval |= SM((antdiv_ctrl1 >> 2), AR_PHY_9285_ANT_DIV_MAIN_GAINTB);
6442 + REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regval);
6443 +
6444 + regval = REG_READ(ah, AR_PHY_CCK_DETECT);
6445 + regval &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
6446 + regval |= SM((antdiv_ctrl1 >> 3), AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
6447 + REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
6448 +}
6449 +
6450 +#endif
6451 +
6452 static void ar9002_hw_spectral_scan_config(struct ath_hw *ah,
6453 struct ath_spec_scan *param)
6454 {
6455 @@ -634,5 +697,9 @@ void ar9002_hw_attach_phy_ops(struct ath
6456 ops->spectral_scan_trigger = ar9002_hw_spectral_scan_trigger;
6457 ops->spectral_scan_wait = ar9002_hw_spectral_scan_wait;
6458
6459 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
6460 + ops->set_bt_ant_diversity = ar9002_hw_set_bt_ant_diversity;
6461 +#endif
6462 +
6463 ar9002_hw_set_nf_limits(ah);
6464 }
6465 --- a/drivers/net/wireless/ath/ath9k/ar9002_phy.h
6466 +++ b/drivers/net/wireless/ath/ath9k/ar9002_phy.h
6467 @@ -317,13 +317,15 @@
6468 #define AR_PHY_9285_ANT_DIV_ALT_GAINTB_S 29
6469 #define AR_PHY_9285_ANT_DIV_MAIN_GAINTB 0x40000000
6470 #define AR_PHY_9285_ANT_DIV_MAIN_GAINTB_S 30
6471 -#define AR_PHY_9285_ANT_DIV_LNA1 2
6472 -#define AR_PHY_9285_ANT_DIV_LNA2 1
6473 -#define AR_PHY_9285_ANT_DIV_LNA1_PLUS_LNA2 3
6474 -#define AR_PHY_9285_ANT_DIV_LNA1_MINUS_LNA2 0
6475 #define AR_PHY_9285_ANT_DIV_GAINTB_0 0
6476 #define AR_PHY_9285_ANT_DIV_GAINTB_1 1
6477
6478 +#define ATH_BT_COEX_ANTDIV_CONTROL1_ENABLE 0x0b
6479 +#define ATH_BT_COEX_ANTDIV_CONTROL2_ENABLE 0x09
6480 +#define ATH_BT_COEX_ANTDIV_CONTROL1_FIXED_A 0x04
6481 +#define ATH_BT_COEX_ANTDIV_CONTROL2_FIXED_A 0x09
6482 +#define ATH_BT_COEX_ANT_DIV_SWITCH_COM 0x66666666
6483 +
6484 #define AR_PHY_EXT_CCA0 0x99b8
6485 #define AR_PHY_EXT_CCA0_THRESH62 0x000000FF
6486 #define AR_PHY_EXT_CCA0_THRESH62_S 0
6487 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
6488 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
6489 @@ -3541,13 +3541,12 @@ static u16 ar9003_switch_com_spdt_get(st
6490 return le16_to_cpu(ar9003_modal_header(ah, is2ghz)->switchcomspdt);
6491 }
6492
6493 -
6494 -static u32 ar9003_hw_ant_ctrl_common_get(struct ath_hw *ah, bool is2ghz)
6495 +u32 ar9003_hw_ant_ctrl_common_get(struct ath_hw *ah, bool is2ghz)
6496 {
6497 return le32_to_cpu(ar9003_modal_header(ah, is2ghz)->antCtrlCommon);
6498 }
6499
6500 -static u32 ar9003_hw_ant_ctrl_common_2_get(struct ath_hw *ah, bool is2ghz)
6501 +u32 ar9003_hw_ant_ctrl_common_2_get(struct ath_hw *ah, bool is2ghz)
6502 {
6503 return le32_to_cpu(ar9003_modal_header(ah, is2ghz)->antCtrlCommon2);
6504 }
6505 @@ -3561,6 +3560,7 @@ static u16 ar9003_hw_ant_ctrl_chain_get(
6506
6507 static void ar9003_hw_ant_ctrl_apply(struct ath_hw *ah, bool is2ghz)
6508 {
6509 + struct ath_common *common = ath9k_hw_common(ah);
6510 struct ath9k_hw_capabilities *pCap = &ah->caps;
6511 int chain;
6512 u32 regval, value, gpio;
6513 @@ -3614,6 +3614,11 @@ static void ar9003_hw_ant_ctrl_apply(str
6514 }
6515
6516 value = ar9003_hw_ant_ctrl_common_2_get(ah, is2ghz);
6517 + if (AR_SREV_9485(ah) && common->bt_ant_diversity) {
6518 + regval &= ~AR_SWITCH_TABLE_COM2_ALL;
6519 + regval |= ah->config.ant_ctrl_comm2g_switch_enable;
6520 +
6521 + }
6522 REG_RMW_FIELD(ah, AR_PHY_SWITCH_COM_2, AR_SWITCH_TABLE_COM2_ALL, value);
6523
6524 if ((AR_SREV_9462(ah)) && (ah->rxchainmask == 0x2)) {
6525 @@ -3645,8 +3650,11 @@ static void ar9003_hw_ant_ctrl_apply(str
6526 regval &= (~AR_PHY_ANT_DIV_LNADIV);
6527 regval |= ((value >> 6) & 0x1) << AR_PHY_ANT_DIV_LNADIV_S;
6528
6529 + if (AR_SREV_9485(ah) && common->bt_ant_diversity)
6530 + regval |= AR_ANT_DIV_ENABLE;
6531 +
6532 if (AR_SREV_9565(ah)) {
6533 - if (ah->shared_chain_lnadiv) {
6534 + if (common->bt_ant_diversity) {
6535 regval |= (1 << AR_PHY_ANT_SW_RX_PROT_S);
6536 } else {
6537 regval &= ~(1 << AR_PHY_ANT_DIV_LNADIV_S);
6538 @@ -3656,10 +3664,14 @@ static void ar9003_hw_ant_ctrl_apply(str
6539
6540 REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
6541
6542 - /*enable fast_div */
6543 + /* enable fast_div */
6544 regval = REG_READ(ah, AR_PHY_CCK_DETECT);
6545 regval &= (~AR_FAST_DIV_ENABLE);
6546 regval |= ((value >> 7) & 0x1) << AR_FAST_DIV_ENABLE_S;
6547 +
6548 + if (AR_SREV_9485(ah) && common->bt_ant_diversity)
6549 + regval |= AR_FAST_DIV_ENABLE;
6550 +
6551 REG_WRITE(ah, AR_PHY_CCK_DETECT, regval);
6552
6553 if (pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
6554 @@ -3673,9 +3685,9 @@ static void ar9003_hw_ant_ctrl_apply(str
6555 AR_PHY_ANT_DIV_ALT_GAINTB |
6556 AR_PHY_ANT_DIV_MAIN_GAINTB));
6557 /* by default use LNA1 for the main antenna */
6558 - regval |= (AR_PHY_ANT_DIV_LNA1 <<
6559 + regval |= (ATH_ANT_DIV_COMB_LNA1 <<
6560 AR_PHY_ANT_DIV_MAIN_LNACONF_S);
6561 - regval |= (AR_PHY_ANT_DIV_LNA2 <<
6562 + regval |= (ATH_ANT_DIV_COMB_LNA2 <<
6563 AR_PHY_ANT_DIV_ALT_LNACONF_S);
6564 REG_WRITE(ah, AR_PHY_MC_GAIN_CTRL, regval);
6565 }
6566 @@ -3813,6 +3825,11 @@ static void ar9003_hw_atten_apply(struct
6567 else
6568 value = ar9003_hw_atten_chain_get_margin(ah, i, chan);
6569
6570 + if (ah->config.alt_mingainidx)
6571 + REG_RMW_FIELD(ah, AR_PHY_EXT_ATTEN_CTL_0,
6572 + AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,
6573 + value);
6574 +
6575 REG_RMW_FIELD(ah, ext_atten_reg[i],
6576 AR_PHY_EXT_ATTEN_CTL_XATTEN1_MARGIN,
6577 value);
6578 --- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
6579 +++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.h
6580 @@ -334,6 +334,8 @@ struct ar9300_eeprom {
6581
6582 s32 ar9003_hw_get_tx_gain_idx(struct ath_hw *ah);
6583 s32 ar9003_hw_get_rx_gain_idx(struct ath_hw *ah);
6584 +u32 ar9003_hw_ant_ctrl_common_get(struct ath_hw *ah, bool is2ghz);
6585 +u32 ar9003_hw_ant_ctrl_common_2_get(struct ath_hw *ah, bool is2ghz);
6586
6587 u8 *ar9003_get_spur_chan_ptr(struct ath_hw *ah, bool is_2ghz);
6588
6589 --- a/drivers/net/wireless/ath/ath9k/ar9003_phy.h
6590 +++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.h
6591 @@ -148,6 +148,8 @@
6592 #define AR_PHY_SFCORR_SPUR_SUBCHNL_SD_S 28
6593 #define AR_PHY_EXT_CCA_THRESH62 0x007F0000
6594 #define AR_PHY_EXT_CCA_THRESH62_S 16
6595 +#define AR_PHY_EXTCHN_PWRTHR1_ANT_DIV_ALT_ANT_MINGAINIDX 0x0000FF00
6596 +#define AR_PHY_EXTCHN_PWRTHR1_ANT_DIV_ALT_ANT_MINGAINIDX_S 8
6597 #define AR_PHY_EXT_MINCCA_PWR 0x01FF0000
6598 #define AR_PHY_EXT_MINCCA_PWR_S 16
6599 #define AR_PHY_EXT_CYCPWR_THR1 0x0000FE00L
6600 @@ -296,11 +298,6 @@
6601 #define AR_PHY_ANT_DIV_MAIN_GAINTB 0x40000000
6602 #define AR_PHY_ANT_DIV_MAIN_GAINTB_S 30
6603
6604 -#define AR_PHY_ANT_DIV_LNA1_MINUS_LNA2 0x0
6605 -#define AR_PHY_ANT_DIV_LNA2 0x1
6606 -#define AR_PHY_ANT_DIV_LNA1 0x2
6607 -#define AR_PHY_ANT_DIV_LNA1_PLUS_LNA2 0x3
6608 -
6609 #define AR_PHY_EXTCHN_PWRTHR1 (AR_AGC_BASE + 0x2c)
6610 #define AR_PHY_EXT_CHN_WIN (AR_AGC_BASE + 0x30)
6611 #define AR_PHY_20_40_DET_THR (AR_AGC_BASE + 0x34)
6612 --- a/drivers/net/wireless/ath/ath9k/debug.h
6613 +++ b/drivers/net/wireless/ath/ath9k/debug.h
6614 @@ -28,9 +28,13 @@ struct fft_sample_tlv;
6615 #ifdef CPTCFG_ATH9K_DEBUGFS
6616 #define TX_STAT_INC(q, c) sc->debug.stats.txstats[q].c++
6617 #define RESET_STAT_INC(sc, type) sc->debug.stats.reset[type]++
6618 +#define ANT_STAT_INC(i, c) sc->debug.stats.ant_stats[i].c++
6619 +#define ANT_LNA_INC(i, c) sc->debug.stats.ant_stats[i].lna_recv_cnt[c]++;
6620 #else
6621 #define TX_STAT_INC(q, c) do { } while (0)
6622 #define RESET_STAT_INC(sc, type) do { } while (0)
6623 +#define ANT_STAT_INC(i, c) do { } while (0)
6624 +#define ANT_LNA_INC(i, c) do { } while (0)
6625 #endif
6626
6627 enum ath_reset_type {
6628 @@ -243,11 +247,22 @@ struct ath_rx_stats {
6629 u32 rx_spectral;
6630 };
6631
6632 +#define ANT_MAIN 0
6633 +#define ANT_ALT 1
6634 +
6635 +struct ath_antenna_stats {
6636 + u32 recv_cnt;
6637 + u32 rssi_avg;
6638 + u32 lna_recv_cnt[4];
6639 + u32 lna_attempt_cnt[4];
6640 +};
6641 +
6642 struct ath_stats {
6643 struct ath_interrupt_stats istats;
6644 struct ath_tx_stats txstats[ATH9K_NUM_TX_QUEUES];
6645 struct ath_rx_stats rxstats;
6646 struct ath_dfs_stats dfs_stats;
6647 + struct ath_antenna_stats ant_stats[2];
6648 u32 reset[__RESET_TYPE_MAX];
6649 };
6650
6651 @@ -281,10 +296,11 @@ void ath9k_sta_remove_debugfs(struct iee
6652 struct ieee80211_vif *vif,
6653 struct ieee80211_sta *sta,
6654 struct dentry *dir);
6655 -
6656 void ath_debug_send_fft_sample(struct ath_softc *sc,
6657 struct fft_sample_tlv *fft_sample);
6658 -
6659 +void ath9k_debug_stat_ant(struct ath_softc *sc,
6660 + struct ath_hw_antcomb_conf *div_ant_conf,
6661 + int main_rssi_avg, int alt_rssi_avg);
6662 #else
6663
6664 #define RX_STAT_INC(c) /* NOP */
6665 @@ -297,12 +313,10 @@ static inline int ath9k_init_debug(struc
6666 static inline void ath9k_deinit_debug(struct ath_softc *sc)
6667 {
6668 }
6669 -
6670 static inline void ath_debug_stat_interrupt(struct ath_softc *sc,
6671 enum ath9k_int status)
6672 {
6673 }
6674 -
6675 static inline void ath_debug_stat_tx(struct ath_softc *sc,
6676 struct ath_buf *bf,
6677 struct ath_tx_status *ts,
6678 @@ -310,11 +324,16 @@ static inline void ath_debug_stat_tx(str
6679 unsigned int flags)
6680 {
6681 }
6682 -
6683 static inline void ath_debug_stat_rx(struct ath_softc *sc,
6684 struct ath_rx_status *rs)
6685 {
6686 }
6687 +static inline void ath9k_debug_stat_ant(struct ath_softc *sc,
6688 + struct ath_hw_antcomb_conf *div_ant_conf,
6689 + int main_rssi_avg, int alt_rssi_avg)
6690 +{
6691 +
6692 +}
6693
6694 #endif /* CPTCFG_ATH9K_DEBUGFS */
6695
6696 --- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c
6697 +++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
6698 @@ -812,6 +812,7 @@ static void ath9k_hw_4k_set_gain(struct
6699 static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
6700 struct ath9k_channel *chan)
6701 {
6702 + struct ath9k_hw_capabilities *pCap = &ah->caps;
6703 struct modal_eep_4k_header *pModal;
6704 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
6705 struct base_eep_header_4k *pBase = &eep->baseEepHeader;
6706 @@ -858,6 +859,24 @@ static void ath9k_hw_4k_set_board_values
6707
6708 REG_WRITE(ah, AR_PHY_CCK_DETECT, regVal);
6709 regVal = REG_READ(ah, AR_PHY_CCK_DETECT);
6710 +
6711 + if (pCap->hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) {
6712 + /*
6713 + * If diversity combining is enabled,
6714 + * set MAIN to LNA1 and ALT to LNA2 initially.
6715 + */
6716 + regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
6717 + regVal &= (~(AR_PHY_9285_ANT_DIV_MAIN_LNACONF |
6718 + AR_PHY_9285_ANT_DIV_ALT_LNACONF));
6719 +
6720 + regVal |= (ATH_ANT_DIV_COMB_LNA1 <<
6721 + AR_PHY_9285_ANT_DIV_MAIN_LNACONF_S);
6722 + regVal |= (ATH_ANT_DIV_COMB_LNA2 <<
6723 + AR_PHY_9285_ANT_DIV_ALT_LNACONF_S);
6724 + regVal &= (~(AR_PHY_9285_FAST_DIV_BIAS));
6725 + regVal |= (0 << AR_PHY_9285_FAST_DIV_BIAS_S);
6726 + REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal);
6727 + }
6728 }
6729
6730 if (pModal->version >= 2) {
6731 --- a/drivers/net/wireless/ath/ath9k/hw-ops.h
6732 +++ b/drivers/net/wireless/ath/ath9k/hw-ops.h
6733 @@ -78,13 +78,16 @@ static inline void ath9k_hw_antdiv_comb_
6734 ath9k_hw_ops(ah)->antdiv_comb_conf_set(ah, antconf);
6735 }
6736
6737 -static inline void ath9k_hw_antctrl_shared_chain_lnadiv(struct ath_hw *ah,
6738 - bool enable)
6739 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
6740 +
6741 +static inline void ath9k_hw_set_bt_ant_diversity(struct ath_hw *ah, bool enable)
6742 {
6743 - if (ath9k_hw_ops(ah)->antctrl_shared_chain_lnadiv)
6744 - ath9k_hw_ops(ah)->antctrl_shared_chain_lnadiv(ah, enable);
6745 + if (ath9k_hw_ops(ah)->set_bt_ant_diversity)
6746 + ath9k_hw_ops(ah)->set_bt_ant_diversity(ah, enable);
6747 }
6748
6749 +#endif
6750 +
6751 /* Private hardware call ops */
6752
6753 /* PHY ops */
6754 --- a/drivers/net/wireless/ath/ath9k/hw.c
6755 +++ b/drivers/net/wireless/ath/ath9k/hw.c
6756 @@ -450,7 +450,6 @@ static void ath9k_hw_init_config(struct
6757 ah->config.ack_6mb = 0x0;
6758 ah->config.cwm_ignore_extcca = 0;
6759 ah->config.pcie_clock_req = 0;
6760 - ah->config.pcie_waen = 0;
6761 ah->config.analog_shiftreg = 1;
6762
6763 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
6764 @@ -1069,7 +1068,7 @@ void ath9k_hw_init_global_settings(struc
6765 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
6766 tx_lat += 11;
6767
6768 - sifstime *= 2;
6769 + sifstime = 32;
6770 ack_offset = 16;
6771 slottime = 13;
6772 } else if (IS_CHAN_QUARTER_RATE(chan)) {
6773 @@ -1079,7 +1078,7 @@ void ath9k_hw_init_global_settings(struc
6774 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
6775 tx_lat += 22;
6776
6777 - sifstime *= 4;
6778 + sifstime = 64;
6779 ack_offset = 32;
6780 slottime = 21;
6781 } else {
6782 @@ -1116,7 +1115,6 @@ void ath9k_hw_init_global_settings(struc
6783 ctstimeout += 48 - sifstime - ah->slottime;
6784 }
6785
6786 -
6787 ath9k_hw_set_sifs_time(ah, sifstime);
6788 ath9k_hw_setslottime(ah, slottime);
6789 ath9k_hw_set_ack_timeout(ah, acktimeout);
6790 @@ -1496,16 +1494,18 @@ static bool ath9k_hw_channel_change(stru
6791 struct ath9k_channel *chan)
6792 {
6793 struct ath_common *common = ath9k_hw_common(ah);
6794 + struct ath9k_hw_capabilities *pCap = &ah->caps;
6795 + bool band_switch = false, mode_diff = false;
6796 + u8 ini_reloaded = 0;
6797 u32 qnum;
6798 int r;
6799 - bool edma = !!(ah->caps.hw_caps & ATH9K_HW_CAP_EDMA);
6800 - bool band_switch, mode_diff;
6801 - u8 ini_reloaded;
6802 -
6803 - band_switch = (chan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ)) !=
6804 - (ah->curchan->channelFlags & (CHANNEL_2GHZ |
6805 - CHANNEL_5GHZ));
6806 - mode_diff = (chan->chanmode != ah->curchan->chanmode);
6807 +
6808 + if (pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) {
6809 + u32 cur = ah->curchan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ);
6810 + u32 new = chan->channelFlags & (CHANNEL_2GHZ | CHANNEL_5GHZ);
6811 + band_switch = (cur != new);
6812 + mode_diff = (chan->chanmode != ah->curchan->chanmode);
6813 + }
6814
6815 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
6816 if (ath9k_hw_numtxpending(ah, qnum)) {
6817 @@ -1520,11 +1520,12 @@ static bool ath9k_hw_channel_change(stru
6818 return false;
6819 }
6820
6821 - if (edma && (band_switch || mode_diff)) {
6822 + if (band_switch || mode_diff) {
6823 ath9k_hw_mark_phy_inactive(ah);
6824 udelay(5);
6825
6826 - ath9k_hw_init_pll(ah, NULL);
6827 + if (band_switch)
6828 + ath9k_hw_init_pll(ah, chan);
6829
6830 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
6831 ath_err(common, "Failed to do fast channel change\n");
6832 @@ -1541,22 +1542,21 @@ static bool ath9k_hw_channel_change(stru
6833 }
6834 ath9k_hw_set_clockrate(ah);
6835 ath9k_hw_apply_txpower(ah, chan, false);
6836 - ath9k_hw_rfbus_done(ah);
6837
6838 if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
6839 ath9k_hw_set_delta_slope(ah, chan);
6840
6841 ath9k_hw_spur_mitigate_freq(ah, chan);
6842
6843 - if (edma && (band_switch || mode_diff)) {
6844 - ah->ah_flags |= AH_FASTCC;
6845 - if (band_switch || ini_reloaded)
6846 - ah->eep_ops->set_board_values(ah, chan);
6847 + if (band_switch || ini_reloaded)
6848 + ah->eep_ops->set_board_values(ah, chan);
6849
6850 - ath9k_hw_init_bb(ah, chan);
6851 + ath9k_hw_init_bb(ah, chan);
6852 + ath9k_hw_rfbus_done(ah);
6853
6854 - if (band_switch || ini_reloaded)
6855 - ath9k_hw_init_cal(ah, chan);
6856 + if (band_switch || ini_reloaded) {
6857 + ah->ah_flags |= AH_FASTCC;
6858 + ath9k_hw_init_cal(ah, chan);
6859 ah->ah_flags &= ~AH_FASTCC;
6860 }
6861
6862 @@ -1778,16 +1778,11 @@ static void ath9k_hw_init_desc(struct at
6863 /*
6864 * Fast channel change:
6865 * (Change synthesizer based on channel freq without resetting chip)
6866 - *
6867 - * Don't do FCC when
6868 - * - Flag is not set
6869 - * - Chip is just coming out of full sleep
6870 - * - Channel to be set is same as current channel
6871 - * - Channel flags are different, (eg.,moving from 2GHz to 5GHz channel)
6872 */
6873 static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
6874 {
6875 struct ath_common *common = ath9k_hw_common(ah);
6876 + struct ath9k_hw_capabilities *pCap = &ah->caps;
6877 int ret;
6878
6879 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
6880 @@ -1806,9 +1801,21 @@ static int ath9k_hw_do_fastcc(struct ath
6881 (CHANNEL_HALF | CHANNEL_QUARTER))
6882 goto fail;
6883
6884 - if ((chan->channelFlags & CHANNEL_ALL) !=
6885 - (ah->curchan->channelFlags & CHANNEL_ALL))
6886 - goto fail;
6887 + /*
6888 + * If cross-band fcc is not supoprted, bail out if
6889 + * either channelFlags or chanmode differ.
6890 + *
6891 + * chanmode will be different if the HT operating mode
6892 + * changes because of CSA.
6893 + */
6894 + if (!(pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH)) {
6895 + if ((chan->channelFlags & CHANNEL_ALL) !=
6896 + (ah->curchan->channelFlags & CHANNEL_ALL))
6897 + goto fail;
6898 +
6899 + if (chan->chanmode != ah->curchan->chanmode)
6900 + goto fail;
6901 + }
6902
6903 if (!ath9k_hw_check_alive(ah))
6904 goto fail;
6905 @@ -2047,7 +2054,7 @@ int ath9k_hw_reset(struct ath_hw *ah, st
6906
6907 ath9k_hw_apply_gpio_override(ah);
6908
6909 - if (AR_SREV_9565(ah) && ah->shared_chain_lnadiv)
6910 + if (AR_SREV_9565(ah) && common->bt_ant_diversity)
6911 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON);
6912
6913 return 0;
6914 @@ -2550,34 +2557,28 @@ int ath9k_hw_fill_cap_info(struct ath_hw
6915 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
6916 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
6917
6918 - if (AR_SREV_9285(ah))
6919 + if (AR_SREV_9285(ah)) {
6920 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
6921 ant_div_ctl1 =
6922 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
6923 - if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
6924 + if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1)) {
6925 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
6926 + ath_info(common, "Enable LNA combining\n");
6927 + }
6928 }
6929 + }
6930 +
6931 if (AR_SREV_9300_20_OR_LATER(ah)) {
6932 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
6933 pCap->hw_caps |= ATH9K_HW_CAP_APM;
6934 }
6935
6936 -
6937 if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
6938 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
6939 - /*
6940 - * enable the diversity-combining algorithm only when
6941 - * both enable_lna_div and enable_fast_div are set
6942 - * Table for Diversity
6943 - * ant_div_alt_lnaconf bit 0-1
6944 - * ant_div_main_lnaconf bit 2-3
6945 - * ant_div_alt_gaintb bit 4
6946 - * ant_div_main_gaintb bit 5
6947 - * enable_ant_div_lnadiv bit 6
6948 - * enable_ant_fast_div bit 7
6949 - */
6950 - if ((ant_div_ctl1 >> 0x6) == 0x3)
6951 + if ((ant_div_ctl1 >> 0x6) == 0x3) {
6952 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
6953 + ath_info(common, "Enable LNA combining\n");
6954 + }
6955 }
6956
6957 if (ath9k_hw_dfs_tested(ah))
6958 @@ -2610,6 +2611,13 @@ int ath9k_hw_fill_cap_info(struct ath_hw
6959 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
6960 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
6961
6962 + /*
6963 + * Fast channel change across bands is available
6964 + * only for AR9462 and AR9565.
6965 + */
6966 + if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
6967 + pCap->hw_caps |= ATH9K_HW_CAP_FCC_BAND_SWITCH;
6968 +
6969 return 0;
6970 }
6971
6972 --- a/drivers/net/wireless/ath/ath9k/hw.h
6973 +++ b/drivers/net/wireless/ath/ath9k/hw.h
6974 @@ -247,6 +247,8 @@ enum ath9k_hw_caps {
6975 ATH9K_HW_CAP_DFS = BIT(16),
6976 ATH9K_HW_WOW_DEVICE_CAPABLE = BIT(17),
6977 ATH9K_HW_CAP_PAPRD = BIT(18),
6978 + ATH9K_HW_CAP_FCC_BAND_SWITCH = BIT(19),
6979 + ATH9K_HW_CAP_BT_ANT_DIV = BIT(20),
6980 };
6981
6982 /*
6983 @@ -309,8 +311,11 @@ struct ath9k_ops_config {
6984 u16 ani_poll_interval; /* ANI poll interval in ms */
6985
6986 /* Platform specific config */
6987 + u32 aspm_l1_fix;
6988 u32 xlna_gpio;
6989 + u32 ant_ctrl_comm2g_switch_enable;
6990 bool xatten_margin_cfg;
6991 + bool alt_mingainidx;
6992 };
6993
6994 enum ath9k_int {
6995 @@ -716,11 +721,14 @@ struct ath_hw_ops {
6996 struct ath_hw_antcomb_conf *antconf);
6997 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
6998 struct ath_hw_antcomb_conf *antconf);
6999 - void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
7000 void (*spectral_scan_config)(struct ath_hw *ah,
7001 struct ath_spec_scan *param);
7002 void (*spectral_scan_trigger)(struct ath_hw *ah);
7003 void (*spectral_scan_wait)(struct ath_hw *ah);
7004 +
7005 +#ifdef CPTCFG_ATH9K_BTCOEX_SUPPORT
7006 + void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
7007 +#endif
7008 };
7009
7010 struct ath_nf_limits {
7011 @@ -765,7 +773,6 @@ struct ath_hw {
7012 bool aspm_enabled;
7013 bool is_monitoring;
7014 bool need_an_top2_fixup;
7015 - bool shared_chain_lnadiv;
7016 u16 tx_trig_level;
7017
7018 u32 nf_regs[6];
7019 --- a/drivers/net/wireless/ath/ath9k/pci.c
7020 +++ b/drivers/net/wireless/ath/ath9k/pci.c
7021 @@ -29,6 +29,60 @@ static DEFINE_PCI_DEVICE_TABLE(ath_pci_i
7022 { PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI */
7023 { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */
7024 { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
7025 +
7026 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7027 + 0x002A,
7028 + PCI_VENDOR_ID_AZWAVE,
7029 + 0x1C71),
7030 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7031 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7032 + 0x002A,
7033 + PCI_VENDOR_ID_FOXCONN,
7034 + 0xE01F),
7035 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7036 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7037 + 0x002A,
7038 + 0x11AD, /* LITEON */
7039 + 0x6632),
7040 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7041 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7042 + 0x002A,
7043 + 0x11AD, /* LITEON */
7044 + 0x6642),
7045 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7046 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7047 + 0x002A,
7048 + PCI_VENDOR_ID_QMI,
7049 + 0x0306),
7050 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7051 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7052 + 0x002A,
7053 + 0x185F, /* WNC */
7054 + 0x309D),
7055 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7056 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7057 + 0x002A,
7058 + 0x10CF, /* Fujitsu */
7059 + 0x147C),
7060 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7061 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7062 + 0x002A,
7063 + 0x10CF, /* Fujitsu */
7064 + 0x147D),
7065 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7066 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7067 + 0x002A,
7068 + 0x10CF, /* Fujitsu */
7069 + 0x1536),
7070 + .driver_data = ATH9K_PCI_D3_L1_WAR },
7071 +
7072 + /* AR9285 card for Asus */
7073 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7074 + 0x002B,
7075 + PCI_VENDOR_ID_AZWAVE,
7076 + 0x2C37),
7077 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7078 +
7079 { PCI_VDEVICE(ATHEROS, 0x002B) }, /* PCI-E */
7080 { PCI_VDEVICE(ATHEROS, 0x002C) }, /* PCI-E 802.11n bonded out */
7081 { PCI_VDEVICE(ATHEROS, 0x002D) }, /* PCI */
7082 @@ -40,29 +94,106 @@ static DEFINE_PCI_DEVICE_TABLE(ath_pci_i
7083 0x0032,
7084 PCI_VENDOR_ID_AZWAVE,
7085 0x2086),
7086 - .driver_data = ATH9K_PCI_CUS198 },
7087 + .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
7088 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7089 0x0032,
7090 PCI_VENDOR_ID_AZWAVE,
7091 0x1237),
7092 - .driver_data = ATH9K_PCI_CUS198 },
7093 + .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
7094 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7095 0x0032,
7096 PCI_VENDOR_ID_AZWAVE,
7097 0x2126),
7098 - .driver_data = ATH9K_PCI_CUS198 },
7099 + .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
7100 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7101 + 0x0032,
7102 + PCI_VENDOR_ID_AZWAVE,
7103 + 0x126A),
7104 + .driver_data = ATH9K_PCI_CUS198 | ATH9K_PCI_BT_ANT_DIV },
7105
7106 /* PCI-E CUS230 */
7107 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7108 0x0032,
7109 PCI_VENDOR_ID_AZWAVE,
7110 0x2152),
7111 - .driver_data = ATH9K_PCI_CUS230 },
7112 + .driver_data = ATH9K_PCI_CUS230 | ATH9K_PCI_BT_ANT_DIV },
7113 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7114 0x0032,
7115 PCI_VENDOR_ID_FOXCONN,
7116 0xE075),
7117 - .driver_data = ATH9K_PCI_CUS230 },
7118 + .driver_data = ATH9K_PCI_CUS230 | ATH9K_PCI_BT_ANT_DIV },
7119 +
7120 + /* WB225 */
7121 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7122 + 0x0032,
7123 + PCI_VENDOR_ID_ATHEROS,
7124 + 0x3119),
7125 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7126 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7127 + 0x0032,
7128 + PCI_VENDOR_ID_ATHEROS,
7129 + 0x3122),
7130 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7131 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7132 + 0x0032,
7133 + 0x185F, /* WNC */
7134 + 0x3119),
7135 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7136 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7137 + 0x0032,
7138 + 0x185F, /* WNC */
7139 + 0x3027),
7140 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7141 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7142 + 0x0032,
7143 + PCI_VENDOR_ID_SAMSUNG,
7144 + 0x4105),
7145 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7146 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7147 + 0x0032,
7148 + PCI_VENDOR_ID_SAMSUNG,
7149 + 0x4106),
7150 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7151 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7152 + 0x0032,
7153 + PCI_VENDOR_ID_SAMSUNG,
7154 + 0x410D),
7155 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7156 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7157 + 0x0032,
7158 + PCI_VENDOR_ID_SAMSUNG,
7159 + 0x410E),
7160 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7161 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7162 + 0x0032,
7163 + PCI_VENDOR_ID_SAMSUNG,
7164 + 0x410F),
7165 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7166 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7167 + 0x0032,
7168 + PCI_VENDOR_ID_SAMSUNG,
7169 + 0xC706),
7170 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7171 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7172 + 0x0032,
7173 + PCI_VENDOR_ID_SAMSUNG,
7174 + 0xC680),
7175 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7176 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7177 + 0x0032,
7178 + PCI_VENDOR_ID_SAMSUNG,
7179 + 0xC708),
7180 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7181 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7182 + 0x0032,
7183 + PCI_VENDOR_ID_LENOVO,
7184 + 0x3218),
7185 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7186 + { PCI_DEVICE_SUB(PCI_VENDOR_ID_ATHEROS,
7187 + 0x0032,
7188 + PCI_VENDOR_ID_LENOVO,
7189 + 0x3219),
7190 + .driver_data = ATH9K_PCI_BT_ANT_DIV },
7191
7192 { PCI_VDEVICE(ATHEROS, 0x0032) }, /* PCI-E AR9485 */
7193 { PCI_VDEVICE(ATHEROS, 0x0033) }, /* PCI-E AR9580 */
7194 @@ -229,6 +360,22 @@ static void ath_pci_aspm_init(struct ath
7195 return;
7196 }
7197
7198 + /*
7199 + * 0x70c - Ack Frequency Register.
7200 + *
7201 + * Bits 27:29 - DEFAULT_L1_ENTRANCE_LATENCY.
7202 + *
7203 + * 000 : 1 us
7204 + * 001 : 2 us
7205 + * 010 : 4 us
7206 + * 011 : 8 us
7207 + * 100 : 16 us
7208 + * 101 : 32 us
7209 + * 110/111 : 64 us
7210 + */
7211 + if (AR_SREV_9462(ah))
7212 + pci_read_config_dword(pdev, 0x70c, &ah->config.aspm_l1_fix);
7213 +
7214 pcie_capability_read_word(parent, PCI_EXP_LNKCTL, &aspm);
7215 if (aspm & (PCI_EXP_LNKCTL_ASPM_L0S | PCI_EXP_LNKCTL_ASPM_L1)) {
7216 ah->aspm_enabled = true;
7217 --- a/drivers/net/wireless/ath/ath9k/phy.h
7218 +++ b/drivers/net/wireless/ath/ath9k/phy.h
7219 @@ -48,4 +48,11 @@
7220 #define AR_PHY_PLL_CONTROL 0x16180
7221 #define AR_PHY_PLL_MODE 0x16184
7222
7223 +enum ath9k_ant_div_comb_lna_conf {
7224 + ATH_ANT_DIV_COMB_LNA1_MINUS_LNA2,
7225 + ATH_ANT_DIV_COMB_LNA2,
7226 + ATH_ANT_DIV_COMB_LNA1,
7227 + ATH_ANT_DIV_COMB_LNA1_PLUS_LNA2,
7228 +};
7229 +
7230 #endif
7231 --- a/drivers/net/wireless/iwlwifi/mvm/time-event.c
7232 +++ b/drivers/net/wireless/iwlwifi/mvm/time-event.c
7233 @@ -73,7 +73,6 @@
7234 #include "iwl-prph.h"
7235
7236 /* A TimeUnit is 1024 microsecond */
7237 -#define TU_TO_JIFFIES(_tu) (usecs_to_jiffies((_tu) * 1024))
7238 #define MSEC_TO_TU(_msec) (_msec*1000/1024)
7239
7240 /*
7241 @@ -191,8 +190,7 @@ static void iwl_mvm_te_handle_notif(stru
7242 iwl_mvm_te_clear_data(mvm, te_data);
7243 } else if (le32_to_cpu(notif->action) & TE_NOTIF_HOST_EVENT_START) {
7244 te_data->running = true;
7245 - te_data->end_jiffies = jiffies +
7246 - TU_TO_JIFFIES(te_data->duration);
7247 + te_data->end_jiffies = TU_TO_EXP_TIME(te_data->duration);
7248
7249 if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
7250 set_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
7251 @@ -329,8 +327,7 @@ void iwl_mvm_protect_session(struct iwl_
7252 lockdep_assert_held(&mvm->mutex);
7253
7254 if (te_data->running &&
7255 - time_after(te_data->end_jiffies,
7256 - jiffies + TU_TO_JIFFIES(min_duration))) {
7257 + time_after(te_data->end_jiffies, TU_TO_EXP_TIME(min_duration))) {
7258 IWL_DEBUG_TE(mvm, "We have enough time in the current TE: %u\n",
7259 jiffies_to_msecs(te_data->end_jiffies - jiffies));
7260 return;
7261 --- a/include/linux/ieee80211.h
7262 +++ b/include/linux/ieee80211.h
7263 @@ -2279,4 +2279,8 @@ static inline bool ieee80211_check_tim(c
7264 return !!(tim->virtual_map[index] & mask);
7265 }
7266
7267 +/* convert time units */
7268 +#define TU_TO_JIFFIES(x) (usecs_to_jiffies((x) * 1024))
7269 +#define TU_TO_EXP_TIME(x) (jiffies + TU_TO_JIFFIES(x))
7270 +
7271 #endif /* LINUX_IEEE80211_H */
7272 --- a/net/mac80211/rate.c
7273 +++ b/net/mac80211/rate.c
7274 @@ -210,7 +210,7 @@ static bool rc_no_data_or_no_ack_use_min
7275 !ieee80211_is_data(fc);
7276 }
7277
7278 -static void rc_send_low_broadcast(s8 *idx, u32 basic_rates,
7279 +static void rc_send_low_basicrate(s8 *idx, u32 basic_rates,
7280 struct ieee80211_supported_band *sband)
7281 {
7282 u8 i;
7283 @@ -272,28 +272,37 @@ static void __rate_control_send_low(stru
7284 }
7285
7286
7287 -bool rate_control_send_low(struct ieee80211_sta *sta,
7288 +bool rate_control_send_low(struct ieee80211_sta *pubsta,
7289 void *priv_sta,
7290 struct ieee80211_tx_rate_control *txrc)
7291 {
7292 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(txrc->skb);
7293 struct ieee80211_supported_band *sband = txrc->sband;
7294 + struct sta_info *sta;
7295 int mcast_rate;
7296 + bool use_basicrate = false;
7297
7298 - if (!sta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) {
7299 - __rate_control_send_low(txrc->hw, sband, sta, info);
7300 + if (!pubsta || !priv_sta || rc_no_data_or_no_ack_use_min(txrc)) {
7301 + __rate_control_send_low(txrc->hw, sband, pubsta, info);
7302
7303 - if (!sta && txrc->bss) {
7304 + if (!pubsta && txrc->bss) {
7305 mcast_rate = txrc->bss_conf->mcast_rate[sband->band];
7306 if (mcast_rate > 0) {
7307 info->control.rates[0].idx = mcast_rate - 1;
7308 return true;
7309 }
7310 + use_basicrate = true;
7311 + } else if (pubsta) {
7312 + sta = container_of(pubsta, struct sta_info, sta);
7313 + if (ieee80211_vif_is_mesh(&sta->sdata->vif))
7314 + use_basicrate = true;
7315 + }
7316
7317 - rc_send_low_broadcast(&info->control.rates[0].idx,
7318 + if (use_basicrate)
7319 + rc_send_low_basicrate(&info->control.rates[0].idx,
7320 txrc->bss_conf->basic_rates,
7321 sband);
7322 - }
7323 +
7324 return true;
7325 }
7326 return false;
7327 --- a/drivers/net/wireless/ath/ath9k/Kconfig
7328 +++ b/drivers/net/wireless/ath/ath9k/Kconfig
7329 @@ -60,7 +60,7 @@ config ATH9K_AHB
7330
7331 config ATH9K_DEBUGFS
7332 bool "Atheros ath9k debugging"
7333 - depends on ATH9K
7334 + depends on ATH9K && DEBUG_FS
7335 select MAC80211_DEBUGFS
7336 depends on RELAY
7337 ---help---
7338 --- a/drivers/net/wireless/ath/ath9k/ar9002_hw.c
7339 +++ b/drivers/net/wireless/ath/ath9k/ar9002_hw.c
7340 @@ -269,13 +269,12 @@ static void ar9002_hw_configpcipowersave
7341 if (ah->config.pcie_waen & AR_WA_D3_L1_DISABLE)
7342 val |= AR_WA_D3_L1_DISABLE;
7343 } else {
7344 - if (((AR_SREV_9285(ah) ||
7345 - AR_SREV_9271(ah) ||
7346 - AR_SREV_9287(ah)) &&
7347 - (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)) ||
7348 - (AR_SREV_9280(ah) &&
7349 - (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE))) {
7350 - val |= AR_WA_D3_L1_DISABLE;
7351 + if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) {
7352 + if (AR9285_WA_DEFAULT & AR_WA_D3_L1_DISABLE)
7353 + val |= AR_WA_D3_L1_DISABLE;
7354 + } else if (AR_SREV_9280(ah)) {
7355 + if (AR9280_WA_DEFAULT & AR_WA_D3_L1_DISABLE)
7356 + val |= AR_WA_D3_L1_DISABLE;
7357 }
7358 }
7359
7360 @@ -297,24 +296,18 @@ static void ar9002_hw_configpcipowersave
7361 } else {
7362 if (ah->config.pcie_waen) {
7363 val = ah->config.pcie_waen;
7364 - if (!power_off)
7365 - val &= (~AR_WA_D3_L1_DISABLE);
7366 + val &= (~AR_WA_D3_L1_DISABLE);
7367 } else {
7368 - if (AR_SREV_9285(ah) ||
7369 - AR_SREV_9271(ah) ||
7370 - AR_SREV_9287(ah)) {
7371 + if (AR_SREV_9285(ah) || AR_SREV_9271(ah) || AR_SREV_9287(ah)) {
7372 val = AR9285_WA_DEFAULT;
7373 - if (!power_off)
7374 - val &= (~AR_WA_D3_L1_DISABLE);
7375 - }
7376 - else if (AR_SREV_9280(ah)) {
7377 + val &= (~AR_WA_D3_L1_DISABLE);
7378 + } else if (AR_SREV_9280(ah)) {
7379 /*
7380 * For AR9280 chips, bit 22 of 0x4004
7381 * needs to be set.
7382 */
7383 val = AR9280_WA_DEFAULT;
7384 - if (!power_off)
7385 - val &= (~AR_WA_D3_L1_DISABLE);
7386 + val &= (~AR_WA_D3_L1_DISABLE);
7387 } else {
7388 val = AR_WA_DEFAULT;
7389 }
7390 --- a/drivers/net/wireless/ath/ath9k/ar9003_hw.c
7391 +++ b/drivers/net/wireless/ath/ath9k/ar9003_hw.c
7392 @@ -153,7 +153,7 @@ static void ar9003_hw_init_mode_regs(str
7393 if (!ah->is_clk_25mhz)
7394 INIT_INI_ARRAY(&ah->iniAdditional,
7395 ar9340_1p0_radio_core_40M);
7396 - } else if (AR_SREV_9485_11(ah)) {
7397 + } else if (AR_SREV_9485_11_OR_LATER(ah)) {
7398 /* mac */
7399 INIT_INI_ARRAY(&ah->iniMac[ATH_INI_CORE],
7400 ar9485_1_1_mac_core);
7401 @@ -424,7 +424,7 @@ static void ar9003_tx_gain_table_mode0(s
7402 else if (AR_SREV_9340(ah))
7403 INIT_INI_ARRAY(&ah->iniModesTxGain,
7404 ar9340Modes_lowest_ob_db_tx_gain_table_1p0);
7405 - else if (AR_SREV_9485_11(ah))
7406 + else if (AR_SREV_9485_11_OR_LATER(ah))
7407 INIT_INI_ARRAY(&ah->iniModesTxGain,
7408 ar9485_modes_lowest_ob_db_tx_gain_1_1);
7409 else if (AR_SREV_9550(ah))
7410 @@ -458,7 +458,7 @@ static void ar9003_tx_gain_table_mode1(s
7411 else if (AR_SREV_9340(ah))
7412 INIT_INI_ARRAY(&ah->iniModesTxGain,
7413 ar9340Modes_high_ob_db_tx_gain_table_1p0);
7414 - else if (AR_SREV_9485_11(ah))
7415 + else if (AR_SREV_9485_11_OR_LATER(ah))
7416 INIT_INI_ARRAY(&ah->iniModesTxGain,
7417 ar9485Modes_high_ob_db_tx_gain_1_1);
7418 else if (AR_SREV_9580(ah))
7419 @@ -492,7 +492,7 @@ static void ar9003_tx_gain_table_mode2(s
7420 else if (AR_SREV_9340(ah))
7421 INIT_INI_ARRAY(&ah->iniModesTxGain,
7422 ar9340Modes_low_ob_db_tx_gain_table_1p0);
7423 - else if (AR_SREV_9485_11(ah))
7424 + else if (AR_SREV_9485_11_OR_LATER(ah))
7425 INIT_INI_ARRAY(&ah->iniModesTxGain,
7426 ar9485Modes_low_ob_db_tx_gain_1_1);
7427 else if (AR_SREV_9580(ah))
7428 @@ -517,7 +517,7 @@ static void ar9003_tx_gain_table_mode3(s
7429 else if (AR_SREV_9340(ah))
7430 INIT_INI_ARRAY(&ah->iniModesTxGain,
7431 ar9340Modes_high_power_tx_gain_table_1p0);
7432 - else if (AR_SREV_9485_11(ah))
7433 + else if (AR_SREV_9485_11_OR_LATER(ah))
7434 INIT_INI_ARRAY(&ah->iniModesTxGain,
7435 ar9485Modes_high_power_tx_gain_1_1);
7436 else if (AR_SREV_9580(ah))
7437 @@ -552,7 +552,7 @@ static void ar9003_tx_gain_table_mode4(s
7438
7439 static void ar9003_tx_gain_table_mode5(struct ath_hw *ah)
7440 {
7441 - if (AR_SREV_9485_11(ah))
7442 + if (AR_SREV_9485_11_OR_LATER(ah))
7443 INIT_INI_ARRAY(&ah->iniModesTxGain,
7444 ar9485Modes_green_ob_db_tx_gain_1_1);
7445 else if (AR_SREV_9340(ah))
7446 @@ -571,7 +571,7 @@ static void ar9003_tx_gain_table_mode6(s
7447 if (AR_SREV_9340(ah))
7448 INIT_INI_ARRAY(&ah->iniModesTxGain,
7449 ar9340Modes_low_ob_db_and_spur_tx_gain_table_1p0);
7450 - else if (AR_SREV_9485_11(ah))
7451 + else if (AR_SREV_9485_11_OR_LATER(ah))
7452 INIT_INI_ARRAY(&ah->iniModesTxGain,
7453 ar9485Modes_green_spur_ob_db_tx_gain_1_1);
7454 else if (AR_SREV_9580(ah))
7455 @@ -611,7 +611,7 @@ static void ar9003_rx_gain_table_mode0(s
7456 else if (AR_SREV_9340(ah))
7457 INIT_INI_ARRAY(&ah->iniModesRxGain,
7458 ar9340Common_rx_gain_table_1p0);
7459 - else if (AR_SREV_9485_11(ah))
7460 + else if (AR_SREV_9485_11_OR_LATER(ah))
7461 INIT_INI_ARRAY(&ah->iniModesRxGain,
7462 ar9485_common_rx_gain_1_1);
7463 else if (AR_SREV_9550(ah)) {
7464 @@ -644,7 +644,7 @@ static void ar9003_rx_gain_table_mode1(s
7465 else if (AR_SREV_9340(ah))
7466 INIT_INI_ARRAY(&ah->iniModesRxGain,
7467 ar9340Common_wo_xlna_rx_gain_table_1p0);
7468 - else if (AR_SREV_9485_11(ah))
7469 + else if (AR_SREV_9485_11_OR_LATER(ah))
7470 INIT_INI_ARRAY(&ah->iniModesRxGain,
7471 ar9485Common_wo_xlna_rx_gain_1_1);
7472 else if (AR_SREV_9462_21(ah))
7473 @@ -745,16 +745,25 @@ static void ar9003_hw_init_mode_gain_reg
7474 static void ar9003_hw_configpcipowersave(struct ath_hw *ah,
7475 bool power_off)
7476 {
7477 + /*
7478 + * Increase L1 Entry Latency. Some WB222 boards don't have
7479 + * this change in eeprom/OTP.
7480 + *
7481 + */
7482 + if (AR_SREV_9462(ah)) {
7483 + u32 val = ah->config.aspm_l1_fix;
7484 + if ((val & 0xff000000) == 0x17000000) {
7485 + val &= 0x00ffffff;
7486 + val |= 0x27000000;
7487 + REG_WRITE(ah, 0x570c, val);
7488 + }
7489 + }
7490 +
7491 /* Nothing to do on restore for 11N */
7492 if (!power_off /* !restore */) {
7493 /* set bit 19 to allow forcing of pcie core into L1 state */
7494 REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PCIE_PM_CTRL_ENA);
7495 -
7496 - /* Several PCIe massages to ensure proper behaviour */
7497 - if (ah->config.pcie_waen)
7498 - REG_WRITE(ah, AR_WA, ah->config.pcie_waen);
7499 - else
7500 - REG_WRITE(ah, AR_WA, ah->WARegVal);
7501 + REG_WRITE(ah, AR_WA, ah->WARegVal);
7502 }
7503
7504 /*
7505 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
7506 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
7507 @@ -491,6 +491,7 @@ int ath9k_hw_process_rxdesc_edma(struct
7508 rxs->rs_rate = MS(rxsp->status1, AR_RxRate);
7509 rxs->rs_more = (rxsp->status2 & AR_RxMore) ? 1 : 0;
7510
7511 + rxs->rs_firstaggr = (rxsp->status11 & AR_RxFirstAggr) ? 1 : 0;
7512 rxs->rs_isaggr = (rxsp->status11 & AR_RxAggr) ? 1 : 0;
7513 rxs->rs_moreaggr = (rxsp->status11 & AR_RxMoreAggr) ? 1 : 0;
7514 rxs->rs_antenna = (MS(rxsp->status4, AR_RxAntenna) & 0x7);
7515 --- a/drivers/net/wireless/ath/ath9k/common.c
7516 +++ b/drivers/net/wireless/ath/ath9k/common.c
7517 @@ -49,37 +49,40 @@ int ath9k_cmn_get_hw_crypto_keytype(stru
7518 }
7519 EXPORT_SYMBOL(ath9k_cmn_get_hw_crypto_keytype);
7520
7521 -static u32 ath9k_get_extchanmode(struct ieee80211_channel *chan,
7522 - enum nl80211_channel_type channel_type)
7523 +static u32 ath9k_get_extchanmode(struct cfg80211_chan_def *chandef)
7524 {
7525 u32 chanmode = 0;
7526
7527 - switch (chan->band) {
7528 + switch (chandef->chan->band) {
7529 case IEEE80211_BAND_2GHZ:
7530 - switch (channel_type) {
7531 - case NL80211_CHAN_NO_HT:
7532 - case NL80211_CHAN_HT20:
7533 + switch (chandef->width) {
7534 + case NL80211_CHAN_WIDTH_20_NOHT:
7535 + case NL80211_CHAN_WIDTH_20:
7536 chanmode = CHANNEL_G_HT20;
7537 break;
7538 - case NL80211_CHAN_HT40PLUS:
7539 - chanmode = CHANNEL_G_HT40PLUS;
7540 + case NL80211_CHAN_WIDTH_40:
7541 + if (chandef->center_freq1 > chandef->chan->center_freq)
7542 + chanmode = CHANNEL_G_HT40PLUS;
7543 + else
7544 + chanmode = CHANNEL_G_HT40MINUS;
7545 break;
7546 - case NL80211_CHAN_HT40MINUS:
7547 - chanmode = CHANNEL_G_HT40MINUS;
7548 + default:
7549 break;
7550 }
7551 break;
7552 case IEEE80211_BAND_5GHZ:
7553 - switch (channel_type) {
7554 - case NL80211_CHAN_NO_HT:
7555 - case NL80211_CHAN_HT20:
7556 + switch (chandef->width) {
7557 + case NL80211_CHAN_WIDTH_20_NOHT:
7558 + case NL80211_CHAN_WIDTH_20:
7559 chanmode = CHANNEL_A_HT20;
7560 break;
7561 - case NL80211_CHAN_HT40PLUS:
7562 - chanmode = CHANNEL_A_HT40PLUS;
7563 + case NL80211_CHAN_WIDTH_40:
7564 + if (chandef->center_freq1 > chandef->chan->center_freq)
7565 + chanmode = CHANNEL_A_HT40PLUS;
7566 + else
7567 + chanmode = CHANNEL_A_HT40MINUS;
7568 break;
7569 - case NL80211_CHAN_HT40MINUS:
7570 - chanmode = CHANNEL_A_HT40MINUS;
7571 + default:
7572 break;
7573 }
7574 break;
7575 @@ -94,13 +97,12 @@ static u32 ath9k_get_extchanmode(struct
7576 * Update internal channel flags.
7577 */
7578 void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan,
7579 - struct ieee80211_channel *chan,
7580 - enum nl80211_channel_type channel_type)
7581 + struct cfg80211_chan_def *chandef)
7582 {
7583 - ichan->channel = chan->center_freq;
7584 - ichan->chan = chan;
7585 + ichan->channel = chandef->chan->center_freq;
7586 + ichan->chan = chandef->chan;
7587
7588 - if (chan->band == IEEE80211_BAND_2GHZ) {
7589 + if (chandef->chan->band == IEEE80211_BAND_2GHZ) {
7590 ichan->chanmode = CHANNEL_G;
7591 ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM;
7592 } else {
7593 @@ -108,8 +110,22 @@ void ath9k_cmn_update_ichannel(struct at
7594 ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
7595 }
7596
7597 - if (channel_type != NL80211_CHAN_NO_HT)
7598 - ichan->chanmode = ath9k_get_extchanmode(chan, channel_type);
7599 + switch (chandef->width) {
7600 + case NL80211_CHAN_WIDTH_5:
7601 + ichan->channelFlags |= CHANNEL_QUARTER;
7602 + break;
7603 + case NL80211_CHAN_WIDTH_10:
7604 + ichan->channelFlags |= CHANNEL_HALF;
7605 + break;
7606 + case NL80211_CHAN_WIDTH_20_NOHT:
7607 + break;
7608 + case NL80211_CHAN_WIDTH_20:
7609 + case NL80211_CHAN_WIDTH_40:
7610 + ichan->chanmode = ath9k_get_extchanmode(chandef);
7611 + break;
7612 + default:
7613 + WARN_ON(1);
7614 + }
7615 }
7616 EXPORT_SYMBOL(ath9k_cmn_update_ichannel);
7617
7618 @@ -125,8 +141,7 @@ struct ath9k_channel *ath9k_cmn_get_curc
7619
7620 chan_idx = curchan->hw_value;
7621 channel = &ah->channels[chan_idx];
7622 - ath9k_cmn_update_ichannel(channel, curchan,
7623 - cfg80211_get_chandef_type(&hw->conf.chandef));
7624 + ath9k_cmn_update_ichannel(channel, &hw->conf.chandef);
7625
7626 return channel;
7627 }
7628 --- a/drivers/net/wireless/ath/ath9k/common.h
7629 +++ b/drivers/net/wireless/ath/ath9k/common.h
7630 @@ -44,8 +44,7 @@
7631
7632 int ath9k_cmn_get_hw_crypto_keytype(struct sk_buff *skb);
7633 void ath9k_cmn_update_ichannel(struct ath9k_channel *ichan,
7634 - struct ieee80211_channel *chan,
7635 - enum nl80211_channel_type channel_type);
7636 + struct cfg80211_chan_def *chandef);
7637 struct ath9k_channel *ath9k_cmn_get_curchannel(struct ieee80211_hw *hw,
7638 struct ath_hw *ah);
7639 int ath9k_cmn_count_streams(unsigned int chainmask, int max);
7640 --- a/drivers/net/wireless/ath/ath9k/hif_usb.c
7641 +++ b/drivers/net/wireless/ath/ath9k/hif_usb.c
7642 @@ -115,10 +115,10 @@ static int hif_usb_send_regout(struct hi
7643 cmd->skb = skb;
7644 cmd->hif_dev = hif_dev;
7645
7646 - usb_fill_bulk_urb(urb, hif_dev->udev,
7647 - usb_sndbulkpipe(hif_dev->udev, USB_REG_OUT_PIPE),
7648 + usb_fill_int_urb(urb, hif_dev->udev,
7649 + usb_sndintpipe(hif_dev->udev, USB_REG_OUT_PIPE),
7650 skb->data, skb->len,
7651 - hif_usb_regout_cb, cmd);
7652 + hif_usb_regout_cb, cmd, 1);
7653
7654 usb_anchor_urb(urb, &hif_dev->regout_submitted);
7655 ret = usb_submit_urb(urb, GFP_KERNEL);
7656 @@ -723,11 +723,11 @@ static void ath9k_hif_usb_reg_in_cb(stru
7657 return;
7658 }
7659
7660 - usb_fill_bulk_urb(urb, hif_dev->udev,
7661 - usb_rcvbulkpipe(hif_dev->udev,
7662 + usb_fill_int_urb(urb, hif_dev->udev,
7663 + usb_rcvintpipe(hif_dev->udev,
7664 USB_REG_IN_PIPE),
7665 nskb->data, MAX_REG_IN_BUF_SIZE,
7666 - ath9k_hif_usb_reg_in_cb, nskb);
7667 + ath9k_hif_usb_reg_in_cb, nskb, 1);
7668 }
7669
7670 resubmit:
7671 @@ -909,11 +909,11 @@ static int ath9k_hif_usb_alloc_reg_in_ur
7672 goto err_skb;
7673 }
7674
7675 - usb_fill_bulk_urb(urb, hif_dev->udev,
7676 - usb_rcvbulkpipe(hif_dev->udev,
7677 + usb_fill_int_urb(urb, hif_dev->udev,
7678 + usb_rcvintpipe(hif_dev->udev,
7679 USB_REG_IN_PIPE),
7680 skb->data, MAX_REG_IN_BUF_SIZE,
7681 - ath9k_hif_usb_reg_in_cb, skb);
7682 + ath9k_hif_usb_reg_in_cb, skb, 1);
7683
7684 /* Anchor URB */
7685 usb_anchor_urb(urb, &hif_dev->reg_in_submitted);
7686 @@ -1031,9 +1031,7 @@ static int ath9k_hif_usb_download_fw(str
7687
7688 static int ath9k_hif_usb_dev_init(struct hif_device_usb *hif_dev)
7689 {
7690 - struct usb_host_interface *alt = &hif_dev->interface->altsetting[0];
7691 - struct usb_endpoint_descriptor *endp;
7692 - int ret, idx;
7693 + int ret;
7694
7695 ret = ath9k_hif_usb_download_fw(hif_dev);
7696 if (ret) {
7697 @@ -1043,20 +1041,6 @@ static int ath9k_hif_usb_dev_init(struct
7698 return ret;
7699 }
7700
7701 - /* On downloading the firmware to the target, the USB descriptor of EP4
7702 - * is 'patched' to change the type of the endpoint to Bulk. This will
7703 - * bring down CPU usage during the scan period.
7704 - */
7705 - for (idx = 0; idx < alt->desc.bNumEndpoints; idx++) {
7706 - endp = &alt->endpoint[idx].desc;
7707 - if ((endp->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
7708 - == USB_ENDPOINT_XFER_INT) {
7709 - endp->bmAttributes &= ~USB_ENDPOINT_XFERTYPE_MASK;
7710 - endp->bmAttributes |= USB_ENDPOINT_XFER_BULK;
7711 - endp->bInterval = 0;
7712 - }
7713 - }
7714 -
7715 /* Alloc URBs */
7716 ret = ath9k_hif_usb_alloc_urbs(hif_dev);
7717 if (ret) {
7718 @@ -1268,7 +1252,7 @@ static void ath9k_hif_usb_reboot(struct
7719 if (!buf)
7720 return;
7721
7722 - ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, USB_REG_OUT_PIPE),
7723 + ret = usb_interrupt_msg(udev, usb_sndintpipe(udev, USB_REG_OUT_PIPE),
7724 buf, 4, NULL, HZ);
7725 if (ret)
7726 dev_err(&udev->dev, "ath9k_htc: USB reboot failed\n");
7727 --- a/drivers/net/wireless/ath/ath9k/htc_drv_main.c
7728 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_main.c
7729 @@ -1203,16 +1203,13 @@ static int ath9k_htc_config(struct ieee8
7730
7731 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) || chip_reset) {
7732 struct ieee80211_channel *curchan = hw->conf.chandef.chan;
7733 - enum nl80211_channel_type channel_type =
7734 - cfg80211_get_chandef_type(&hw->conf.chandef);
7735 int pos = curchan->hw_value;
7736
7737 ath_dbg(common, CONFIG, "Set channel: %d MHz\n",
7738 curchan->center_freq);
7739
7740 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
7741 - hw->conf.chandef.chan,
7742 - channel_type);
7743 + &hw->conf.chandef);
7744
7745 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
7746 ath_err(common, "Unable to set channel\n");
7747 --- a/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
7748 +++ b/drivers/net/wireless/ath/ath9k/htc_drv_txrx.c
7749 @@ -448,6 +448,7 @@ static void ath9k_htc_tx_process(struct
7750 struct ieee80211_conf *cur_conf = &priv->hw->conf;
7751 bool txok;
7752 int slot;
7753 + int hdrlen, padsize;
7754
7755 slot = strip_drv_header(priv, skb);
7756 if (slot < 0) {
7757 @@ -504,6 +505,15 @@ send_mac80211:
7758
7759 ath9k_htc_tx_clear_slot(priv, slot);
7760
7761 + /* Remove padding before handing frame back to mac80211 */
7762 + hdrlen = ieee80211_get_hdrlen_from_skb(skb);
7763 +
7764 + padsize = hdrlen & 3;
7765 + if (padsize && skb->len > hdrlen + padsize) {
7766 + memmove(skb->data + padsize, skb->data, hdrlen);
7767 + skb_pull(skb, padsize);
7768 + }
7769 +
7770 /* Send status to mac80211 */
7771 ieee80211_tx_status(priv->hw, skb);
7772 }
7773 --- a/drivers/net/wireless/ath/ath9k/link.c
7774 +++ b/drivers/net/wireless/ath/ath9k/link.c
7775 @@ -41,7 +41,7 @@ void ath_tx_complete_poll_work(struct wo
7776 txq->axq_tx_inprogress = true;
7777 }
7778 }
7779 - ath_txq_unlock_complete(sc, txq);
7780 + ath_txq_unlock(sc, txq);
7781 }
7782
7783 if (needreset) {
7784 --- a/drivers/net/wireless/ath/ath9k/mac.c
7785 +++ b/drivers/net/wireless/ath/ath9k/mac.c
7786 @@ -583,9 +583,9 @@ int ath9k_hw_rxprocdesc(struct ath_hw *a
7787 rs->rs_rate = MS(ads.ds_rxstatus0, AR_RxRate);
7788 rs->rs_more = (ads.ds_rxstatus1 & AR_RxMore) ? 1 : 0;
7789
7790 + rs->rs_firstaggr = (ads.ds_rxstatus8 & AR_RxFirstAggr) ? 1 : 0;
7791 rs->rs_isaggr = (ads.ds_rxstatus8 & AR_RxAggr) ? 1 : 0;
7792 - rs->rs_moreaggr =
7793 - (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
7794 + rs->rs_moreaggr = (ads.ds_rxstatus8 & AR_RxMoreAggr) ? 1 : 0;
7795 rs->rs_antenna = MS(ads.ds_rxstatus3, AR_RxAntenna);
7796
7797 /* directly mapped flags for ieee80211_rx_status */
7798 --- a/drivers/net/wireless/ath/ath9k/mac.h
7799 +++ b/drivers/net/wireless/ath/ath9k/mac.h
7800 @@ -140,6 +140,7 @@ struct ath_rx_status {
7801 int8_t rs_rssi_ext1;
7802 int8_t rs_rssi_ext2;
7803 u8 rs_isaggr;
7804 + u8 rs_firstaggr;
7805 u8 rs_moreaggr;
7806 u8 rs_num_delims;
7807 u8 rs_flags;
7808 @@ -569,6 +570,7 @@ struct ar5416_desc {
7809 #define AR_RxAggr 0x00020000
7810 #define AR_PostDelimCRCErr 0x00040000
7811 #define AR_RxStatusRsvd71 0x3ff80000
7812 +#define AR_RxFirstAggr 0x20000000
7813 #define AR_DecryptBusyErr 0x40000000
7814 #define AR_KeyMiss 0x80000000
7815
7816 --- a/drivers/net/wireless/ath/ath9k/rc.c
7817 +++ b/drivers/net/wireless/ath/ath9k/rc.c
7818 @@ -1324,8 +1324,8 @@ static void ath_rate_update(void *priv,
7819 ath_rc_init(sc, priv_sta);
7820
7821 ath_dbg(ath9k_hw_common(sc->sc_ah), CONFIG,
7822 - "Operating HT Bandwidth changed to: %d\n",
7823 - cfg80211_get_chandef_type(&sc->hw->conf.chandef));
7824 + "Operating Bandwidth changed to: %d\n",
7825 + sc->hw->conf.chandef.width);
7826 }
7827 }
7828
7829 --- a/drivers/net/wireless/ath/ath9k/reg.h
7830 +++ b/drivers/net/wireless/ath/ath9k/reg.h
7831 @@ -893,9 +893,9 @@
7832
7833 #define AR_SREV_9485(_ah) \
7834 (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9485))
7835 -#define AR_SREV_9485_11(_ah) \
7836 - (AR_SREV_9485(_ah) && \
7837 - ((_ah)->hw_version.macRev == AR_SREV_REVISION_9485_11))
7838 +#define AR_SREV_9485_11_OR_LATER(_ah) \
7839 + (((_ah)->hw_version.macVersion == AR_SREV_VERSION_9485) && \
7840 + ((_ah)->hw_version.macRev >= AR_SREV_REVISION_9485_11))
7841 #define AR_SREV_9485_OR_LATER(_ah) \
7842 (((_ah)->hw_version.macVersion >= AR_SREV_VERSION_9485))
7843
7844 --- a/net/mac80211/main.c
7845 +++ b/net/mac80211/main.c
7846 @@ -101,7 +101,7 @@ static u32 ieee80211_hw_conf_chan(struct
7847 struct ieee80211_sub_if_data *sdata;
7848 struct cfg80211_chan_def chandef = {};
7849 u32 changed = 0;
7850 - int power;
7851 + int power = 0;
7852 u32 offchannel_flag;
7853
7854 offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
7855 @@ -155,16 +155,16 @@ static u32 ieee80211_hw_conf_chan(struct
7856 changed |= IEEE80211_CONF_CHANGE_SMPS;
7857 }
7858
7859 - power = chandef.chan->max_power;
7860 -
7861 rcu_read_lock();
7862 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
7863 if (!rcu_access_pointer(sdata->vif.chanctx_conf))
7864 continue;
7865 - power = min(power, sdata->vif.bss_conf.txpower);
7866 + power = max(power, sdata->vif.bss_conf.txpower);
7867 }
7868 rcu_read_unlock();
7869
7870 + power = min(power, chandef.chan->max_power);
7871 +
7872 if (local->hw.conf.power_level != power) {
7873 changed |= IEEE80211_CONF_CHANGE_POWER;
7874 local->hw.conf.power_level = power;
7875 --- a/net/mac80211/status.c
7876 +++ b/net/mac80211/status.c
7877 @@ -180,6 +180,9 @@ static void ieee80211_frame_acked(struct
7878 struct ieee80211_local *local = sta->local;
7879 struct ieee80211_sub_if_data *sdata = sta->sdata;
7880
7881 + if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
7882 + sta->last_rx = jiffies;
7883 +
7884 if (ieee80211_is_data_qos(mgmt->frame_control)) {
7885 struct ieee80211_hdr *hdr = (void *) skb->data;
7886 u8 *qc = ieee80211_get_qos_ctl(hdr);