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