xref: /openbmc/linux/net/mac80211/ht.c (revision 1b0b4c4238c0bdcf1a8ffa4c5431ec1d3fb9a345)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
244d414dbSJohannes Berg /*
344d414dbSJohannes Berg  * HT handling
444d414dbSJohannes Berg  *
544d414dbSJohannes Berg  * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
6bacac545SJohannes Berg  * Copyright 2002-2005, Instant802 Networks, Inc.
7bacac545SJohannes Berg  * Copyright 2005-2006, Devicescape Software, Inc.
844d414dbSJohannes Berg  * Copyright 2006-2007	Jiri Benc <jbenc@suse.cz>
944d414dbSJohannes Berg  * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
10cfcdbde3SJohannes Berg  * Copyright 2007-2010, Intel Corporation
117a7c0a64SJohannes Berg  * Copyright 2017	Intel Deutschland GmbH
121444f589SJohannes Berg  * Copyright(c) 2020-2023 Intel Corporation
1344d414dbSJohannes Berg  */
1444d414dbSJohannes Berg 
1544d414dbSJohannes Berg #include <linux/ieee80211.h>
16bc3b2d7fSPaul Gortmaker #include <linux/export.h>
1744d414dbSJohannes Berg #include <net/mac80211.h>
1844d414dbSJohannes Berg #include "ieee80211_i.h"
1981cb7623SSujith #include "rate.h"
2044d414dbSJohannes Berg 
__check_htcap_disable(struct ieee80211_ht_cap * ht_capa,struct ieee80211_ht_cap * ht_capa_mask,struct ieee80211_sta_ht_cap * ht_cap,u16 flag)21822854b0SSimon Wunderlich static void __check_htcap_disable(struct ieee80211_ht_cap *ht_capa,
22822854b0SSimon Wunderlich 				  struct ieee80211_ht_cap *ht_capa_mask,
23ef96a842SBen Greear 				  struct ieee80211_sta_ht_cap *ht_cap,
24ef96a842SBen Greear 				  u16 flag)
25ef96a842SBen Greear {
26ef96a842SBen Greear 	__le16 le_flag = cpu_to_le16(flag);
27822854b0SSimon Wunderlich 	if (ht_capa_mask->cap_info & le_flag) {
28822854b0SSimon Wunderlich 		if (!(ht_capa->cap_info & le_flag))
29ef96a842SBen Greear 			ht_cap->cap &= ~flag;
30ef96a842SBen Greear 	}
31ef96a842SBen Greear }
32ef96a842SBen Greear 
__check_htcap_enable(struct ieee80211_ht_cap * ht_capa,struct ieee80211_ht_cap * ht_capa_mask,struct ieee80211_sta_ht_cap * ht_cap,u16 flag)339a07bf50SJouni Malinen static void __check_htcap_enable(struct ieee80211_ht_cap *ht_capa,
349a07bf50SJouni Malinen 				  struct ieee80211_ht_cap *ht_capa_mask,
359a07bf50SJouni Malinen 				  struct ieee80211_sta_ht_cap *ht_cap,
369a07bf50SJouni Malinen 				  u16 flag)
379a07bf50SJouni Malinen {
389a07bf50SJouni Malinen 	__le16 le_flag = cpu_to_le16(flag);
399a07bf50SJouni Malinen 
409a07bf50SJouni Malinen 	if ((ht_capa_mask->cap_info & le_flag) &&
419a07bf50SJouni Malinen 	    (ht_capa->cap_info & le_flag))
429a07bf50SJouni Malinen 		ht_cap->cap |= flag;
439a07bf50SJouni Malinen }
449a07bf50SJouni Malinen 
ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data * sdata,struct ieee80211_sta_ht_cap * ht_cap)45ef96a842SBen Greear void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
46ef96a842SBen Greear 				     struct ieee80211_sta_ht_cap *ht_cap)
47ef96a842SBen Greear {
48822854b0SSimon Wunderlich 	struct ieee80211_ht_cap *ht_capa, *ht_capa_mask;
49822854b0SSimon Wunderlich 	u8 *scaps, *smask;
50ef96a842SBen Greear 	int i;
51ef96a842SBen Greear 
52e1a0c6b3SJohannes Berg 	if (!ht_cap->ht_supported)
53e1a0c6b3SJohannes Berg 		return;
54e1a0c6b3SJohannes Berg 
55822854b0SSimon Wunderlich 	switch (sdata->vif.type) {
56822854b0SSimon Wunderlich 	case NL80211_IFTYPE_STATION:
57822854b0SSimon Wunderlich 		ht_capa = &sdata->u.mgd.ht_capa;
58822854b0SSimon Wunderlich 		ht_capa_mask = &sdata->u.mgd.ht_capa_mask;
59822854b0SSimon Wunderlich 		break;
60822854b0SSimon Wunderlich 	case NL80211_IFTYPE_ADHOC:
61822854b0SSimon Wunderlich 		ht_capa = &sdata->u.ibss.ht_capa;
62822854b0SSimon Wunderlich 		ht_capa_mask = &sdata->u.ibss.ht_capa_mask;
63822854b0SSimon Wunderlich 		break;
64822854b0SSimon Wunderlich 	default:
65822854b0SSimon Wunderlich 		WARN_ON_ONCE(1);
66822854b0SSimon Wunderlich 		return;
67822854b0SSimon Wunderlich 	}
68822854b0SSimon Wunderlich 
69822854b0SSimon Wunderlich 	scaps = (u8 *)(&ht_capa->mcs.rx_mask);
70822854b0SSimon Wunderlich 	smask = (u8 *)(&ht_capa_mask->mcs.rx_mask);
71822854b0SSimon Wunderlich 
72ef96a842SBen Greear 	/* NOTE:  If you add more over-rides here, update register_hw
739a07bf50SJouni Malinen 	 * ht_capa_mod_mask logic in main.c as well.
74ef96a842SBen Greear 	 * And, if this method can ever change ht_cap.ht_supported, fix
75ef96a842SBen Greear 	 * the check in ieee80211_add_ht_ie.
76ef96a842SBen Greear 	 */
77ef96a842SBen Greear 
78ef96a842SBen Greear 	/* check for HT over-rides, MCS rates first. */
79ef96a842SBen Greear 	for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
80ef96a842SBen Greear 		u8 m = smask[i];
81ef96a842SBen Greear 		ht_cap->mcs.rx_mask[i] &= ~m; /* turn off all masked bits */
82ef96a842SBen Greear 		/* Add back rates that are supported */
83ef96a842SBen Greear 		ht_cap->mcs.rx_mask[i] |= (m & scaps[i]);
84ef96a842SBen Greear 	}
85ef96a842SBen Greear 
86ef96a842SBen Greear 	/* Force removal of HT-40 capabilities? */
87822854b0SSimon Wunderlich 	__check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
88822854b0SSimon Wunderlich 			      IEEE80211_HT_CAP_SUP_WIDTH_20_40);
89822854b0SSimon Wunderlich 	__check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
90822854b0SSimon Wunderlich 			      IEEE80211_HT_CAP_SGI_40);
91ef96a842SBen Greear 
92bc0784d9SBen Greear 	/* Allow user to disable SGI-20 (SGI-40 is handled above) */
93822854b0SSimon Wunderlich 	__check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
94822854b0SSimon Wunderlich 			      IEEE80211_HT_CAP_SGI_20);
95bc0784d9SBen Greear 
96ef96a842SBen Greear 	/* Allow user to disable the max-AMSDU bit. */
97822854b0SSimon Wunderlich 	__check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
98822854b0SSimon Wunderlich 			      IEEE80211_HT_CAP_MAX_AMSDU);
99ef96a842SBen Greear 
100a2e7495dSPawel Kulakowski 	/* Allow user to disable LDPC */
101a2e7495dSPawel Kulakowski 	__check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
102a2e7495dSPawel Kulakowski 			      IEEE80211_HT_CAP_LDPC_CODING);
103a2e7495dSPawel Kulakowski 
1049a07bf50SJouni Malinen 	/* Allow user to enable 40 MHz intolerant bit. */
1059a07bf50SJouni Malinen 	__check_htcap_enable(ht_capa, ht_capa_mask, ht_cap,
1069a07bf50SJouni Malinen 			     IEEE80211_HT_CAP_40MHZ_INTOLERANT);
1079a07bf50SJouni Malinen 
108d9bb4108SSergey Matyukevich 	/* Allow user to enable TX STBC bit  */
109d9bb4108SSergey Matyukevich 	__check_htcap_enable(ht_capa, ht_capa_mask, ht_cap,
110d9bb4108SSergey Matyukevich 			     IEEE80211_HT_CAP_TX_STBC);
111d9bb4108SSergey Matyukevich 
112d9bb4108SSergey Matyukevich 	/* Allow user to configure RX STBC bits */
113e9f33a8fSJohannes Berg 	if (ht_capa_mask->cap_info & cpu_to_le16(IEEE80211_HT_CAP_RX_STBC))
114e9f33a8fSJohannes Berg 		ht_cap->cap |= le16_to_cpu(ht_capa->cap_info) &
115e9f33a8fSJohannes Berg 					IEEE80211_HT_CAP_RX_STBC;
116d9bb4108SSergey Matyukevich 
117ef96a842SBen Greear 	/* Allow user to decrease AMPDU factor */
118822854b0SSimon Wunderlich 	if (ht_capa_mask->ampdu_params_info &
119ef96a842SBen Greear 	    IEEE80211_HT_AMPDU_PARM_FACTOR) {
120822854b0SSimon Wunderlich 		u8 n = ht_capa->ampdu_params_info &
121822854b0SSimon Wunderlich 		       IEEE80211_HT_AMPDU_PARM_FACTOR;
122ef96a842SBen Greear 		if (n < ht_cap->ampdu_factor)
123ef96a842SBen Greear 			ht_cap->ampdu_factor = n;
124ef96a842SBen Greear 	}
125ef96a842SBen Greear 
126ef96a842SBen Greear 	/* Allow the user to increase AMPDU density. */
127822854b0SSimon Wunderlich 	if (ht_capa_mask->ampdu_params_info &
128ef96a842SBen Greear 	    IEEE80211_HT_AMPDU_PARM_DENSITY) {
129822854b0SSimon Wunderlich 		u8 n = (ht_capa->ampdu_params_info &
130ef96a842SBen Greear 			IEEE80211_HT_AMPDU_PARM_DENSITY)
131ef96a842SBen Greear 			>> IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT;
132ef96a842SBen Greear 		if (n > ht_cap->ampdu_density)
133ef96a842SBen Greear 			ht_cap->ampdu_density = n;
134ef96a842SBen Greear 	}
135ef96a842SBen Greear }
136ef96a842SBen Greear 
137ef96a842SBen Greear 
ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data * sdata,struct ieee80211_supported_band * sband,const struct ieee80211_ht_cap * ht_cap_ie,struct link_sta_info * link_sta)138e1a0c6b3SJohannes Berg bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
139ef96a842SBen Greear 				       struct ieee80211_supported_band *sband,
1404a3cb702SJohannes Berg 				       const struct ieee80211_ht_cap *ht_cap_ie,
141c71420dbSJohannes Berg 				       struct link_sta_info *link_sta)
14244d414dbSJohannes Berg {
143d8675a63SJohannes Berg 	struct ieee80211_bss_conf *link_conf;
144c71420dbSJohannes Berg 	struct sta_info *sta = link_sta->sta;
145c07270b6SJohannes Berg 	struct ieee80211_sta_ht_cap ht_cap, own_cap;
146ae5eb026SJohannes Berg 	u8 ampdu_info, tx_mcs_set_cap;
147ae5eb026SJohannes Berg 	int i, max_tx_streams;
148e1a0c6b3SJohannes Berg 	bool changed;
149e1a0c6b3SJohannes Berg 	enum ieee80211_sta_rx_bandwidth bw;
150d8675a63SJohannes Berg 	enum nl80211_chan_width width;
15144d414dbSJohannes Berg 
152e1a0c6b3SJohannes Berg 	memset(&ht_cap, 0, sizeof(ht_cap));
15344d414dbSJohannes Berg 
15415804e3eSChristian Lamparter 	if (!ht_cap_ie || !sband->ht_cap.ht_supported)
155e1a0c6b3SJohannes Berg 		goto apply;
15644d414dbSJohannes Berg 
157e1a0c6b3SJohannes Berg 	ht_cap.ht_supported = true;
158ae5eb026SJohannes Berg 
159c07270b6SJohannes Berg 	own_cap = sband->ht_cap;
160c07270b6SJohannes Berg 
161c07270b6SJohannes Berg 	/*
162c07270b6SJohannes Berg 	 * If user has specified capability over-rides, take care
16313cc8a4aSArik Nemtsov 	 * of that if the station we're setting up is the AP or TDLS peer that
164c07270b6SJohannes Berg 	 * we advertised a restricted capability set to. Override
165c07270b6SJohannes Berg 	 * our own capabilities and then use those below.
166c07270b6SJohannes Berg 	 */
16713cc8a4aSArik Nemtsov 	if (sdata->vif.type == NL80211_IFTYPE_STATION ||
16813cc8a4aSArik Nemtsov 	    sdata->vif.type == NL80211_IFTYPE_ADHOC)
169c07270b6SJohannes Berg 		ieee80211_apply_htcap_overrides(sdata, &own_cap);
170c07270b6SJohannes Berg 
1719a418af5SJohannes Berg 	/*
1729a418af5SJohannes Berg 	 * The bits listed in this expression should be
1739a418af5SJohannes Berg 	 * the same for the peer and us, if the station
1749a418af5SJohannes Berg 	 * advertises more then we can't use those thus
1759a418af5SJohannes Berg 	 * we mask them out.
1769a418af5SJohannes Berg 	 */
177e1a0c6b3SJohannes Berg 	ht_cap.cap = le16_to_cpu(ht_cap_ie->cap_info) &
178c07270b6SJohannes Berg 		(own_cap.cap | ~(IEEE80211_HT_CAP_LDPC_CODING |
1799a418af5SJohannes Berg 				 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
1809a418af5SJohannes Berg 				 IEEE80211_HT_CAP_GRN_FLD |
1819a418af5SJohannes Berg 				 IEEE80211_HT_CAP_SGI_20 |
1829a418af5SJohannes Berg 				 IEEE80211_HT_CAP_SGI_40 |
1839a418af5SJohannes Berg 				 IEEE80211_HT_CAP_DSSSCCK40));
18421add825SJohannes Berg 
1859a418af5SJohannes Berg 	/*
1869a418af5SJohannes Berg 	 * The STBC bits are asymmetric -- if we don't have
1879a418af5SJohannes Berg 	 * TX then mask out the peer's RX and vice versa.
1889a418af5SJohannes Berg 	 */
189c07270b6SJohannes Berg 	if (!(own_cap.cap & IEEE80211_HT_CAP_TX_STBC))
190e1a0c6b3SJohannes Berg 		ht_cap.cap &= ~IEEE80211_HT_CAP_RX_STBC;
191c07270b6SJohannes Berg 	if (!(own_cap.cap & IEEE80211_HT_CAP_RX_STBC))
192e1a0c6b3SJohannes Berg 		ht_cap.cap &= ~IEEE80211_HT_CAP_TX_STBC;
193ae5eb026SJohannes Berg 
194ae5eb026SJohannes Berg 	ampdu_info = ht_cap_ie->ampdu_params_info;
195e1a0c6b3SJohannes Berg 	ht_cap.ampdu_factor =
196d9fe60deSJohannes Berg 		ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR;
197e1a0c6b3SJohannes Berg 	ht_cap.ampdu_density =
198d9fe60deSJohannes Berg 		(ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
199d9fe60deSJohannes Berg 
200d9fe60deSJohannes Berg 	/* own MCS TX capabilities */
201c07270b6SJohannes Berg 	tx_mcs_set_cap = own_cap.mcs.tx_params;
202d9fe60deSJohannes Berg 
20390b4ca9dSJohannes Berg 	/* Copy peer MCS TX capabilities, the driver might need them. */
204e1a0c6b3SJohannes Berg 	ht_cap.mcs.tx_params = ht_cap_ie->mcs.tx_params;
20590b4ca9dSJohannes Berg 
206d9fe60deSJohannes Berg 	/* can we TX with MCS rates? */
207d9fe60deSJohannes Berg 	if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED))
208e1a0c6b3SJohannes Berg 		goto apply;
209d9fe60deSJohannes Berg 
210d9fe60deSJohannes Berg 	/* Counting from 0, therefore +1 */
211d9fe60deSJohannes Berg 	if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF)
212d9fe60deSJohannes Berg 		max_tx_streams =
213d9fe60deSJohannes Berg 			((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
214d9fe60deSJohannes Berg 				>> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
215d9fe60deSJohannes Berg 	else
216d9fe60deSJohannes Berg 		max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS;
217d9fe60deSJohannes Berg 
218d9fe60deSJohannes Berg 	/*
21990b4ca9dSJohannes Berg 	 * 802.11n-2009 20.3.5 / 20.6 says:
220d9fe60deSJohannes Berg 	 * - indices 0 to 7 and 32 are single spatial stream
221d9fe60deSJohannes Berg 	 * - 8 to 31 are multiple spatial streams using equal modulation
222d9fe60deSJohannes Berg 	 *   [8..15 for two streams, 16..23 for three and 24..31 for four]
223d9fe60deSJohannes Berg 	 * - remainder are multiple spatial streams using unequal modulation
224d9fe60deSJohannes Berg 	 */
225d9fe60deSJohannes Berg 	for (i = 0; i < max_tx_streams; i++)
226e1a0c6b3SJohannes Berg 		ht_cap.mcs.rx_mask[i] =
227c07270b6SJohannes Berg 			own_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
228d9fe60deSJohannes Berg 
229d9fe60deSJohannes Berg 	if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
230d9fe60deSJohannes Berg 		for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
231d9fe60deSJohannes Berg 		     i < IEEE80211_HT_MCS_MASK_LEN; i++)
232e1a0c6b3SJohannes Berg 			ht_cap.mcs.rx_mask[i] =
233c07270b6SJohannes Berg 				own_cap.mcs.rx_mask[i] &
234ae5eb026SJohannes Berg 					ht_cap_ie->mcs.rx_mask[i];
235d9fe60deSJohannes Berg 
236d9fe60deSJohannes Berg 	/* handle MCS rate 32 too */
237c07270b6SJohannes Berg 	if (own_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
238e1a0c6b3SJohannes Berg 		ht_cap.mcs.rx_mask[32/8] |= 1;
239ef96a842SBen Greear 
240dc5943d5SArik Nemtsov 	/* set Rx highest rate */
241dc5943d5SArik Nemtsov 	ht_cap.mcs.rx_highest = ht_cap_ie->mcs.rx_highest;
242dc5943d5SArik Nemtsov 
243506bcfa8SEmmanuel Grumbach 	if (ht_cap.cap & IEEE80211_HT_CAP_MAX_AMSDU)
2444c51541dSBenjamin Berg 		link_sta->pub->agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_7935;
245506bcfa8SEmmanuel Grumbach 	else
2464c51541dSBenjamin Berg 		link_sta->pub->agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_3839;
2474c51541dSBenjamin Berg 
2484c51541dSBenjamin Berg 	ieee80211_sta_recalc_aggregates(&sta->sta);
249506bcfa8SEmmanuel Grumbach 
250e1a0c6b3SJohannes Berg  apply:
251c71420dbSJohannes Berg 	changed = memcmp(&link_sta->pub->ht_cap, &ht_cap, sizeof(ht_cap));
252e1a0c6b3SJohannes Berg 
253c71420dbSJohannes Berg 	memcpy(&link_sta->pub->ht_cap, &ht_cap, sizeof(ht_cap));
254e1a0c6b3SJohannes Berg 
255d8675a63SJohannes Berg 	rcu_read_lock();
256d8675a63SJohannes Berg 	link_conf = rcu_dereference(sdata->vif.link_conf[link_sta->link_id]);
257d8675a63SJohannes Berg 	if (WARN_ON(!link_conf))
258d8675a63SJohannes Berg 		width = NL80211_CHAN_WIDTH_20_NOHT;
259d8675a63SJohannes Berg 	else
260d8675a63SJohannes Berg 		width = link_conf->chandef.width;
261d8675a63SJohannes Berg 
262d8675a63SJohannes Berg 	switch (width) {
263e1a0c6b3SJohannes Berg 	default:
264e1a0c6b3SJohannes Berg 		WARN_ON_ONCE(1);
265fc0561dcSGustavo A. R. Silva 		fallthrough;
266e1a0c6b3SJohannes Berg 	case NL80211_CHAN_WIDTH_20_NOHT:
267e1a0c6b3SJohannes Berg 	case NL80211_CHAN_WIDTH_20:
268e1a0c6b3SJohannes Berg 		bw = IEEE80211_STA_RX_BW_20;
269e1a0c6b3SJohannes Berg 		break;
270e1a0c6b3SJohannes Berg 	case NL80211_CHAN_WIDTH_40:
271e1a0c6b3SJohannes Berg 	case NL80211_CHAN_WIDTH_80:
272e1a0c6b3SJohannes Berg 	case NL80211_CHAN_WIDTH_80P80:
273e1a0c6b3SJohannes Berg 	case NL80211_CHAN_WIDTH_160:
274*0e25eac3SBen Greear 	case NL80211_CHAN_WIDTH_320:
275e1a0c6b3SJohannes Berg 		bw = ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
276e1a0c6b3SJohannes Berg 				IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
277e1a0c6b3SJohannes Berg 		break;
278e1a0c6b3SJohannes Berg 	}
279d8675a63SJohannes Berg 	rcu_read_unlock();
280e1a0c6b3SJohannes Berg 
281c71420dbSJohannes Berg 	link_sta->pub->bandwidth = bw;
282e1a0c6b3SJohannes Berg 
283c71420dbSJohannes Berg 	link_sta->cur_max_bandwidth =
2840af83d3dSJohannes Berg 		ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
2850af83d3dSJohannes Berg 				IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
2860af83d3dSJohannes Berg 
287c4d800dcSIlan Peer 	if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
288c4d800dcSIlan Peer 	    sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
289c4d800dcSIlan Peer 		enum ieee80211_smps_mode smps_mode;
290c4d800dcSIlan Peer 
291af0ed69bSJohannes Berg 		switch ((ht_cap.cap & IEEE80211_HT_CAP_SM_PS)
292af0ed69bSJohannes Berg 				>> IEEE80211_HT_CAP_SM_PS_SHIFT) {
293af0ed69bSJohannes Berg 		case WLAN_HT_CAP_SM_PS_INVALID:
294af0ed69bSJohannes Berg 		case WLAN_HT_CAP_SM_PS_STATIC:
295af0ed69bSJohannes Berg 			smps_mode = IEEE80211_SMPS_STATIC;
296af0ed69bSJohannes Berg 			break;
297af0ed69bSJohannes Berg 		case WLAN_HT_CAP_SM_PS_DYNAMIC:
298af0ed69bSJohannes Berg 			smps_mode = IEEE80211_SMPS_DYNAMIC;
299af0ed69bSJohannes Berg 			break;
300af0ed69bSJohannes Berg 		case WLAN_HT_CAP_SM_PS_DISABLED:
301af0ed69bSJohannes Berg 			smps_mode = IEEE80211_SMPS_OFF;
302af0ed69bSJohannes Berg 			break;
303af0ed69bSJohannes Berg 		}
304af0ed69bSJohannes Berg 
305261ce887SBenjamin Berg 		if (smps_mode != link_sta->pub->smps_mode)
306af0ed69bSJohannes Berg 			changed = true;
307261ce887SBenjamin Berg 		link_sta->pub->smps_mode = smps_mode;
308c4d800dcSIlan Peer 	} else {
309261ce887SBenjamin Berg 		link_sta->pub->smps_mode = IEEE80211_SMPS_OFF;
310c4d800dcSIlan Peer 	}
311261ce887SBenjamin Berg 
312e1a0c6b3SJohannes Berg 	return changed;
313ae5eb026SJohannes Berg }
314d9fe60deSJohannes Berg 
ieee80211_sta_tear_down_BA_sessions(struct sta_info * sta,enum ieee80211_agg_stop_reason reason)315c82c4a80SJohannes Berg void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta,
316c82c4a80SJohannes Berg 					 enum ieee80211_agg_stop_reason reason)
31744d414dbSJohannes Berg {
318b8695a8fSJohannes Berg 	int i;
31944d414dbSJohannes Berg 
32012811037SIlan peer 	mutex_lock(&sta->ampdu_mlme.mtx);
3210afe9d4aSJohannes Berg 	for (i = 0; i <  IEEE80211_NUM_TIDS; i++)
32212811037SIlan peer 		___ieee80211_stop_rx_ba_session(sta, i, WLAN_BACK_RECIPIENT,
323c82c4a80SJohannes Berg 						WLAN_REASON_QSTA_LEAVE_QBSS,
324c82c4a80SJohannes Berg 						reason != AGG_STOP_DESTROY_STA &&
325c82c4a80SJohannes Berg 						reason != AGG_STOP_PEER_REQUEST);
3267a7c0a64SJohannes Berg 
32772e2c343SSara Sharon 	for (i = 0; i <  IEEE80211_NUM_TIDS; i++)
32872e2c343SSara Sharon 		___ieee80211_stop_tx_ba_session(sta, i, reason);
3290afe9d4aSJohannes Berg 	mutex_unlock(&sta->ampdu_mlme.mtx);
33072e2c343SSara Sharon 
33198e93e96SIlan peer 	/*
33298e93e96SIlan peer 	 * In case the tear down is part of a reconfigure due to HW restart
33398e93e96SIlan peer 	 * request, it is possible that the low level driver requested to stop
33498e93e96SIlan peer 	 * the BA session, so handle it to properly clean tid_tx data.
33598e93e96SIlan peer 	 */
33639c1134cSAlexander Wetzel 	if(reason == AGG_STOP_DESTROY_STA) {
33739c1134cSAlexander Wetzel 		cancel_work_sync(&sta->ampdu_mlme.work);
33839c1134cSAlexander Wetzel 
33998e93e96SIlan peer 		mutex_lock(&sta->ampdu_mlme.mtx);
34098e93e96SIlan peer 		for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
34198e93e96SIlan peer 			struct tid_ampdu_tx *tid_tx =
34298e93e96SIlan peer 				rcu_dereference_protected_tid_tx(sta, i);
34398e93e96SIlan peer 
34498e93e96SIlan peer 			if (!tid_tx)
34598e93e96SIlan peer 				continue;
34698e93e96SIlan peer 
34798e93e96SIlan peer 			if (test_and_clear_bit(HT_AGG_STATE_STOP_CB, &tid_tx->state))
34898e93e96SIlan peer 				ieee80211_stop_tx_ba_cb(sta, i, tid_tx);
34998e93e96SIlan peer 		}
35098e93e96SIlan peer 		mutex_unlock(&sta->ampdu_mlme.mtx);
35144d414dbSJohannes Berg 	}
35239c1134cSAlexander Wetzel }
35344d414dbSJohannes Berg 
ieee80211_ba_session_work(struct work_struct * work)35467c282c0SJohannes Berg void ieee80211_ba_session_work(struct work_struct *work)
35567c282c0SJohannes Berg {
35667c282c0SJohannes Berg 	struct sta_info *sta =
35767c282c0SJohannes Berg 		container_of(work, struct sta_info, ampdu_mlme.work);
35867c282c0SJohannes Berg 	struct tid_ampdu_tx *tid_tx;
35939c1134cSAlexander Wetzel 	bool blocked;
36067c282c0SJohannes Berg 	int tid;
36167c282c0SJohannes Berg 
36239c1134cSAlexander Wetzel 	/* When this flag is set, new sessions should be blocked. */
36339c1134cSAlexander Wetzel 	blocked = test_sta_flag(sta, WLAN_STA_BLOCK_BA);
36467c282c0SJohannes Berg 
365a93e3644SJohannes Berg 	mutex_lock(&sta->ampdu_mlme.mtx);
3665a306f58SJohannes Berg 	for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
3677c3b1dd8SJohannes Berg 		if (test_and_clear_bit(tid, sta->ampdu_mlme.tid_rx_timer_expired))
3687c3b1dd8SJohannes Berg 			___ieee80211_stop_rx_ba_session(
3697c3b1dd8SJohannes Berg 				sta, tid, WLAN_BACK_RECIPIENT,
37053f73c09SJohannes Berg 				WLAN_REASON_QSTA_TIMEOUT, true);
3717c3b1dd8SJohannes Berg 
372f41ccd71SShahar Levi 		if (test_and_clear_bit(tid,
373f41ccd71SShahar Levi 				       sta->ampdu_mlme.tid_rx_stop_requested))
374f41ccd71SShahar Levi 			___ieee80211_stop_rx_ba_session(
375f41ccd71SShahar Levi 				sta, tid, WLAN_BACK_RECIPIENT,
376f41ccd71SShahar Levi 				WLAN_REASON_UNSPECIFIED, true);
377f41ccd71SShahar Levi 
37839c1134cSAlexander Wetzel 		if (!blocked &&
37939c1134cSAlexander Wetzel 		    test_and_clear_bit(tid,
380699cb58cSJohannes Berg 				       sta->ampdu_mlme.tid_rx_manage_offl))
381bde59c47SJohannes Berg 			___ieee80211_start_rx_ba_session(sta, 0, 0, 0, 1, tid,
382b8042b3dSJohannes Berg 							 IEEE80211_MAX_AMPDU_BUF_HT,
3832ab45876SJohn Crispin 							 false, true, NULL);
384699cb58cSJohannes Berg 
385699cb58cSJohannes Berg 		if (test_and_clear_bit(tid + IEEE80211_NUM_TIDS,
386699cb58cSJohannes Berg 				       sta->ampdu_mlme.tid_rx_manage_offl))
387699cb58cSJohannes Berg 			___ieee80211_stop_rx_ba_session(
388699cb58cSJohannes Berg 				sta, tid, WLAN_BACK_RECIPIENT,
389699cb58cSJohannes Berg 				0, false);
390699cb58cSJohannes Berg 
391e562078aSBen Greear 		spin_lock_bh(&sta->lock);
392e562078aSBen Greear 
393ec034b20SJohannes Berg 		tid_tx = sta->ampdu_mlme.tid_start_tx[tid];
39439c1134cSAlexander Wetzel 		if (!blocked && tid_tx) {
395592234e9SAlexander Wetzel 			struct txq_info *txqi = to_txq_info(sta->sta.txq[tid]);
396592234e9SAlexander Wetzel 			struct ieee80211_sub_if_data *sdata =
397592234e9SAlexander Wetzel 				vif_to_sdata(txqi->txq.vif);
398592234e9SAlexander Wetzel 			struct fq *fq = &sdata->local->fq;
399592234e9SAlexander Wetzel 
400592234e9SAlexander Wetzel 			spin_lock_bh(&fq->lock);
401592234e9SAlexander Wetzel 
402592234e9SAlexander Wetzel 			/* Allow only frags to be dequeued */
403592234e9SAlexander Wetzel 			set_bit(IEEE80211_TXQ_STOP, &txqi->flags);
404592234e9SAlexander Wetzel 
405592234e9SAlexander Wetzel 			if (!skb_queue_empty(&txqi->frags)) {
406592234e9SAlexander Wetzel 				/* Fragmented Tx is ongoing, wait for it to
407592234e9SAlexander Wetzel 				 * finish. Reschedule worker to retry later.
408592234e9SAlexander Wetzel 				 */
409592234e9SAlexander Wetzel 
410592234e9SAlexander Wetzel 				spin_unlock_bh(&fq->lock);
411592234e9SAlexander Wetzel 				spin_unlock_bh(&sta->lock);
412592234e9SAlexander Wetzel 
413592234e9SAlexander Wetzel 				/* Give the task working on the txq a chance
414592234e9SAlexander Wetzel 				 * to send out the queued frags
415592234e9SAlexander Wetzel 				 */
416592234e9SAlexander Wetzel 				synchronize_net();
417592234e9SAlexander Wetzel 
418592234e9SAlexander Wetzel 				mutex_unlock(&sta->ampdu_mlme.mtx);
419592234e9SAlexander Wetzel 
420592234e9SAlexander Wetzel 				ieee80211_queue_work(&sdata->local->hw, work);
421592234e9SAlexander Wetzel 				return;
422592234e9SAlexander Wetzel 			}
423592234e9SAlexander Wetzel 
424592234e9SAlexander Wetzel 			spin_unlock_bh(&fq->lock);
425592234e9SAlexander Wetzel 
426ec034b20SJohannes Berg 			/*
427ec034b20SJohannes Berg 			 * Assign it over to the normal tid_tx array
428ec034b20SJohannes Berg 			 * where it "goes live".
429ec034b20SJohannes Berg 			 */
43067c282c0SJohannes Berg 
431ec034b20SJohannes Berg 			sta->ampdu_mlme.tid_start_tx[tid] = NULL;
432ec034b20SJohannes Berg 			/* could there be a race? */
433ec034b20SJohannes Berg 			if (sta->ampdu_mlme.tid_tx[tid])
434ec034b20SJohannes Berg 				kfree(tid_tx);
435ec034b20SJohannes Berg 			else
436ec034b20SJohannes Berg 				ieee80211_assign_tid_tx(sta, tid, tid_tx);
437ec034b20SJohannes Berg 			spin_unlock_bh(&sta->lock);
438ec034b20SJohannes Berg 
43967c282c0SJohannes Berg 			ieee80211_tx_ba_session_handle_start(sta, tid);
440ec034b20SJohannes Berg 			continue;
441ec034b20SJohannes Berg 		}
442e562078aSBen Greear 		spin_unlock_bh(&sta->lock);
443ec034b20SJohannes Berg 
44440b275b6SJohannes Berg 		tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
4457a7c0a64SJohannes Berg 		if (!tid_tx)
4467a7c0a64SJohannes Berg 			continue;
4477a7c0a64SJohannes Berg 
44839c1134cSAlexander Wetzel 		if (!blocked &&
44939c1134cSAlexander Wetzel 		    test_and_clear_bit(HT_AGG_STATE_START_CB, &tid_tx->state))
4507a7c0a64SJohannes Berg 			ieee80211_start_tx_ba_cb(sta, tid, tid_tx);
4517a7c0a64SJohannes Berg 		if (test_and_clear_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state))
45267c282c0SJohannes Berg 			___ieee80211_stop_tx_ba_session(sta, tid,
453c82c4a80SJohannes Berg 							AGG_STOP_LOCAL_REQUEST);
4547a7c0a64SJohannes Berg 		if (test_and_clear_bit(HT_AGG_STATE_STOP_CB, &tid_tx->state))
4557a7c0a64SJohannes Berg 			ieee80211_stop_tx_ba_cb(sta, tid, tid_tx);
45667c282c0SJohannes Berg 	}
457cfcdbde3SJohannes Berg 	mutex_unlock(&sta->ampdu_mlme.mtx);
45867c282c0SJohannes Berg }
45967c282c0SJohannes Berg 
ieee80211_send_delba(struct ieee80211_sub_if_data * sdata,const u8 * da,u16 tid,u16 initiator,u16 reason_code)460b8695a8fSJohannes Berg void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
461de1ede7aSJohannes Berg 			  const u8 *da, u16 tid,
46244d414dbSJohannes Berg 			  u16 initiator, u16 reason_code)
46344d414dbSJohannes Berg {
46444d414dbSJohannes Berg 	struct ieee80211_local *local = sdata->local;
46544d414dbSJohannes Berg 	struct sk_buff *skb;
46644d414dbSJohannes Berg 	struct ieee80211_mgmt *mgmt;
46744d414dbSJohannes Berg 	u16 params;
46844d414dbSJohannes Berg 
46944d414dbSJohannes Berg 	skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
470d15b8459SJoe Perches 	if (!skb)
47144d414dbSJohannes Berg 		return;
47244d414dbSJohannes Berg 
47344d414dbSJohannes Berg 	skb_reserve(skb, local->hw.extra_tx_headroom);
474b080db58SJohannes Berg 	mgmt = skb_put_zero(skb, 24);
47544d414dbSJohannes Berg 	memcpy(mgmt->da, da, ETH_ALEN);
47647846c9bSJohannes Berg 	memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
4778abd3f9bSJohannes Berg 	if (sdata->vif.type == NL80211_IFTYPE_AP ||
478ae2772b3SThomas Pedersen 	    sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
479ae2772b3SThomas Pedersen 	    sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
48047846c9bSJohannes Berg 		memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
48146900298SJohannes Berg 	else if (sdata->vif.type == NL80211_IFTYPE_STATION)
482bfd8403aSJohannes Berg 		memcpy(mgmt->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
48313c40c54SAlexander Simon 	else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
48413c40c54SAlexander Simon 		memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
48546900298SJohannes Berg 
48644d414dbSJohannes Berg 	mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
48744d414dbSJohannes Berg 					  IEEE80211_STYPE_ACTION);
48844d414dbSJohannes Berg 
48944d414dbSJohannes Berg 	skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
49044d414dbSJohannes Berg 
49144d414dbSJohannes Berg 	mgmt->u.action.category = WLAN_CATEGORY_BACK;
49244d414dbSJohannes Berg 	mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
49344d414dbSJohannes Berg 	params = (u16)(initiator << 11); 	/* bit 11 initiator */
49444d414dbSJohannes Berg 	params |= (u16)(tid << 12); 		/* bit 15:12 TID number */
49544d414dbSJohannes Berg 
49644d414dbSJohannes Berg 	mgmt->u.action.u.delba.params = cpu_to_le16(params);
49744d414dbSJohannes Berg 	mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
49844d414dbSJohannes Berg 
499c6e13327SKarl Beldan 	ieee80211_tx_skb(sdata, skb);
50044d414dbSJohannes Berg }
50144d414dbSJohannes Berg 
ieee80211_process_delba(struct ieee80211_sub_if_data * sdata,struct sta_info * sta,struct ieee80211_mgmt * mgmt,size_t len)502de1ede7aSJohannes Berg void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
503de1ede7aSJohannes Berg 			     struct sta_info *sta,
504de1ede7aSJohannes Berg 			     struct ieee80211_mgmt *mgmt, size_t len)
505de1ede7aSJohannes Berg {
506de1ede7aSJohannes Berg 	u16 tid, params;
507de1ede7aSJohannes Berg 	u16 initiator;
508de1ede7aSJohannes Berg 
509de1ede7aSJohannes Berg 	params = le16_to_cpu(mgmt->u.action.u.delba.params);
510de1ede7aSJohannes Berg 	tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
511de1ede7aSJohannes Berg 	initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
512de1ede7aSJohannes Berg 
513bdcbd8e0SJohannes Berg 	ht_dbg_ratelimited(sdata, "delba from %pM (%s) tid %d reason code %d\n",
514e87cc472SJoe Perches 			   mgmt->sa, initiator ? "initiator" : "recipient",
515e87cc472SJoe Perches 			   tid,
516372362adSJohannes Berg 			   le16_to_cpu(mgmt->u.action.u.delba.reason_code));
517de1ede7aSJohannes Berg 
518de1ede7aSJohannes Berg 	if (initiator == WLAN_BACK_INITIATOR)
51953f73c09SJohannes Berg 		__ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_INITIATOR, 0,
52053f73c09SJohannes Berg 					       true);
521a622ab72SJohannes Berg 	else
522c82c4a80SJohannes Berg 		__ieee80211_stop_tx_ba_session(sta, tid, AGG_STOP_PEER_REQUEST);
523de1ede7aSJohannes Berg }
5240f78231bSJohannes Berg 
52557566b20Stamizhr@codeaurora.org enum nl80211_smps_mode
ieee80211_smps_mode_to_smps_mode(enum ieee80211_smps_mode smps)52657566b20Stamizhr@codeaurora.org ieee80211_smps_mode_to_smps_mode(enum ieee80211_smps_mode smps)
52757566b20Stamizhr@codeaurora.org {
52857566b20Stamizhr@codeaurora.org 	switch (smps) {
52957566b20Stamizhr@codeaurora.org 	case IEEE80211_SMPS_OFF:
53057566b20Stamizhr@codeaurora.org 		return NL80211_SMPS_OFF;
53157566b20Stamizhr@codeaurora.org 	case IEEE80211_SMPS_STATIC:
53257566b20Stamizhr@codeaurora.org 		return NL80211_SMPS_STATIC;
53357566b20Stamizhr@codeaurora.org 	case IEEE80211_SMPS_DYNAMIC:
53457566b20Stamizhr@codeaurora.org 		return NL80211_SMPS_DYNAMIC;
53557566b20Stamizhr@codeaurora.org 	default:
53657566b20Stamizhr@codeaurora.org 		return NL80211_SMPS_OFF;
53757566b20Stamizhr@codeaurora.org 	}
53857566b20Stamizhr@codeaurora.org }
53957566b20Stamizhr@codeaurora.org 
ieee80211_send_smps_action(struct ieee80211_sub_if_data * sdata,enum ieee80211_smps_mode smps,const u8 * da,const u8 * bssid)5400f78231bSJohannes Berg int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata,
5410f78231bSJohannes Berg 			       enum ieee80211_smps_mode smps, const u8 *da,
5420f78231bSJohannes Berg 			       const u8 *bssid)
5430f78231bSJohannes Berg {
5440f78231bSJohannes Berg 	struct ieee80211_local *local = sdata->local;
5450f78231bSJohannes Berg 	struct sk_buff *skb;
5460f78231bSJohannes Berg 	struct ieee80211_mgmt *action_frame;
5470f78231bSJohannes Berg 
5480f78231bSJohannes Berg 	/* 27 = header + category + action + smps mode */
5490f78231bSJohannes Berg 	skb = dev_alloc_skb(27 + local->hw.extra_tx_headroom);
5500f78231bSJohannes Berg 	if (!skb)
5510f78231bSJohannes Berg 		return -ENOMEM;
5520f78231bSJohannes Berg 
5530f78231bSJohannes Berg 	skb_reserve(skb, local->hw.extra_tx_headroom);
5544df864c1SJohannes Berg 	action_frame = skb_put(skb, 27);
5550f78231bSJohannes Berg 	memcpy(action_frame->da, da, ETH_ALEN);
5560f78231bSJohannes Berg 	memcpy(action_frame->sa, sdata->dev->dev_addr, ETH_ALEN);
5570f78231bSJohannes Berg 	memcpy(action_frame->bssid, bssid, ETH_ALEN);
5580f78231bSJohannes Berg 	action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
5590f78231bSJohannes Berg 						  IEEE80211_STYPE_ACTION);
5600f78231bSJohannes Berg 	action_frame->u.action.category = WLAN_CATEGORY_HT;
5610f78231bSJohannes Berg 	action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
5620f78231bSJohannes Berg 	switch (smps) {
5630f78231bSJohannes Berg 	case IEEE80211_SMPS_AUTOMATIC:
5640f78231bSJohannes Berg 	case IEEE80211_SMPS_NUM_MODES:
5650f78231bSJohannes Berg 		WARN_ON(1);
566fc0561dcSGustavo A. R. Silva 		fallthrough;
5670f78231bSJohannes Berg 	case IEEE80211_SMPS_OFF:
5680f78231bSJohannes Berg 		action_frame->u.action.u.ht_smps.smps_control =
5690f78231bSJohannes Berg 				WLAN_HT_SMPS_CONTROL_DISABLED;
5700f78231bSJohannes Berg 		break;
5710f78231bSJohannes Berg 	case IEEE80211_SMPS_STATIC:
5720f78231bSJohannes Berg 		action_frame->u.action.u.ht_smps.smps_control =
5730f78231bSJohannes Berg 				WLAN_HT_SMPS_CONTROL_STATIC;
5740f78231bSJohannes Berg 		break;
5750f78231bSJohannes Berg 	case IEEE80211_SMPS_DYNAMIC:
5760f78231bSJohannes Berg 		action_frame->u.action.u.ht_smps.smps_control =
5770f78231bSJohannes Berg 				WLAN_HT_SMPS_CONTROL_DYNAMIC;
5780f78231bSJohannes Berg 		break;
5790f78231bSJohannes Berg 	}
5800f78231bSJohannes Berg 
5810f78231bSJohannes Berg 	/* we'll do more on status of this frame */
5820f78231bSJohannes Berg 	IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
5830f78231bSJohannes Berg 	ieee80211_tx_skb(sdata, skb);
5840f78231bSJohannes Berg 
5850f78231bSJohannes Berg 	return 0;
5860f78231bSJohannes Berg }
587d1f5b7a3SJohannes Berg 
ieee80211_request_smps(struct ieee80211_vif * vif,unsigned int link_id,enum ieee80211_smps_mode smps_mode)588e9aac179SJohannes Berg void ieee80211_request_smps(struct ieee80211_vif *vif, unsigned int link_id,
589d1f5b7a3SJohannes Berg 			    enum ieee80211_smps_mode smps_mode)
590d1f5b7a3SJohannes Berg {
591d1f5b7a3SJohannes Berg 	struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
592d8675a63SJohannes Berg 	struct ieee80211_link_data *link;
593d1f5b7a3SJohannes Berg 
59410a35c22SJohannes Berg 	if (WARN_ON_ONCE(vif->type != NL80211_IFTYPE_STATION))
595d1f5b7a3SJohannes Berg 		return;
596d1f5b7a3SJohannes Berg 
597d8675a63SJohannes Berg 	rcu_read_lock();
598d8675a63SJohannes Berg 	link = rcu_dereference(sdata->link[link_id]);
599e9aac179SJohannes Berg 	if (WARN_ON(!link))
600d8675a63SJohannes Berg 		goto out;
60110a35c22SJohannes Berg 
602e9aac179SJohannes Berg 	if (link->u.mgd.driver_smps_mode == smps_mode)
603d8675a63SJohannes Berg 		goto out;
604e9aac179SJohannes Berg 
605e9aac179SJohannes Berg 	link->u.mgd.driver_smps_mode = smps_mode;
6061444f589SJohannes Berg 	wiphy_work_queue(sdata->local->hw.wiphy,
6071444f589SJohannes Berg 			 &link->u.mgd.request_smps_work);
608d8675a63SJohannes Berg out:
609d8675a63SJohannes Berg 	rcu_read_unlock();
610687da132SEmmanuel Grumbach }
611d1f5b7a3SJohannes Berg /* this might change ... don't want non-open drivers using it */
612d1f5b7a3SJohannes Berg EXPORT_SYMBOL_GPL(ieee80211_request_smps);
613