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
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <linuxwifi@intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
67 /* For counting bound interfaces */
68 struct iwl_mvm_active_iface_iterator_data
{
69 struct ieee80211_vif
*ignore_vif
;
71 enum iwl_sf_state sta_vif_state
;
76 * Count bound interfaces which are not p2p, besides data->ignore_vif.
77 * data->station_vif will point to one bound vif of type station, if exists.
79 static void iwl_mvm_bound_iface_iterator(void *_data
, u8
*mac
,
80 struct ieee80211_vif
*vif
)
82 struct iwl_mvm_active_iface_iterator_data
*data
= _data
;
83 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
85 if (vif
== data
->ignore_vif
|| !mvmvif
->phy_ctxt
||
86 vif
->type
== NL80211_IFTYPE_P2P_DEVICE
)
89 data
->num_active_macs
++;
91 if (vif
->type
== NL80211_IFTYPE_STATION
) {
92 data
->sta_vif_ap_sta_id
= mvmvif
->ap_sta_id
;
93 if (vif
->bss_conf
.assoc
)
94 data
->sta_vif_state
= SF_FULL_ON
;
96 data
->sta_vif_state
= SF_INIT_OFF
;
101 * Aging and idle timeouts for the different possible scenarios
102 * in default configuration
105 __le32 sf_full_timeout_def
[SF_NUM_SCENARIO
][SF_NUM_TIMEOUT_TYPES
] = {
107 cpu_to_le32(SF_SINGLE_UNICAST_AGING_TIMER_DEF
),
108 cpu_to_le32(SF_SINGLE_UNICAST_IDLE_TIMER_DEF
)
111 cpu_to_le32(SF_AGG_UNICAST_AGING_TIMER_DEF
),
112 cpu_to_le32(SF_AGG_UNICAST_IDLE_TIMER_DEF
)
115 cpu_to_le32(SF_MCAST_AGING_TIMER_DEF
),
116 cpu_to_le32(SF_MCAST_IDLE_TIMER_DEF
)
119 cpu_to_le32(SF_BA_AGING_TIMER_DEF
),
120 cpu_to_le32(SF_BA_IDLE_TIMER_DEF
)
123 cpu_to_le32(SF_TX_RE_AGING_TIMER_DEF
),
124 cpu_to_le32(SF_TX_RE_IDLE_TIMER_DEF
)
129 * Aging and idle timeouts for the different possible scenarios
130 * in single BSS MAC configuration.
132 static const __le32 sf_full_timeout
[SF_NUM_SCENARIO
][SF_NUM_TIMEOUT_TYPES
] = {
134 cpu_to_le32(SF_SINGLE_UNICAST_AGING_TIMER
),
135 cpu_to_le32(SF_SINGLE_UNICAST_IDLE_TIMER
)
138 cpu_to_le32(SF_AGG_UNICAST_AGING_TIMER
),
139 cpu_to_le32(SF_AGG_UNICAST_IDLE_TIMER
)
142 cpu_to_le32(SF_MCAST_AGING_TIMER
),
143 cpu_to_le32(SF_MCAST_IDLE_TIMER
)
146 cpu_to_le32(SF_BA_AGING_TIMER
),
147 cpu_to_le32(SF_BA_IDLE_TIMER
)
150 cpu_to_le32(SF_TX_RE_AGING_TIMER
),
151 cpu_to_le32(SF_TX_RE_IDLE_TIMER
)
155 static void iwl_mvm_fill_sf_command(struct iwl_mvm
*mvm
,
156 struct iwl_sf_cfg_cmd
*sf_cmd
,
157 struct ieee80211_sta
*sta
)
161 sf_cmd
->watermark
[SF_LONG_DELAY_ON
] = cpu_to_le32(SF_W_MARK_SCAN
);
164 * If we are in association flow - check antenna configuration
165 * capabilities of the AP station, and choose the watermark accordingly.
168 if (sta
->ht_cap
.ht_supported
|| sta
->vht_cap
.vht_supported
) {
169 switch (sta
->rx_nss
) {
171 watermark
= SF_W_MARK_SISO
;
174 watermark
= SF_W_MARK_MIMO2
;
177 watermark
= SF_W_MARK_MIMO3
;
181 watermark
= SF_W_MARK_LEGACY
;
183 /* default watermark value for unassociated mode. */
185 watermark
= SF_W_MARK_MIMO2
;
187 sf_cmd
->watermark
[SF_FULL_ON
] = cpu_to_le32(watermark
);
189 for (i
= 0; i
< SF_NUM_SCENARIO
; i
++) {
190 for (j
= 0; j
< SF_NUM_TIMEOUT_TYPES
; j
++) {
191 sf_cmd
->long_delay_timeouts
[i
][j
] =
192 cpu_to_le32(SF_LONG_DELAY_AGING_TIMER
);
197 BUILD_BUG_ON(sizeof(sf_full_timeout
) !=
198 sizeof(__le32
) * SF_NUM_SCENARIO
*
199 SF_NUM_TIMEOUT_TYPES
);
201 memcpy(sf_cmd
->full_on_timeouts
, sf_full_timeout
,
202 sizeof(sf_full_timeout
));
204 BUILD_BUG_ON(sizeof(sf_full_timeout_def
) !=
205 sizeof(__le32
) * SF_NUM_SCENARIO
*
206 SF_NUM_TIMEOUT_TYPES
);
208 memcpy(sf_cmd
->full_on_timeouts
, sf_full_timeout_def
,
209 sizeof(sf_full_timeout_def
));
214 static int iwl_mvm_sf_config(struct iwl_mvm
*mvm
, u8 sta_id
,
215 enum iwl_sf_state new_state
)
217 struct iwl_sf_cfg_cmd sf_cmd
= {
218 .state
= cpu_to_le32(SF_FULL_ON
),
220 struct ieee80211_sta
*sta
;
223 if (mvm
->cfg
->disable_dummy_notification
)
224 sf_cmd
.state
|= cpu_to_le32(SF_CFG_DUMMY_NOTIF_OFF
);
227 * If an associated AP sta changed its antenna configuration, the state
228 * will remain FULL_ON but SF parameters need to be reconsidered.
230 if (new_state
!= SF_FULL_ON
&& mvm
->sf_state
== new_state
)
235 iwl_mvm_fill_sf_command(mvm
, &sf_cmd
, NULL
);
238 if (sta_id
== IWL_MVM_STATION_COUNT
) {
240 "No station: Cannot switch SF to FULL_ON\n");
244 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
245 if (IS_ERR_OR_NULL(sta
)) {
246 IWL_ERR(mvm
, "Invalid station id\n");
250 iwl_mvm_fill_sf_command(mvm
, &sf_cmd
, sta
);
254 iwl_mvm_fill_sf_command(mvm
, &sf_cmd
, NULL
);
257 WARN_ONCE(1, "Invalid state: %d. not sending Smart Fifo cmd\n",
262 ret
= iwl_mvm_send_cmd_pdu(mvm
, REPLY_SF_CFG_CMD
, CMD_ASYNC
,
263 sizeof(sf_cmd
), &sf_cmd
);
265 mvm
->sf_state
= new_state
;
272 * Count bound interfaces that are not to be removed, ignoring p2p devices,
273 * and set new state accordingly.
275 int iwl_mvm_sf_update(struct iwl_mvm
*mvm
, struct ieee80211_vif
*changed_vif
,
278 enum iwl_sf_state new_state
;
279 u8 sta_id
= IWL_MVM_STATION_COUNT
;
280 struct iwl_mvm_vif
*mvmvif
= NULL
;
281 struct iwl_mvm_active_iface_iterator_data data
= {
282 .ignore_vif
= changed_vif
,
283 .sta_vif_state
= SF_UNINIT
,
284 .sta_vif_ap_sta_id
= IWL_MVM_STATION_COUNT
,
288 * Ignore the call if we are in HW Restart flow, or if the handled
289 * vif is a p2p device.
291 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) ||
292 (changed_vif
&& changed_vif
->type
== NL80211_IFTYPE_P2P_DEVICE
))
295 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
296 IEEE80211_IFACE_ITER_NORMAL
,
297 iwl_mvm_bound_iface_iterator
,
300 /* If changed_vif exists and is not to be removed, add to the count */
301 if (changed_vif
&& !remove_vif
)
302 data
.num_active_macs
++;
304 switch (data
.num_active_macs
) {
306 /* If there are no active macs - change state to SF_INIT_OFF */
307 new_state
= SF_INIT_OFF
;
311 /* The one active mac left is of type station
312 * and we filled the relevant data during iteration
314 new_state
= data
.sta_vif_state
;
315 sta_id
= data
.sta_vif_ap_sta_id
;
317 if (WARN_ON(!changed_vif
))
319 if (changed_vif
->type
!= NL80211_IFTYPE_STATION
) {
320 new_state
= SF_UNINIT
;
321 } else if (changed_vif
->bss_conf
.assoc
&&
322 changed_vif
->bss_conf
.dtim_period
) {
323 mvmvif
= iwl_mvm_vif_from_mac80211(changed_vif
);
324 sta_id
= mvmvif
->ap_sta_id
;
325 new_state
= SF_FULL_ON
;
327 new_state
= SF_INIT_OFF
;
332 /* If there are multiple active macs - change to SF_UNINIT */
333 new_state
= SF_UNINIT
;
335 return iwl_mvm_sf_config(mvm
, sta_id
, new_state
);