]>
Commit | Line | Data |
---|---|---|
8ca151b5 JB |
1 | /****************************************************************************** |
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 | |
25 | * in the file called LICENSE.GPL. | |
26 | * | |
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 | ||
79 | void iwl_mvm_te_clear_data(struct iwl_mvm *mvm, | |
80 | struct iwl_mvm_time_event_data *te_data) | |
81 | { | |
82 | lockdep_assert_held(&mvm->time_event_lock); | |
83 | ||
84 | if (te_data->id == TE_MAX) | |
85 | return; | |
86 | ||
87 | list_del(&te_data->list); | |
88 | te_data->running = false; | |
89 | te_data->uid = 0; | |
90 | te_data->id = TE_MAX; | |
91 | te_data->vif = NULL; | |
92 | } | |
93 | ||
94 | void iwl_mvm_roc_done_wk(struct work_struct *wk) | |
95 | { | |
96 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, roc_done_wk); | |
97 | ||
98 | synchronize_net(); | |
99 | ||
100 | /* | |
101 | * Flush the offchannel queue -- this is called when the time | |
102 | * event finishes or is cancelled, so that frames queued for it | |
103 | * won't get stuck on the queue and be transmitted in the next | |
104 | * time event. | |
105 | * We have to send the command asynchronously since this cannot | |
106 | * be under the mutex for locking reasons, but that's not an | |
107 | * issue as it will have to complete before the next command is | |
108 | * executed, and a new time event means a new command. | |
109 | */ | |
110 | iwl_mvm_flush_tx_path(mvm, BIT(IWL_OFFCHANNEL_QUEUE), false); | |
111 | } | |
112 | ||
113 | static void iwl_mvm_roc_finished(struct iwl_mvm *mvm) | |
114 | { | |
115 | /* | |
116 | * First, clear the ROC_RUNNING status bit. This will cause the TX | |
117 | * path to drop offchannel transmissions. That would also be done | |
118 | * by mac80211, but it is racy, in particular in the case that the | |
119 | * time event actually completed in the firmware (which is handled | |
120 | * in iwl_mvm_te_handle_notif). | |
121 | */ | |
122 | clear_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status); | |
123 | ||
124 | /* | |
125 | * Of course, our status bit is just as racy as mac80211, so in | |
126 | * addition, fire off the work struct which will drop all frames | |
127 | * from the hardware queues that made it through the race. First | |
128 | * it will of course synchronize the TX path to make sure that | |
129 | * any *new* TX will be rejected. | |
130 | */ | |
131 | schedule_work(&mvm->roc_done_wk); | |
132 | } | |
133 | ||
134 | /* | |
135 | * Handles a FW notification for an event that is known to the driver. | |
136 | * | |
137 | * @mvm: the mvm component | |
138 | * @te_data: the time event data | |
139 | * @notif: the notification data corresponding the time event data. | |
140 | */ | |
141 | static void iwl_mvm_te_handle_notif(struct iwl_mvm *mvm, | |
142 | struct iwl_mvm_time_event_data *te_data, | |
143 | struct iwl_time_event_notif *notif) | |
144 | { | |
145 | lockdep_assert_held(&mvm->time_event_lock); | |
146 | ||
147 | IWL_DEBUG_TE(mvm, "Handle time event notif - UID = 0x%x action %d\n", | |
148 | le32_to_cpu(notif->unique_id), | |
149 | le32_to_cpu(notif->action)); | |
150 | ||
151 | /* | |
152 | * The FW sends the start/end time event notifications even for events | |
153 | * that it fails to schedule. This is indicated in the status field of | |
154 | * the notification. This happens in cases that the scheduler cannot | |
155 | * find a schedule that can handle the event (for example requesting a | |
156 | * P2P Device discoveribility, while there are other higher priority | |
157 | * events in the system). | |
158 | */ | |
159 | WARN_ONCE(!le32_to_cpu(notif->status), | |
160 | "Failed to schedule time event\n"); | |
161 | ||
162 | if (le32_to_cpu(notif->action) == TE_NOTIF_HOST_END) { | |
163 | IWL_DEBUG_TE(mvm, | |
164 | "TE ended - current time %lu, estimated end %lu\n", | |
165 | jiffies, te_data->end_jiffies); | |
166 | ||
167 | if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
168 | ieee80211_remain_on_channel_expired(mvm->hw); | |
169 | iwl_mvm_roc_finished(mvm); | |
170 | } | |
171 | ||
172 | /* | |
173 | * By now, we should have finished association | |
174 | * and know the dtim period. | |
175 | */ | |
176 | if (te_data->vif->type == NL80211_IFTYPE_STATION && | |
177 | (!te_data->vif->bss_conf.assoc || | |
178 | !te_data->vif->bss_conf.dtim_period)) | |
179 | IWL_ERR(mvm, | |
180 | "No assocation and the time event is over already...\n"); | |
181 | ||
182 | iwl_mvm_te_clear_data(mvm, te_data); | |
183 | } else if (le32_to_cpu(notif->action) == TE_NOTIF_HOST_START) { | |
184 | te_data->running = true; | |
185 | te_data->end_jiffies = jiffies + | |
186 | TU_TO_JIFFIES(te_data->duration); | |
187 | ||
188 | if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
189 | set_bit(IWL_MVM_STATUS_ROC_RUNNING, &mvm->status); | |
190 | ieee80211_ready_on_channel(mvm->hw); | |
191 | } | |
192 | } else { | |
193 | IWL_WARN(mvm, "Got TE with unknown action\n"); | |
194 | } | |
195 | } | |
196 | ||
197 | /* | |
198 | * The Rx handler for time event notifications | |
199 | */ | |
200 | int iwl_mvm_rx_time_event_notif(struct iwl_mvm *mvm, | |
201 | struct iwl_rx_cmd_buffer *rxb, | |
202 | struct iwl_device_cmd *cmd) | |
203 | { | |
204 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
205 | struct iwl_time_event_notif *notif = (void *)pkt->data; | |
206 | struct iwl_mvm_time_event_data *te_data, *tmp; | |
207 | ||
208 | IWL_DEBUG_TE(mvm, "Time event notification - UID = 0x%x action %d\n", | |
209 | le32_to_cpu(notif->unique_id), | |
210 | le32_to_cpu(notif->action)); | |
211 | ||
212 | spin_lock_bh(&mvm->time_event_lock); | |
213 | list_for_each_entry_safe(te_data, tmp, &mvm->time_event_list, list) { | |
214 | if (le32_to_cpu(notif->unique_id) == te_data->uid) | |
215 | iwl_mvm_te_handle_notif(mvm, te_data, notif); | |
216 | } | |
217 | spin_unlock_bh(&mvm->time_event_lock); | |
218 | ||
219 | return 0; | |
220 | } | |
221 | ||
222 | static bool iwl_mvm_time_event_notif(struct iwl_notif_wait_data *notif_wait, | |
223 | struct iwl_rx_packet *pkt, void *data) | |
224 | { | |
225 | struct iwl_mvm *mvm = | |
226 | container_of(notif_wait, struct iwl_mvm, notif_wait); | |
227 | struct iwl_mvm_time_event_data *te_data = data; | |
228 | struct ieee80211_vif *vif = te_data->vif; | |
229 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
230 | struct iwl_time_event_notif *notif; | |
231 | struct iwl_time_event_resp *resp; | |
232 | ||
233 | u32 mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color); | |
234 | ||
235 | /* until we do something else */ | |
236 | WARN_ON(te_data->id != TE_BSS_STA_AGGRESSIVE_ASSOC); | |
237 | ||
238 | switch (pkt->hdr.cmd) { | |
239 | case TIME_EVENT_CMD: | |
240 | resp = (void *)pkt->data; | |
241 | /* TODO: I can't check that since the fw is buggy - it doesn't | |
242 | * put the right values when we remove a TE. We can be here | |
243 | * when we remove a TE because the remove TE command is sent in | |
244 | * ASYNC... | |
245 | * WARN_ON(mac_id_n_color != le32_to_cpu(resp->id_and_color)); | |
246 | */ | |
247 | te_data->uid = le32_to_cpu(resp->unique_id); | |
248 | IWL_DEBUG_TE(mvm, "Got response - UID = 0x%x\n", te_data->uid); | |
249 | return false; | |
250 | ||
251 | case TIME_EVENT_NOTIFICATION: | |
252 | notif = (void *)pkt->data; | |
253 | WARN_ON(le32_to_cpu(notif->status) != 1); | |
254 | WARN_ON(mac_id_n_color != le32_to_cpu(notif->id_and_color)); | |
255 | /* check if this is our Time Event that is starting */ | |
256 | if (le32_to_cpu(notif->unique_id) != te_data->uid) | |
257 | return false; | |
258 | IWL_DEBUG_TE(mvm, "Event %d is starting - time is %d\n", | |
259 | te_data->uid, le32_to_cpu(notif->timestamp)); | |
260 | ||
261 | WARN_ONCE(!le32_to_cpu(notif->status), | |
262 | "Failed to schedule protected session TE\n"); | |
263 | ||
264 | te_data->running = true; | |
265 | te_data->end_jiffies = jiffies + | |
266 | TU_TO_JIFFIES(te_data->duration); | |
267 | return true; | |
268 | ||
269 | default: | |
270 | WARN_ON(1); | |
271 | return false; | |
272 | }; | |
273 | } | |
274 | ||
275 | void iwl_mvm_protect_session(struct iwl_mvm *mvm, | |
276 | struct ieee80211_vif *vif, | |
277 | u32 duration, u32 min_duration) | |
278 | { | |
279 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
280 | struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data; | |
281 | static const u8 time_event_notif[] = { TIME_EVENT_CMD, | |
282 | TIME_EVENT_NOTIFICATION }; | |
283 | struct iwl_notification_wait wait_time_event; | |
284 | struct iwl_time_event_cmd time_cmd = {}; | |
285 | int ret; | |
286 | ||
287 | lockdep_assert_held(&mvm->mutex); | |
288 | ||
289 | if (te_data->running && | |
290 | time_after(te_data->end_jiffies, | |
291 | jiffies + TU_TO_JIFFIES(min_duration))) { | |
292 | IWL_DEBUG_TE(mvm, "We have enough time in the current TE: %u\n", | |
293 | jiffies_to_msecs(te_data->end_jiffies - jiffies)); | |
294 | return; | |
295 | } | |
296 | ||
297 | if (te_data->running) { | |
298 | IWL_DEBUG_TE(mvm, "extend 0x%x: only %u ms left\n", | |
299 | te_data->uid, | |
300 | jiffies_to_msecs(te_data->end_jiffies - jiffies)); | |
301 | /* | |
302 | * we don't have enough time | |
303 | * cancel the current TE and issue a new one | |
304 | * Of course it would be better to remove the old one only | |
305 | * when the new one is added, but we don't care if we are off | |
306 | * channel for a bit. All we need to do, is not to return | |
307 | * before we actually begin to be on the channel. | |
308 | */ | |
309 | iwl_mvm_stop_session_protection(mvm, vif); | |
310 | } | |
311 | ||
312 | iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, | |
313 | time_event_notif, | |
314 | ARRAY_SIZE(time_event_notif), | |
315 | iwl_mvm_time_event_notif, | |
316 | &mvmvif->time_event_data); | |
317 | ||
318 | time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD); | |
319 | time_cmd.id_and_color = | |
320 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)); | |
321 | time_cmd.id = cpu_to_le32(TE_BSS_STA_AGGRESSIVE_ASSOC); | |
322 | ||
323 | time_cmd.apply_time = | |
324 | cpu_to_le32(iwl_read_prph(mvm->trans, DEVICE_SYSTEM_TIME_REG)); | |
325 | time_cmd.dep_policy = TE_INDEPENDENT; | |
326 | time_cmd.is_present = cpu_to_le32(1); | |
327 | time_cmd.max_frags = cpu_to_le32(TE_FRAG_NONE); | |
328 | time_cmd.max_delay = cpu_to_le32(500); | |
329 | /* TODO: why do we need to interval = bi if it is not periodic? */ | |
330 | time_cmd.interval = cpu_to_le32(1); | |
331 | time_cmd.interval_reciprocal = cpu_to_le32(iwl_mvm_reciprocal(1)); | |
332 | time_cmd.duration = cpu_to_le32(duration); | |
333 | time_cmd.repeat = cpu_to_le32(1); | |
334 | time_cmd.notify = cpu_to_le32(TE_NOTIF_HOST_START | TE_NOTIF_HOST_END); | |
335 | ||
336 | te_data->vif = vif; | |
337 | te_data->duration = duration; | |
338 | ||
339 | spin_lock_bh(&mvm->time_event_lock); | |
340 | te_data->id = le32_to_cpu(time_cmd.id); | |
341 | list_add_tail(&te_data->list, &mvm->time_event_list); | |
342 | spin_unlock_bh(&mvm->time_event_lock); | |
343 | ||
344 | ret = iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC, | |
345 | sizeof(time_cmd), &time_cmd); | |
346 | if (ret) { | |
347 | IWL_ERR(mvm, "Couldn't send TIME_EVENT_CMD: %d\n", ret); | |
348 | goto out_remove_notif; | |
349 | } | |
350 | ||
351 | ret = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1 * HZ); | |
352 | if (ret) { | |
353 | IWL_ERR(mvm, "%s - failed on timeout\n", __func__); | |
354 | spin_lock_bh(&mvm->time_event_lock); | |
355 | iwl_mvm_te_clear_data(mvm, te_data); | |
356 | spin_unlock_bh(&mvm->time_event_lock); | |
357 | } | |
358 | ||
359 | return; | |
360 | ||
361 | out_remove_notif: | |
362 | iwl_remove_notification(&mvm->notif_wait, &wait_time_event); | |
363 | } | |
364 | ||
365 | /* | |
366 | * Explicit request to remove a time event. The removal of a time event needs to | |
367 | * be synchronized with the flow of a time event's end notification, which also | |
368 | * removes the time event from the op mode data structures. | |
369 | */ | |
370 | void iwl_mvm_remove_time_event(struct iwl_mvm *mvm, | |
371 | struct iwl_mvm_vif *mvmvif, | |
372 | struct iwl_mvm_time_event_data *te_data) | |
373 | { | |
374 | struct iwl_time_event_cmd time_cmd = {}; | |
375 | u32 id, uid; | |
376 | int ret; | |
377 | ||
378 | /* | |
379 | * It is possible that by the time we got to this point the time | |
380 | * event was already removed. | |
381 | */ | |
382 | spin_lock_bh(&mvm->time_event_lock); | |
383 | ||
384 | /* Save time event uid before clearing its data */ | |
385 | uid = te_data->uid; | |
386 | id = te_data->id; | |
387 | ||
388 | /* | |
389 | * The clear_data function handles time events that were already removed | |
390 | */ | |
391 | iwl_mvm_te_clear_data(mvm, te_data); | |
392 | spin_unlock_bh(&mvm->time_event_lock); | |
393 | ||
394 | /* | |
395 | * It is possible that by the time we try to remove it, the time event | |
396 | * has already ended and removed. In such a case there is no need to | |
397 | * send a removal command. | |
398 | */ | |
399 | if (id == TE_MAX) { | |
400 | IWL_DEBUG_TE(mvm, "TE 0x%x has already ended\n", uid); | |
401 | return; | |
402 | } | |
403 | ||
404 | /* When we remove a TE, the UID is to be set in the id field */ | |
405 | time_cmd.id = cpu_to_le32(uid); | |
406 | time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_REMOVE); | |
407 | time_cmd.id_and_color = | |
408 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)); | |
409 | ||
410 | IWL_DEBUG_TE(mvm, "Removing TE 0x%x\n", le32_to_cpu(time_cmd.id)); | |
411 | ret = iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_ASYNC, | |
412 | sizeof(time_cmd), &time_cmd); | |
413 | if (WARN_ON(ret)) | |
414 | return; | |
415 | } | |
416 | ||
417 | void iwl_mvm_stop_session_protection(struct iwl_mvm *mvm, | |
418 | struct ieee80211_vif *vif) | |
419 | { | |
420 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
421 | struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data; | |
422 | ||
423 | lockdep_assert_held(&mvm->mutex); | |
424 | iwl_mvm_remove_time_event(mvm, mvmvif, te_data); | |
425 | } | |
426 | ||
427 | static bool iwl_mvm_roc_te_notif(struct iwl_notif_wait_data *notif_wait, | |
428 | struct iwl_rx_packet *pkt, void *data) | |
429 | { | |
430 | struct iwl_mvm *mvm = | |
431 | container_of(notif_wait, struct iwl_mvm, notif_wait); | |
432 | struct iwl_mvm_time_event_data *te_data = data; | |
433 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(te_data->vif); | |
434 | struct iwl_time_event_resp *resp; | |
435 | ||
436 | u32 mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color); | |
437 | ||
438 | /* until we do something else */ | |
439 | WARN_ON(te_data->id != TE_P2P_DEVICE_DISCOVERABLE); | |
440 | ||
441 | switch (pkt->hdr.cmd) { | |
442 | case TIME_EVENT_CMD: | |
443 | resp = (void *)pkt->data; | |
444 | WARN_ON(mac_id_n_color != le32_to_cpu(resp->id_and_color)); | |
445 | te_data->uid = le32_to_cpu(resp->unique_id); | |
446 | IWL_DEBUG_TE(mvm, "Got response - UID = 0x%x\n", te_data->uid); | |
447 | return true; | |
448 | ||
449 | default: | |
450 | WARN_ON(1); | |
451 | return false; | |
452 | }; | |
453 | } | |
454 | ||
455 | int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
456 | int duration) | |
457 | { | |
458 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
459 | struct iwl_mvm_time_event_data *te_data = &mvmvif->time_event_data; | |
460 | static const u8 roc_te_notif[] = { TIME_EVENT_CMD }; | |
461 | struct iwl_notification_wait wait_time_event; | |
462 | struct iwl_time_event_cmd time_cmd = {}; | |
463 | int ret; | |
464 | ||
465 | lockdep_assert_held(&mvm->mutex); | |
466 | if (te_data->running) { | |
467 | IWL_WARN(mvm, "P2P_DEVICE remain on channel already running\n"); | |
468 | return -EBUSY; | |
469 | } | |
470 | ||
471 | /* | |
472 | * Flush the done work, just in case it's still pending, so that | |
473 | * the work it does can complete and we can accept new frames. | |
474 | */ | |
475 | flush_work(&mvm->roc_done_wk); | |
476 | ||
477 | iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event, | |
478 | roc_te_notif, | |
479 | ARRAY_SIZE(roc_te_notif), | |
480 | iwl_mvm_roc_te_notif, | |
481 | &mvmvif->time_event_data); | |
482 | ||
483 | time_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD); | |
484 | time_cmd.id_and_color = | |
485 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)); | |
486 | time_cmd.id = cpu_to_le32(TE_P2P_DEVICE_DISCOVERABLE); | |
487 | ||
488 | time_cmd.apply_time = cpu_to_le32(0); | |
489 | time_cmd.dep_policy = cpu_to_le32(TE_INDEPENDENT); | |
490 | time_cmd.is_present = cpu_to_le32(1); | |
491 | ||
492 | time_cmd.interval = cpu_to_le32(1); | |
493 | ||
494 | /* | |
495 | * TE_P2P_DEVICE_DISCOVERABLE can have lower priority than other events | |
496 | * that are being scheduled by the driver/fw, and thus it might not be | |
497 | * scheduled. To improve the chances of it being scheduled, allow it to | |
498 | * be fragmented. | |
499 | * In addition, for the same reasons, allow to delay the scheduling of | |
500 | * the time event. | |
501 | */ | |
502 | time_cmd.max_frags = cpu_to_le32(MSEC_TO_TU(duration)/20); | |
503 | time_cmd.max_delay = cpu_to_le32(MSEC_TO_TU(duration/2)); | |
504 | time_cmd.duration = cpu_to_le32(MSEC_TO_TU(duration)); | |
505 | time_cmd.repeat = cpu_to_le32(1); | |
506 | time_cmd.notify = cpu_to_le32(TE_NOTIF_HOST_START | TE_NOTIF_HOST_END); | |
507 | ||
508 | /* Push the te data to the tracked te list */ | |
509 | te_data->vif = vif; | |
510 | te_data->duration = MSEC_TO_TU(duration); | |
511 | ||
512 | spin_lock_bh(&mvm->time_event_lock); | |
513 | te_data->id = le32_to_cpu(time_cmd.id); | |
514 | list_add_tail(&te_data->list, &mvm->time_event_list); | |
515 | spin_unlock_bh(&mvm->time_event_lock); | |
516 | ||
517 | ret = iwl_mvm_send_cmd_pdu(mvm, TIME_EVENT_CMD, CMD_SYNC, | |
518 | sizeof(time_cmd), &time_cmd); | |
519 | if (ret) { | |
520 | IWL_ERR(mvm, "Couldn't send TIME_EVENT_CMD: %d\n", ret); | |
521 | goto out_remove_notif; | |
522 | } | |
523 | ||
524 | ret = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1 * HZ); | |
525 | if (ret) { | |
526 | IWL_ERR(mvm, "%s - failed on timeout\n", __func__); | |
527 | iwl_mvm_te_clear_data(mvm, te_data); | |
528 | } | |
529 | ||
530 | return ret; | |
531 | ||
532 | out_remove_notif: | |
533 | iwl_remove_notification(&mvm->notif_wait, &wait_time_event); | |
534 | return ret; | |
535 | } | |
536 | ||
537 | void iwl_mvm_stop_p2p_roc(struct iwl_mvm *mvm) | |
538 | { | |
539 | struct iwl_mvm_vif *mvmvif; | |
540 | struct iwl_mvm_time_event_data *te_data; | |
541 | ||
542 | lockdep_assert_held(&mvm->mutex); | |
543 | ||
544 | /* | |
545 | * Iterate over the list of time events and find the time event that is | |
546 | * associated with a P2P_DEVICE interface. | |
547 | * This assumes that a P2P_DEVICE interface can have only a single time | |
548 | * event at any given time and this time event coresponds to a ROC | |
549 | * request | |
550 | */ | |
551 | mvmvif = NULL; | |
552 | spin_lock_bh(&mvm->time_event_lock); | |
553 | list_for_each_entry(te_data, &mvm->time_event_list, list) { | |
554 | if (te_data->vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
555 | mvmvif = iwl_mvm_vif_from_mac80211(te_data->vif); | |
556 | break; | |
557 | } | |
558 | } | |
559 | spin_unlock_bh(&mvm->time_event_lock); | |
560 | ||
561 | if (!mvmvif) { | |
562 | IWL_WARN(mvm, "P2P_DEVICE no remain on channel event\n"); | |
563 | return; | |
564 | } | |
565 | ||
566 | iwl_mvm_remove_time_event(mvm, mvmvif, te_data); | |
567 | ||
568 | iwl_mvm_roc_finished(mvm); | |
569 | } |