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