1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
10 * Copyright (C) 2018 Intel Corporation
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * The full GNU General Public License is included in this distribution
22 * in the file called COPYING.
24 * Contact Information:
25 * Intel Linux Wireless <linuxwifi@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
31 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
32 * Copyright (C) 2018 Intel Corporation
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
39 * * Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * * Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in
43 * the documentation and/or other materials provided with the
45 * * Neither the name Intel Corporation nor the names of its
46 * contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *****************************************************************************/
64 /* For counting bound interfaces */
65 struct iwl_mvm_active_iface_iterator_data
{
66 struct ieee80211_vif
*ignore_vif
;
68 enum iwl_sf_state sta_vif_state
;
73 * Count bound interfaces which are not p2p, besides data->ignore_vif.
74 * data->station_vif will point to one bound vif of type station, if exists.
76 static void iwl_mvm_bound_iface_iterator(void *_data
, u8
*mac
,
77 struct ieee80211_vif
*vif
)
79 struct iwl_mvm_active_iface_iterator_data
*data
= _data
;
80 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
82 if (vif
== data
->ignore_vif
|| !mvmvif
->phy_ctxt
||
83 vif
->type
== NL80211_IFTYPE_P2P_DEVICE
)
86 data
->num_active_macs
++;
88 if (vif
->type
== NL80211_IFTYPE_STATION
) {
89 data
->sta_vif_ap_sta_id
= mvmvif
->ap_sta_id
;
90 if (vif
->bss_conf
.assoc
)
91 data
->sta_vif_state
= SF_FULL_ON
;
93 data
->sta_vif_state
= SF_INIT_OFF
;
98 * Aging and idle timeouts for the different possible scenarios
99 * in default configuration
102 __le32 sf_full_timeout_def
[SF_NUM_SCENARIO
][SF_NUM_TIMEOUT_TYPES
] = {
104 cpu_to_le32(SF_SINGLE_UNICAST_AGING_TIMER_DEF
),
105 cpu_to_le32(SF_SINGLE_UNICAST_IDLE_TIMER_DEF
)
108 cpu_to_le32(SF_AGG_UNICAST_AGING_TIMER_DEF
),
109 cpu_to_le32(SF_AGG_UNICAST_IDLE_TIMER_DEF
)
112 cpu_to_le32(SF_MCAST_AGING_TIMER_DEF
),
113 cpu_to_le32(SF_MCAST_IDLE_TIMER_DEF
)
116 cpu_to_le32(SF_BA_AGING_TIMER_DEF
),
117 cpu_to_le32(SF_BA_IDLE_TIMER_DEF
)
120 cpu_to_le32(SF_TX_RE_AGING_TIMER_DEF
),
121 cpu_to_le32(SF_TX_RE_IDLE_TIMER_DEF
)
126 * Aging and idle timeouts for the different possible scenarios
127 * in single BSS MAC configuration.
129 static const __le32 sf_full_timeout
[SF_NUM_SCENARIO
][SF_NUM_TIMEOUT_TYPES
] = {
131 cpu_to_le32(SF_SINGLE_UNICAST_AGING_TIMER
),
132 cpu_to_le32(SF_SINGLE_UNICAST_IDLE_TIMER
)
135 cpu_to_le32(SF_AGG_UNICAST_AGING_TIMER
),
136 cpu_to_le32(SF_AGG_UNICAST_IDLE_TIMER
)
139 cpu_to_le32(SF_MCAST_AGING_TIMER
),
140 cpu_to_le32(SF_MCAST_IDLE_TIMER
)
143 cpu_to_le32(SF_BA_AGING_TIMER
),
144 cpu_to_le32(SF_BA_IDLE_TIMER
)
147 cpu_to_le32(SF_TX_RE_AGING_TIMER
),
148 cpu_to_le32(SF_TX_RE_IDLE_TIMER
)
152 static void iwl_mvm_fill_sf_command(struct iwl_mvm
*mvm
,
153 struct iwl_sf_cfg_cmd
*sf_cmd
,
154 struct ieee80211_sta
*sta
)
158 sf_cmd
->watermark
[SF_LONG_DELAY_ON
] = cpu_to_le32(SF_W_MARK_SCAN
);
161 * If we are in association flow - check antenna configuration
162 * capabilities of the AP station, and choose the watermark accordingly.
165 if (sta
->ht_cap
.ht_supported
|| sta
->vht_cap
.vht_supported
) {
166 switch (sta
->rx_nss
) {
168 watermark
= SF_W_MARK_SISO
;
171 watermark
= SF_W_MARK_MIMO2
;
174 watermark
= SF_W_MARK_MIMO3
;
178 watermark
= SF_W_MARK_LEGACY
;
180 /* default watermark value for unassociated mode. */
182 watermark
= SF_W_MARK_MIMO2
;
184 sf_cmd
->watermark
[SF_FULL_ON
] = cpu_to_le32(watermark
);
186 for (i
= 0; i
< SF_NUM_SCENARIO
; i
++) {
187 for (j
= 0; j
< SF_NUM_TIMEOUT_TYPES
; j
++) {
188 sf_cmd
->long_delay_timeouts
[i
][j
] =
189 cpu_to_le32(SF_LONG_DELAY_AGING_TIMER
);
194 BUILD_BUG_ON(sizeof(sf_full_timeout
) !=
195 sizeof(__le32
) * SF_NUM_SCENARIO
*
196 SF_NUM_TIMEOUT_TYPES
);
198 memcpy(sf_cmd
->full_on_timeouts
, sf_full_timeout
,
199 sizeof(sf_full_timeout
));
201 BUILD_BUG_ON(sizeof(sf_full_timeout_def
) !=
202 sizeof(__le32
) * SF_NUM_SCENARIO
*
203 SF_NUM_TIMEOUT_TYPES
);
205 memcpy(sf_cmd
->full_on_timeouts
, sf_full_timeout_def
,
206 sizeof(sf_full_timeout_def
));
211 static int iwl_mvm_sf_config(struct iwl_mvm
*mvm
, u8 sta_id
,
212 enum iwl_sf_state new_state
)
214 struct iwl_sf_cfg_cmd sf_cmd
= {
215 .state
= cpu_to_le32(new_state
),
217 struct ieee80211_sta
*sta
;
220 if (mvm
->cfg
->disable_dummy_notification
)
221 sf_cmd
.state
|= cpu_to_le32(SF_CFG_DUMMY_NOTIF_OFF
);
224 * If an associated AP sta changed its antenna configuration, the state
225 * will remain FULL_ON but SF parameters need to be reconsidered.
227 if (new_state
!= SF_FULL_ON
&& mvm
->sf_state
== new_state
)
232 iwl_mvm_fill_sf_command(mvm
, &sf_cmd
, NULL
);
235 if (sta_id
== IWL_MVM_INVALID_STA
) {
237 "No station: Cannot switch SF to FULL_ON\n");
241 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
242 if (IS_ERR_OR_NULL(sta
)) {
243 IWL_ERR(mvm
, "Invalid station id\n");
247 iwl_mvm_fill_sf_command(mvm
, &sf_cmd
, sta
);
251 iwl_mvm_fill_sf_command(mvm
, &sf_cmd
, NULL
);
254 WARN_ONCE(1, "Invalid state: %d. not sending Smart Fifo cmd\n",
259 ret
= iwl_mvm_send_cmd_pdu(mvm
, REPLY_SF_CFG_CMD
, CMD_ASYNC
,
260 sizeof(sf_cmd
), &sf_cmd
);
262 mvm
->sf_state
= new_state
;
269 * Count bound interfaces that are not to be removed, ignoring p2p devices,
270 * and set new state accordingly.
272 int iwl_mvm_sf_update(struct iwl_mvm
*mvm
, struct ieee80211_vif
*changed_vif
,
275 enum iwl_sf_state new_state
;
276 u8 sta_id
= IWL_MVM_INVALID_STA
;
277 struct iwl_mvm_vif
*mvmvif
= NULL
;
278 struct iwl_mvm_active_iface_iterator_data data
= {
279 .ignore_vif
= changed_vif
,
280 .sta_vif_state
= SF_UNINIT
,
281 .sta_vif_ap_sta_id
= IWL_MVM_INVALID_STA
,
285 * Ignore the call if we are in HW Restart flow, or if the handled
286 * vif is a p2p device.
288 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) ||
289 (changed_vif
&& changed_vif
->type
== NL80211_IFTYPE_P2P_DEVICE
))
292 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
293 IEEE80211_IFACE_ITER_NORMAL
,
294 iwl_mvm_bound_iface_iterator
,
297 /* If changed_vif exists and is not to be removed, add to the count */
298 if (changed_vif
&& !remove_vif
)
299 data
.num_active_macs
++;
301 switch (data
.num_active_macs
) {
303 /* If there are no active macs - change state to SF_INIT_OFF */
304 new_state
= SF_INIT_OFF
;
308 /* The one active mac left is of type station
309 * and we filled the relevant data during iteration
311 new_state
= data
.sta_vif_state
;
312 sta_id
= data
.sta_vif_ap_sta_id
;
314 if (WARN_ON(!changed_vif
))
316 if (changed_vif
->type
!= NL80211_IFTYPE_STATION
) {
317 new_state
= SF_UNINIT
;
318 } else if (changed_vif
->bss_conf
.assoc
&&
319 changed_vif
->bss_conf
.dtim_period
) {
320 mvmvif
= iwl_mvm_vif_from_mac80211(changed_vif
);
321 sta_id
= mvmvif
->ap_sta_id
;
322 new_state
= SF_FULL_ON
;
324 new_state
= SF_INIT_OFF
;
329 /* If there are multiple active macs - change to SF_UNINIT */
330 new_state
= SF_UNINIT
;
332 return iwl_mvm_sf_config(mvm
, sta_id
, new_state
);