blob: 7ed94a089d5e1837fa02142085254b0292734a6d [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 *
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64#include <linux/jiffies.h>
65#include <net/mac80211.h>
66
67#include "iwl-notif-wait.h"
68#include "iwl-trans.h"
69#include "fw-api.h"
70#include "time-event.h"
71#include "mvm.h"
72#include "iwl-io.h"
73#include "iwl-prph.h"
74
75/* A TimeUnit is 1024 microsecond */
76#define TU_TO_JIFFIES(_tu) (usecs_to_jiffies((_tu) * 1024))
77#define MSEC_TO_TU(_msec) (_msec*1000/1024)
78
Ilan Peere635c792013-02-13 11:05:18 +020079/*
80 * For the high priority TE use a time event type that has similar priority to
81 * the FW's action scan priority.
Ilan Peer456f6dd2013-02-04 14:09:37 +020082 */
Ilan Peere635c792013-02-13 11:05:18 +020083#define IWL_MVM_ROC_TE_TYPE_NORMAL TE_P2P_DEVICE_DISCOVERABLE
84#define IWL_MVM_ROC_TE_TYPE_MGMT_TX TE_P2P_CLIENT_ASSOC
Ilan Peer456f6dd2013-02-04 14:09:37 +020085
Johannes Berg8ca151b2013-01-24 14:25:36 +010086void iwl_mvm_te_clear_data(struct iwl_mvm *mvm,
87 struct iwl_mvm_time_event_data *te_data)
88{
89 lockdep_assert_held(&mvm->time_event_lock);
90
91 if (te_data->id == TE_MAX)
92 return;
93
94 list_del(&te_data->list);
95 te_data->running = false;
96 te_data->uid = 0;
97 te_data->id = TE_MAX;
98 te_data->vif = NULL;
99}
100
101void iwl_mvm_roc_done_wk(struct work_struct *wk)
102{
103 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, roc_done_wk);
104
105 synchronize_net();
106
107 /*
108 * Flush the offchannel queue -- this is called when the time
109 * event finishes or is cancelled, so that frames queued for it
110 * won't get stuck on the queue and be transmitted in the next
111 * time event.
112 * We have to send the command asynchronously since this cannot
113 * be under the mutex for locking reasons, but that's not an
114 * issue as it will have to complete before the next command is
115 * executed, and a new time event means a new command.
116 */
Ilan Peer398e8c62013-03-13 15:20:35 +0200117 iwl_mvm_flush_tx_path(mvm, BIT(IWL_MVM_OFFCHANNEL_QUEUE), false);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100118}
119
120static void iwl_mvm_roc_finished(struct iwl_mvm *mvm)
121{
122 /*
123 * First, clear the ROC_RUNNING status bit. This will cause the TX
124 * path to drop offchannel transmissions. That would also be done
125 * by mac80211, but it is racy, in particular in the case that the
126 * time event actually completed in the firmware (which is handled
127 * in iwl_mvm_te_handle_notif).
128 */
129 clear_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
130
131 /*
132 * Of course, our status bit is just as racy as mac80211, so in
133 * addition, fire off the work struct which will drop all frames
134 * from the hardware queues that made it through the race. First
135 * it will of course synchronize the TX path to make sure that
136 * any *new* TX will be rejected.
137 */
138 schedule_work(&mvm->roc_done_wk);
139}
140
141/*
142 * Handles a FW notification for an event that is known to the driver.
143 *
144 * @mvm: the mvm component
145 * @te_data: the time event data
146 * @notif: the notification data corresponding the time event data.
147 */
148static void iwl_mvm_te_handle_notif(struct iwl_mvm *mvm,
149 struct iwl_mvm_time_event_data *te_data,
150 struct iwl_time_event_notif *notif)
151{
152 lockdep_assert_held(&mvm->time_event_lock);
153
154 IWL_DEBUG_TE(mvm, "Handle time event notif - UID = 0x%x action %d\n",
155 le32_to_cpu(notif->unique_id),
156 le32_to_cpu(notif->action));
157
158 /*
159 * The FW sends the start/end time event notifications even for events
160 * that it fails to schedule. This is indicated in the status field of
161 * the notification. This happens in cases that the scheduler cannot
162 * find a schedule that can handle the event (for example requesting a
163 * P2P Device discoveribility, while there are other higher priority
164 * events in the system).
165 */
166 WARN_ONCE(!le32_to_cpu(notif->status),
167 "Failed to schedule time event\n");
168
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300169 if (le32_to_cpu(notif->action) & TE_V2_NOTIF_HOST_EVENT_END) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100170 IWL_DEBUG_TE(mvm,
171 "TE ended - current time %lu, estimated end %lu\n",
172 jiffies, te_data->end_jiffies);
173
174 if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
175 ieee80211_remain_on_channel_expired(mvm->hw);
176 iwl_mvm_roc_finished(mvm);
177 }
178
179 /*
180 * By now, we should have finished association
181 * and know the dtim period.
182 */
183 if (te_data->vif->type == NL80211_IFTYPE_STATION &&
184 (!te_data->vif->bss_conf.assoc ||
Johannes Berg210a5442013-01-24 23:48:23 +0100185 !te_data->vif->bss_conf.dtim_period)) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100186 IWL_ERR(mvm,
187 "No assocation and the time event is over already...\n");
Johannes Berg210a5442013-01-24 23:48:23 +0100188 ieee80211_connection_loss(te_data->vif);
189 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100190
191 iwl_mvm_te_clear_data(mvm, te_data);
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300192 } else if (le32_to_cpu(notif->action) & TE_V2_NOTIF_HOST_EVENT_START) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100193 te_data->running = true;
194 te_data->end_jiffies = jiffies +
195 TU_TO_JIFFIES(te_data->duration);
196
197 if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
198 set_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status);
199 ieee80211_ready_on_channel(mvm->hw);
200 }
201 } else {
202 IWL_WARN(mvm, "Got TE with unknown action\n");
203 }
204}
205
206/*
207 * The Rx handler for time event notifications
208 */
209int iwl_mvm_rx_time_event_notif(struct iwl_mvm *mvm,
210 struct iwl_rx_cmd_buffer *rxb,
211 struct iwl_device_cmd *cmd)
212{
213 struct iwl_rx_packet *pkt = rxb_addr(rxb);
214 struct iwl_time_event_notif *notif = (void *)pkt->data;
215 struct iwl_mvm_time_event_data *te_data, *tmp;
216
217 IWL_DEBUG_TE(mvm, "Time event notification - UID = 0x%x action %d\n",
218 le32_to_cpu(notif->unique_id),
219 le32_to_cpu(notif->action));
220
221 spin_lock_bh(&mvm->time_event_lock);
222 list_for_each_entry_safe(te_data, tmp, &mvm->time_event_list, list) {
223 if (le32_to_cpu(notif->unique_id) == te_data->uid)
224 iwl_mvm_te_handle_notif(mvm, te_data, notif);
225 }
226 spin_unlock_bh(&mvm->time_event_lock);
227
228 return 0;
229}
230
Johannes Bergffdf9682013-01-29 15:28:17 +0100231static bool iwl_mvm_time_event_response(struct iwl_notif_wait_data *notif_wait,
232 struct iwl_rx_packet *pkt, void *data)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100233{
234 struct iwl_mvm *mvm =
235 container_of(notif_wait, struct iwl_mvm, notif_wait);
236 struct iwl_mvm_time_event_data *te_data = data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100237 struct iwl_time_event_resp *resp;
Johannes Bergffdf9682013-01-29 15:28:17 +0100238 int resp_len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100239
Johannes Bergffdf9682013-01-29 15:28:17 +0100240 if (WARN_ON(pkt->hdr.cmd != TIME_EVENT_CMD))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100241 return true;
242
Johannes Bergffdf9682013-01-29 15:28:17 +0100243 if (WARN_ON_ONCE(resp_len != sizeof(pkt->hdr) + sizeof(*resp))) {
244 IWL_ERR(mvm, "Invalid TIME_EVENT_CMD response\n");
245 return true;
246 }
247
248 resp = (void *)pkt->data;
Johannes Berge3722822013-02-16 00:11:34 +0100249
250 /* we should never get a response to another TIME_EVENT_CMD here */
251 if (WARN_ON_ONCE(le32_to_cpu(resp->id) != te_data->id))
252 return false;
253
Johannes Bergffdf9682013-01-29 15:28:17 +0100254 te_data->uid = le32_to_cpu(resp->unique_id);
255 IWL_DEBUG_TE(mvm, "TIME_EVENT_CMD response - UID = 0x%x\n",
256 te_data->uid);
257 return true;
258}
259
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300260/* used to convert from time event API v2 to v1 */
261#define TE_V2_DEP_POLICY_MSK (TE_V2_DEP_OTHER | TE_V2_DEP_TSF |\
262 TE_V2_EVENT_SOCIOPATHIC)
263static inline u16 te_v2_get_notify(__le16 policy)
264{
265 return le16_to_cpu(policy) & TE_V2_NOTIF_MSK;
266}
267
268static inline u16 te_v2_get_dep_policy(__le16 policy)
269{
270 return (le16_to_cpu(policy) & TE_V2_DEP_POLICY_MSK) >>
271 TE_V2_PLACEMENT_POS;
272}
273
274static inline u16 te_v2_get_absence(__le16 policy)
275{
276 return (le16_to_cpu(policy) & TE_V2_ABSENCE) >> TE_V2_ABSENCE_POS;
277}
278
279static void iwl_mvm_te_v2_to_v1(const struct iwl_time_event_cmd_v2 *cmd_v2,
280 struct iwl_time_event_cmd_v1 *cmd_v1)
281{
282 cmd_v1->id_and_color = cmd_v2->id_and_color;
283 cmd_v1->action = cmd_v2->action;
284 cmd_v1->id = cmd_v2->id;
285 cmd_v1->apply_time = cmd_v2->apply_time;
286 cmd_v1->max_delay = cmd_v2->max_delay;
287 cmd_v1->depends_on = cmd_v2->depends_on;
288 cmd_v1->interval = cmd_v2->interval;
289 cmd_v1->duration = cmd_v2->duration;
290 if (cmd_v2->repeat == TE_V2_REPEAT_ENDLESS)
291 cmd_v1->repeat = cpu_to_le32(TE_V1_REPEAT_ENDLESS);
292 else
293 cmd_v1->repeat = cpu_to_le32(cmd_v2->repeat);
294 cmd_v1->max_frags = cpu_to_le32(cmd_v2->max_frags);
295 cmd_v1->interval_reciprocal = 0; /* unused */
296
297 cmd_v1->dep_policy = cpu_to_le32(te_v2_get_dep_policy(cmd_v2->policy));
298 cmd_v1->is_present = cpu_to_le32(!te_v2_get_absence(cmd_v2->policy));
299 cmd_v1->notify = cpu_to_le32(te_v2_get_notify(cmd_v2->policy));
300}
301
302static int iwl_mvm_send_time_event_cmd(struct iwl_mvm *mvm,
303 const struct iwl_time_event_cmd_v2 *cmd)
304{
305 struct iwl_time_event_cmd_v1 cmd_v1;
306
307 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_TIME_EVENT_API_V2)
308 return iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC,
309 sizeof(*cmd), cmd);
310
311 iwl_mvm_te_v2_to_v1(cmd, &cmd_v1);
312 return iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC,
313 sizeof(cmd_v1), &cmd_v1);
314}
315
316
Johannes Bergffdf9682013-01-29 15:28:17 +0100317static int iwl_mvm_time_event_send_add(struct iwl_mvm *mvm,
318 struct ieee80211_vif *vif,
319 struct iwl_mvm_time_event_data *te_data,
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300320 struct iwl_time_event_cmd_v2 *te_cmd)
Johannes Bergffdf9682013-01-29 15:28:17 +0100321{
322 static const u8 time_event_response[] = { TIME_EVENT_CMD };
323 struct iwl_notification_wait wait_time_event;
324 int ret;
325
326 lockdep_assert_held(&mvm->mutex);
327
Johannes Berg93630dc2013-02-15 23:54:10 +0100328 IWL_DEBUG_TE(mvm, "Add new TE, duration %d TU\n",
329 le32_to_cpu(te_cmd->duration));
330
Johannes Bergffdf9682013-01-29 15:28:17 +0100331 spin_lock_bh(&mvm->time_event_lock);
332 if (WARN_ON(te_data->id != TE_MAX)) {
333 spin_unlock_bh(&mvm->time_event_lock);
334 return -EIO;
335 }
336 te_data->vif = vif;
337 te_data->duration = le32_to_cpu(te_cmd->duration);
338 te_data->id = le32_to_cpu(te_cmd->id);
339 list_add_tail(&te_data->list, &mvm->time_event_list);
340 spin_unlock_bh(&mvm->time_event_lock);
341
342 /*
343 * Use a notification wait, which really just processes the
344 * command response and doesn't wait for anything, in order
345 * to be able to process the response and get the UID inside
346 * the RX path. Using CMD_WANT_SKB doesn't work because it
347 * stores the buffer and then wakes up this thread, by which
348 * time another notification (that the time event started)
349 * might already be processed unsuccessfully.
350 */
351 iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
352 time_event_response,
353 ARRAY_SIZE(time_event_response),
354 iwl_mvm_time_event_response, te_data);
355
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300356 ret = iwl_mvm_send_time_event_cmd(mvm, te_cmd);
Johannes Bergffdf9682013-01-29 15:28:17 +0100357 if (ret) {
358 IWL_ERR(mvm, "Couldn't send TIME_EVENT_CMD: %d\n", ret);
359 iwl_remove_notification(&mvm->notif_wait, &wait_time_event);
360 goto out_clear_te;
361 }
362
363 /* No need to wait for anything, so just pass 1 (0 isn't valid) */
364 ret = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1);
365 /* should never fail */
366 WARN_ON_ONCE(ret);
367
368 if (ret) {
369 out_clear_te:
370 spin_lock_bh(&mvm->time_event_lock);
371 iwl_mvm_te_clear_data(mvm, te_data);
372 spin_unlock_bh(&mvm->time_event_lock);
373 }
374 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100375}
376
377void iwl_mvm_protect_session(struct iwl_mvm *mvm,
378 struct ieee80211_vif *vif,
379 u32 duration, u32 min_duration)
380{
381 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
382 struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300383 struct iwl_time_event_cmd_v2 time_cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100384
385 lockdep_assert_held(&mvm->mutex);
386
387 if (te_data->running &&
388 time_after(te_data->end_jiffies,
389 jiffies + TU_TO_JIFFIES(min_duration))) {
390 IWL_DEBUG_TE(mvm, "We have enough time in the current TE: %u\n",
391 jiffies_to_msecs(te_data->end_jiffies - jiffies));
392 return;
393 }
394
395 if (te_data->running) {
396 IWL_DEBUG_TE(mvm, "extend 0x%x: only %u ms left\n",
397 te_data->uid,
398 jiffies_to_msecs(te_data->end_jiffies - jiffies));
399 /*
400 * we don't have enough time
401 * cancel the current TE and issue a new one
402 * Of course it would be better to remove the old one only
403 * when the new one is added, but we don't care if we are off
404 * channel for a bit. All we need to do, is not to return
405 * before we actually begin to be on the channel.
406 */
407 iwl_mvm_stop_session_protection(mvm, vif);
408 }
409
Johannes Berg8ca151b2013-01-24 14:25:36 +0100410 time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
411 time_cmd.id_and_color =
412 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
413 time_cmd.id = cpu_to_le32(TE_BSS_STA_AGGRESSIVE_ASSOC);
414
415 time_cmd.apply_time =
416 cpu_to_le32(iwl_read_prph(mvm->trans, DEVICE_SYSTEM_TIME_REG));
Johannes Bergffdf9682013-01-29 15:28:17 +0100417
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300418 time_cmd.max_frags = TE_V2_FRAG_NONE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100419 time_cmd.max_delay = cpu_to_le32(500);
420 /* TODO: why do we need to interval = bi if it is not periodic? */
421 time_cmd.interval = cpu_to_le32(1);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100422 time_cmd.duration = cpu_to_le32(duration);
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300423 time_cmd.repeat = 1;
424 time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START |
425 TE_V2_NOTIF_HOST_EVENT_END);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100426
Johannes Bergffdf9682013-01-29 15:28:17 +0100427 iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100428}
429
430/*
431 * Explicit request to remove a time event. The removal of a time event needs to
432 * be synchronized with the flow of a time event's end notification, which also
433 * removes the time event from the op mode data structures.
434 */
435void iwl_mvm_remove_time_event(struct iwl_mvm *mvm,
436 struct iwl_mvm_vif *mvmvif,
437 struct iwl_mvm_time_event_data *te_data)
438{
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300439 struct iwl_time_event_cmd_v2 time_cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100440 u32 id, uid;
441 int ret;
442
443 /*
444 * It is possible that by the time we got to this point the time
445 * event was already removed.
446 */
447 spin_lock_bh(&mvm->time_event_lock);
448
449 /* Save time event uid before clearing its data */
450 uid = te_data->uid;
451 id = te_data->id;
452
453 /*
454 * The clear_data function handles time events that were already removed
455 */
456 iwl_mvm_te_clear_data(mvm, te_data);
457 spin_unlock_bh(&mvm->time_event_lock);
458
459 /*
460 * It is possible that by the time we try to remove it, the time event
461 * has already ended and removed. In such a case there is no need to
462 * send a removal command.
463 */
464 if (id == TE_MAX) {
465 IWL_DEBUG_TE(mvm, "TE 0x%x has already ended\n", uid);
466 return;
467 }
468
469 /* When we remove a TE, the UID is to be set in the id field */
470 time_cmd.id = cpu_to_le32(uid);
471 time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE);
472 time_cmd.id_and_color =
473 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
474
475 IWL_DEBUG_TE(mvm, "Removing TE 0x%x\n", le32_to_cpu(time_cmd.id));
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300476 ret = iwl_mvm_send_time_event_cmd(mvm, &time_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100477 if (WARN_ON(ret))
478 return;
479}
480
481void iwl_mvm_stop_session_protection(struct iwl_mvm *mvm,
482 struct ieee80211_vif *vif)
483{
484 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
485 struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
486
487 lockdep_assert_held(&mvm->mutex);
488 iwl_mvm_remove_time_event(mvm, mvmvif, te_data);
489}
490
Johannes Berg8ca151b2013-01-24 14:25:36 +0100491int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Ilan Peere635c792013-02-13 11:05:18 +0200492 int duration, enum ieee80211_roc_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100493{
494 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
495 struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data;
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300496 struct iwl_time_event_cmd_v2 time_cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100497
498 lockdep_assert_held(&mvm->mutex);
499 if (te_data->running) {
500 IWL_WARN(mvm, "P2P_DEVICE remain on channel already running\n");
501 return -EBUSY;
502 }
503
504 /*
505 * Flush the done work, just in case it's still pending, so that
506 * the work it does can complete and we can accept new frames.
507 */
508 flush_work(&mvm->roc_done_wk);
509
Johannes Berg8ca151b2013-01-24 14:25:36 +0100510 time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
511 time_cmd.id_and_color =
512 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color));
Ilan Peere635c792013-02-13 11:05:18 +0200513
514 switch (type) {
515 case IEEE80211_ROC_TYPE_NORMAL:
516 time_cmd.id = cpu_to_le32(IWL_MVM_ROC_TE_TYPE_NORMAL);
517 break;
518 case IEEE80211_ROC_TYPE_MGMT_TX:
519 time_cmd.id = cpu_to_le32(IWL_MVM_ROC_TE_TYPE_MGMT_TX);
520 break;
521 default:
522 WARN_ONCE(1, "Got an invalid ROC type\n");
523 return -EINVAL;
524 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100525
526 time_cmd.apply_time = cpu_to_le32(0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100527 time_cmd.interval = cpu_to_le32(1);
528
529 /*
Ilan Peere635c792013-02-13 11:05:18 +0200530 * The P2P Device TEs can have lower priority than other events
Johannes Berg8ca151b2013-01-24 14:25:36 +0100531 * that are being scheduled by the driver/fw, and thus it might not be
Ilan Peere635c792013-02-13 11:05:18 +0200532 * scheduled. To improve the chances of it being scheduled, allow them
533 * to be fragmented, and in addition allow them to be delayed.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100534 */
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300535 time_cmd.max_frags = min(MSEC_TO_TU(duration)/50, TE_V2_FRAG_ENDLESS);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100536 time_cmd.max_delay = cpu_to_le32(MSEC_TO_TU(duration/2));
537 time_cmd.duration = cpu_to_le32(MSEC_TO_TU(duration));
Eytan Lifshitzf8f03c32013-08-07 19:36:42 +0300538 time_cmd.repeat = 1;
539 time_cmd.policy = cpu_to_le16(TE_V2_NOTIF_HOST_EVENT_START |
540 TE_V2_NOTIF_HOST_EVENT_END);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100541
Johannes Bergffdf9682013-01-29 15:28:17 +0100542 return iwl_mvm_time_event_send_add(mvm, vif, te_data, &time_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100543}
544
545void iwl_mvm_stop_p2p_roc(struct iwl_mvm *mvm)
546{
547 struct iwl_mvm_vif *mvmvif;
548 struct iwl_mvm_time_event_data *te_data;
549
550 lockdep_assert_held(&mvm->mutex);
551
552 /*
553 * Iterate over the list of time events and find the time event that is
554 * associated with a P2P_DEVICE interface.
555 * This assumes that a P2P_DEVICE interface can have only a single time
556 * event at any given time and this time event coresponds to a ROC
557 * request
558 */
559 mvmvif = NULL;
560 spin_lock_bh(&mvm->time_event_lock);
561 list_for_each_entry(te_data, &mvm->time_event_list, list) {
562 if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) {
563 mvmvif = iwl_mvm_vif_from_mac80211(te_data->vif);
564 break;
565 }
566 }
567 spin_unlock_bh(&mvm->time_event_lock);
568
569 if (!mvmvif) {
570 IWL_WARN(mvm, "P2P_DEVICE no remain on channel event\n");
571 return;
572 }
573
574 iwl_mvm_remove_time_event(mvm, mvmvif, te_data);
575
576 iwl_mvm_roc_finished(mvm);
577}