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 * The full GNU General Public License is included in this distribution
21 * in the file called COPYING.
23 * Contact Information:
24 * Intel Linux Wireless <linuxwifi@intel.com>
25 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
29 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
30 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
31 * All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
37 * * Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * * Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in
41 * the documentation and/or other materials provided with the
43 * * Neither the name Intel Corporation nor the names of its
44 * contributors may be used to endorse or promote products derived
45 * from this software without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
48 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
49 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
50 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
51 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
57 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 *****************************************************************************/
62 /* For counting bound interfaces */
63 struct iwl_mvm_active_iface_iterator_data {
64 struct ieee80211_vif *ignore_vif;
66 enum iwl_sf_state sta_vif_state;
71 * Count bound interfaces which are not p2p, besides data->ignore_vif.
72 * data->station_vif will point to one bound vif of type station, if exists.
74 static void iwl_mvm_bound_iface_iterator(void *_data, u8 *mac,
75 struct ieee80211_vif *vif)
77 struct iwl_mvm_active_iface_iterator_data *data = _data;
78 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
80 if (vif == data->ignore_vif || !mvmvif->phy_ctxt ||
81 vif->type == NL80211_IFTYPE_P2P_DEVICE)
84 data->num_active_macs++;
86 if (vif->type == NL80211_IFTYPE_STATION) {
87 data->sta_vif_ap_sta_id = mvmvif->ap_sta_id;
88 if (vif->bss_conf.assoc)
89 data->sta_vif_state = SF_FULL_ON;
91 data->sta_vif_state = SF_INIT_OFF;
96 * Aging and idle timeouts for the different possible scenarios
97 * in default configuration
100 __le32 sf_full_timeout_def[SF_NUM_SCENARIO][SF_NUM_TIMEOUT_TYPES] = {
102 cpu_to_le32(SF_SINGLE_UNICAST_AGING_TIMER_DEF),
103 cpu_to_le32(SF_SINGLE_UNICAST_IDLE_TIMER_DEF)
106 cpu_to_le32(SF_AGG_UNICAST_AGING_TIMER_DEF),
107 cpu_to_le32(SF_AGG_UNICAST_IDLE_TIMER_DEF)
110 cpu_to_le32(SF_MCAST_AGING_TIMER_DEF),
111 cpu_to_le32(SF_MCAST_IDLE_TIMER_DEF)
114 cpu_to_le32(SF_BA_AGING_TIMER_DEF),
115 cpu_to_le32(SF_BA_IDLE_TIMER_DEF)
118 cpu_to_le32(SF_TX_RE_AGING_TIMER_DEF),
119 cpu_to_le32(SF_TX_RE_IDLE_TIMER_DEF)
124 * Aging and idle timeouts for the different possible scenarios
125 * in single BSS MAC configuration.
127 static const __le32 sf_full_timeout[SF_NUM_SCENARIO][SF_NUM_TIMEOUT_TYPES] = {
129 cpu_to_le32(SF_SINGLE_UNICAST_AGING_TIMER),
130 cpu_to_le32(SF_SINGLE_UNICAST_IDLE_TIMER)
133 cpu_to_le32(SF_AGG_UNICAST_AGING_TIMER),
134 cpu_to_le32(SF_AGG_UNICAST_IDLE_TIMER)
137 cpu_to_le32(SF_MCAST_AGING_TIMER),
138 cpu_to_le32(SF_MCAST_IDLE_TIMER)
141 cpu_to_le32(SF_BA_AGING_TIMER),
142 cpu_to_le32(SF_BA_IDLE_TIMER)
145 cpu_to_le32(SF_TX_RE_AGING_TIMER),
146 cpu_to_le32(SF_TX_RE_IDLE_TIMER)
150 static void iwl_mvm_fill_sf_command(struct iwl_mvm *mvm,
151 struct iwl_sf_cfg_cmd *sf_cmd,
152 struct ieee80211_sta *sta)
156 sf_cmd->watermark[SF_LONG_DELAY_ON] = cpu_to_le32(SF_W_MARK_SCAN);
159 * If we are in association flow - check antenna configuration
160 * capabilities of the AP station, and choose the watermark accordingly.
163 if (sta->ht_cap.ht_supported || sta->vht_cap.vht_supported) {
164 switch (sta->rx_nss) {
166 watermark = SF_W_MARK_SISO;
169 watermark = SF_W_MARK_MIMO2;
172 watermark = SF_W_MARK_MIMO3;
176 watermark = SF_W_MARK_LEGACY;
178 /* default watermark value for unassociated mode. */
180 watermark = SF_W_MARK_MIMO2;
182 sf_cmd->watermark[SF_FULL_ON] = cpu_to_le32(watermark);
184 for (i = 0; i < SF_NUM_SCENARIO; i++) {
185 for (j = 0; j < SF_NUM_TIMEOUT_TYPES; j++) {
186 sf_cmd->long_delay_timeouts[i][j] =
187 cpu_to_le32(SF_LONG_DELAY_AGING_TIMER);
192 BUILD_BUG_ON(sizeof(sf_full_timeout) !=
193 sizeof(__le32) * SF_NUM_SCENARIO *
194 SF_NUM_TIMEOUT_TYPES);
196 memcpy(sf_cmd->full_on_timeouts, sf_full_timeout,
197 sizeof(sf_full_timeout));
199 BUILD_BUG_ON(sizeof(sf_full_timeout_def) !=
200 sizeof(__le32) * SF_NUM_SCENARIO *
201 SF_NUM_TIMEOUT_TYPES);
203 memcpy(sf_cmd->full_on_timeouts, sf_full_timeout_def,
204 sizeof(sf_full_timeout_def));
209 static int iwl_mvm_sf_config(struct iwl_mvm *mvm, u8 sta_id,
210 enum iwl_sf_state new_state)
212 struct iwl_sf_cfg_cmd sf_cmd = {
213 .state = cpu_to_le32(new_state),
215 struct ieee80211_sta *sta;
218 if (mvm->cfg->disable_dummy_notification)
219 sf_cmd.state |= cpu_to_le32(SF_CFG_DUMMY_NOTIF_OFF);
222 * If an associated AP sta changed its antenna configuration, the state
223 * will remain FULL_ON but SF parameters need to be reconsidered.
225 if (new_state != SF_FULL_ON && mvm->sf_state == new_state)
230 iwl_mvm_fill_sf_command(mvm, &sf_cmd, NULL);
233 if (sta_id == IWL_MVM_INVALID_STA) {
235 "No station: Cannot switch SF to FULL_ON\n");
239 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
240 if (IS_ERR_OR_NULL(sta)) {
241 IWL_ERR(mvm, "Invalid station id\n");
245 iwl_mvm_fill_sf_command(mvm, &sf_cmd, sta);
249 iwl_mvm_fill_sf_command(mvm, &sf_cmd, NULL);
252 WARN_ONCE(1, "Invalid state: %d. not sending Smart Fifo cmd\n",
257 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_SF_CFG_CMD, CMD_ASYNC,
258 sizeof(sf_cmd), &sf_cmd);
260 mvm->sf_state = new_state;
267 * Count bound interfaces that are not to be removed, ignoring p2p devices,
268 * and set new state accordingly.
270 int iwl_mvm_sf_update(struct iwl_mvm *mvm, struct ieee80211_vif *changed_vif,
273 enum iwl_sf_state new_state;
274 u8 sta_id = IWL_MVM_INVALID_STA;
275 struct iwl_mvm_vif *mvmvif = NULL;
276 struct iwl_mvm_active_iface_iterator_data data = {
277 .ignore_vif = changed_vif,
278 .sta_vif_state = SF_UNINIT,
279 .sta_vif_ap_sta_id = IWL_MVM_INVALID_STA,
283 * Ignore the call if we are in HW Restart flow, or if the handled
284 * vif is a p2p device.
286 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
287 (changed_vif && changed_vif->type == NL80211_IFTYPE_P2P_DEVICE))
290 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
291 IEEE80211_IFACE_ITER_NORMAL,
292 iwl_mvm_bound_iface_iterator,
295 /* If changed_vif exists and is not to be removed, add to the count */
296 if (changed_vif && !remove_vif)
297 data.num_active_macs++;
299 switch (data.num_active_macs) {
301 /* If there are no active macs - change state to SF_INIT_OFF */
302 new_state = SF_INIT_OFF;
306 /* The one active mac left is of type station
307 * and we filled the relevant data during iteration
309 new_state = data.sta_vif_state;
310 sta_id = data.sta_vif_ap_sta_id;
312 if (WARN_ON(!changed_vif))
314 if (changed_vif->type != NL80211_IFTYPE_STATION) {
315 new_state = SF_UNINIT;
316 } else if (changed_vif->bss_conf.assoc &&
317 changed_vif->bss_conf.dtim_period) {
318 mvmvif = iwl_mvm_vif_from_mac80211(changed_vif);
319 sta_id = mvmvif->ap_sta_id;
320 new_state = SF_FULL_ON;
322 new_state = SF_INIT_OFF;
327 /* If there are multiple active macs - change to SF_UNINIT */
328 new_state = SF_UNINIT;
330 return iwl_mvm_sf_config(mvm, sta_id, new_state);