blob: f88410c7cbfbadb608b3a79fe72841a5f4bcd475 [file] [log] [blame]
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001/******************************************************************************
2 *
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.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +020010 *
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.
14 *
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.
19 *
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,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
27 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2013 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020035 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +020036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
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
47 * distribution.
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.
51 *
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.
63 *
64 *****************************************************************************/
65#include "mvm.h"
66
67/* For counting bound interfaces */
68struct iwl_mvm_active_iface_iterator_data {
69 struct ieee80211_vif *ignore_vif;
70 u8 sta_vif_ap_sta_id;
71 enum iwl_sf_state sta_vif_state;
72 int num_active_macs;
73};
74
75/*
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.
78 */
79static void iwl_mvm_bound_iface_iterator(void *_data, u8 *mac,
80 struct ieee80211_vif *vif)
81{
82 struct iwl_mvm_active_iface_iterator_data *data = _data;
83 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
84
85 if (vif == data->ignore_vif || !mvmvif->phy_ctxt ||
86 vif->type == NL80211_IFTYPE_P2P_DEVICE)
87 return;
88
89 data->num_active_macs++;
90
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;
95 else
96 data->sta_vif_state = SF_INIT_OFF;
97 }
98}
99
100/*
101 * Aging and idle timeouts for the different possible scenarios
102 * in SF_FULL_ON state.
103 */
104static const __le32 sf_full_timeout[SF_NUM_SCENARIO][SF_NUM_TIMEOUT_TYPES] = {
105 {
106 cpu_to_le32(SF_SINGLE_UNICAST_AGING_TIMER),
107 cpu_to_le32(SF_SINGLE_UNICAST_IDLE_TIMER)
108 },
109 {
110 cpu_to_le32(SF_AGG_UNICAST_AGING_TIMER),
111 cpu_to_le32(SF_AGG_UNICAST_IDLE_TIMER)
112 },
113 {
114 cpu_to_le32(SF_MCAST_AGING_TIMER),
115 cpu_to_le32(SF_MCAST_IDLE_TIMER)
116 },
117 {
118 cpu_to_le32(SF_BA_AGING_TIMER),
119 cpu_to_le32(SF_BA_IDLE_TIMER)
120 },
121 {
122 cpu_to_le32(SF_TX_RE_AGING_TIMER),
123 cpu_to_le32(SF_TX_RE_IDLE_TIMER)
124 },
125};
126
127static void iwl_mvm_fill_sf_command(struct iwl_sf_cfg_cmd *sf_cmd,
128 struct ieee80211_sta *sta)
129{
130 int i, j, watermark;
131
132 sf_cmd->watermark[SF_LONG_DELAY_ON] = cpu_to_le32(SF_W_MARK_SCAN);
133
134 /*
135 * If we are in association flow - check antenna configuration
136 * capabilities of the AP station, and choose the watermark accordingly.
137 */
138 if (sta) {
139 if (sta->ht_cap.ht_supported || sta->vht_cap.vht_supported) {
140 switch (sta->rx_nss) {
141 case 1:
142 watermark = SF_W_MARK_SISO;
143 break;
144 case 2:
145 watermark = SF_W_MARK_MIMO2;
146 break;
147 default:
148 watermark = SF_W_MARK_MIMO3;
149 break;
150 }
151 } else {
152 watermark = SF_W_MARK_LEGACY;
153 }
154 /* default watermark value for unassociated mode. */
155 } else {
156 watermark = SF_W_MARK_MIMO2;
157 }
158 sf_cmd->watermark[SF_FULL_ON] = cpu_to_le32(watermark);
159
160 for (i = 0; i < SF_NUM_SCENARIO; i++) {
161 for (j = 0; j < SF_NUM_TIMEOUT_TYPES; j++) {
162 sf_cmd->long_delay_timeouts[i][j] =
163 cpu_to_le32(SF_LONG_DELAY_AGING_TIMER);
164 }
165 }
166 BUILD_BUG_ON(sizeof(sf_full_timeout) !=
167 sizeof(__le32) * SF_NUM_SCENARIO * SF_NUM_TIMEOUT_TYPES);
168
169 memcpy(sf_cmd->full_on_timeouts, sf_full_timeout,
170 sizeof(sf_full_timeout));
171}
172
173static int iwl_mvm_sf_config(struct iwl_mvm *mvm, u8 sta_id,
174 enum iwl_sf_state new_state)
175{
176 struct iwl_sf_cfg_cmd sf_cmd = {
Emmanuel Grumbach86974bf2014-07-31 14:32:37 +0300177 .state = cpu_to_le32(new_state),
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +0200178 };
179 struct ieee80211_sta *sta;
180 int ret = 0;
181
182 /*
183 * If an associated AP sta changed its antenna configuration, the state
184 * will remain FULL_ON but SF parameters need to be reconsidered.
185 */
186 if (new_state != SF_FULL_ON && mvm->sf_state == new_state)
187 return 0;
188
189 switch (new_state) {
190 case SF_UNINIT:
191 break;
192 case SF_FULL_ON:
193 if (sta_id == IWL_MVM_STATION_COUNT) {
194 IWL_ERR(mvm,
195 "No station: Cannot switch SF to FULL_ON\n");
196 return -EINVAL;
197 }
198 rcu_read_lock();
199 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
200 if (IS_ERR_OR_NULL(sta)) {
201 IWL_ERR(mvm, "Invalid station id\n");
202 rcu_read_unlock();
203 return -EINVAL;
204 }
205 iwl_mvm_fill_sf_command(&sf_cmd, sta);
206 rcu_read_unlock();
207 break;
208 case SF_INIT_OFF:
209 iwl_mvm_fill_sf_command(&sf_cmd, NULL);
210 break;
211 default:
212 WARN_ONCE(1, "Invalid state: %d. not sending Smart Fifo cmd\n",
213 new_state);
214 return -EINVAL;
215 }
216
217 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_SF_CFG_CMD, CMD_ASYNC,
218 sizeof(sf_cmd), &sf_cmd);
219 if (!ret)
220 mvm->sf_state = new_state;
221
222 return ret;
223}
224
225/*
226 * Update Smart fifo:
227 * Count bound interfaces that are not to be removed, ignoring p2p devices,
228 * and set new state accordingly.
229 */
230int iwl_mvm_sf_update(struct iwl_mvm *mvm, struct ieee80211_vif *changed_vif,
231 bool remove_vif)
232{
233 enum iwl_sf_state new_state;
234 u8 sta_id = IWL_MVM_STATION_COUNT;
235 struct iwl_mvm_vif *mvmvif = NULL;
236 struct iwl_mvm_active_iface_iterator_data data = {
237 .ignore_vif = changed_vif,
238 .sta_vif_state = SF_UNINIT,
239 .sta_vif_ap_sta_id = IWL_MVM_STATION_COUNT,
240 };
241
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +0200242 /*
243 * Ignore the call if we are in HW Restart flow, or if the handled
244 * vif is a p2p device.
245 */
246 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
247 (changed_vif && changed_vif->type == NL80211_IFTYPE_P2P_DEVICE))
248 return 0;
249
250 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
251 IEEE80211_IFACE_ITER_NORMAL,
252 iwl_mvm_bound_iface_iterator,
253 &data);
254
255 /* If changed_vif exists and is not to be removed, add to the count */
256 if (changed_vif && !remove_vif)
257 data.num_active_macs++;
258
259 switch (data.num_active_macs) {
260 case 0:
261 /* If there are no active macs - change state to SF_INIT_OFF */
262 new_state = SF_INIT_OFF;
263 break;
264 case 1:
265 if (remove_vif) {
266 /* The one active mac left is of type station
267 * and we filled the relevant data during iteration
268 */
269 new_state = data.sta_vif_state;
270 sta_id = data.sta_vif_ap_sta_id;
271 } else {
272 if (WARN_ON(!changed_vif))
273 return -EINVAL;
274 if (changed_vif->type != NL80211_IFTYPE_STATION) {
275 new_state = SF_UNINIT;
Johannes Berg0229cda2014-03-19 18:36:39 +0100276 } else if (changed_vif->bss_conf.assoc &&
277 changed_vif->bss_conf.dtim_period) {
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +0200278 mvmvif = iwl_mvm_vif_from_mac80211(changed_vif);
279 sta_id = mvmvif->ap_sta_id;
280 new_state = SF_FULL_ON;
281 } else {
282 new_state = SF_INIT_OFF;
283 }
284 }
285 break;
286 default:
287 /* If there are multiple active macs - change to SF_UNINIT */
288 new_state = SF_UNINIT;
289 }
290 return iwl_mvm_sf_config(mvm, sta_id, new_state);
291}