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 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
10 * Copyright (C) 2019 - 2020 Intel Corporation
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * General Public License for more details.
20 *
21 * The full GNU General Public License is included in this distribution
22 * in the file called COPYING.
23 *
24 * Contact Information:
25 *  Intel Linux Wireless <linuxwifi@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 * BSD LICENSE
29 *
30 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
31 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
32 * Copyright (C) 2019 - 2020 Intel Corporation
33 * All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 *
39 *  * Redistributions of source code must retain the above copyright
40 *    notice, this list of conditions and the following disclaimer.
41 *  * Redistributions in binary form must reproduce the above copyright
42 *    notice, this list of conditions and the following disclaimer in
43 *    the documentation and/or other materials provided with the
44 *    distribution.
45 *  * Neither the name Intel Corporation nor the names of its
46 *    contributors may be used to endorse or promote products derived
47 *    from this software without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 *
61 *****************************************************************************/
62
63#ifndef __time_event_h__
64#define __time_event_h__
65
66#include "fw-api.h"
67
68#include "mvm.h"
69
70/**
71 * DOC: Time Events - what is it?
72 *
73 * Time Events are a fw feature that allows the driver to control the presence
74 * of the device on the channel. Since the fw supports multiple channels
75 * concurrently, the fw may choose to jump to another channel at any time.
76 * In order to make sure that the fw is on a specific channel at a certain time
77 * and for a certain duration, the driver needs to issue a time event.
78 *
79 * The simplest example is for BSS association. The driver issues a time event,
80 * waits for it to start, and only then tells mac80211 that we can start the
81 * association. This way, we make sure that the association will be done
82 * smoothly and won't be interrupted by channel switch decided within the fw.
83 */
84
85 /**
86 * DOC: The flow against the fw
87 *
88 * When the driver needs to make sure we are in a certain channel, at a certain
89 * time and for a certain duration, it sends a Time Event. The flow against the
90 * fw goes like this:
91 *	1) Driver sends a TIME_EVENT_CMD to the fw
92 *	2) Driver gets the response for that command. This response contains the
93 *	   Unique ID (UID) of the event.
94 *	3) The fw sends notification when the event starts.
95 *
96 * Of course the API provides various options that allow to cover parameters
97 * of the flow.
98 *	What is the duration of the event?
99 *	What is the start time of the event?
100 *	Is there an end-time for the event?
101 *	How much can the event be delayed?
102 *	Can the event be split?
103 *	If yes what is the maximal number of chunks?
104 *	etc...
105 */
106
107/**
108 * DOC: Abstraction to the driver
109 *
110 * In order to simplify the use of time events to the rest of the driver,
111 * we abstract the use of time events. This component provides the functions
112 * needed by the driver.
113 */
114
115#define IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS 600
116#define IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS 400
117
118/**
119 * iwl_mvm_protect_session - start / extend the session protection.
120 * @mvm: the mvm component
121 * @vif: the virtual interface for which the session is issued
122 * @duration: the duration of the session in TU.
123 * @min_duration: will start a new session if the current session will end
124 *	in less than min_duration.
125 * @max_delay: maximum delay before starting the time event (in TU)
126 * @wait_for_notif: true if it is required that a time event notification be
127 *	waited for (that the time event has been scheduled before returning)
128 *
129 * This function can be used to start a session protection which means that the
130 * fw will stay on the channel for %duration_ms milliseconds. This function
131 * can block (sleep) until the session starts. This function can also be used
132 * to extend a currently running session.
133 * This function is meant to be used for BSS association for example, where we
134 * want to make sure that the fw stays on the channel during the association.
135 */
136void iwl_mvm_protect_session(struct iwl_mvm *mvm,
137			     struct ieee80211_vif *vif,
138			     u32 duration, u32 min_duration,
139			     u32 max_delay, bool wait_for_notif);
140
141/**
142 * iwl_mvm_stop_session_protection - cancel the session protection.
143 * @mvm: the mvm component
144 * @vif: the virtual interface for which the session is issued
145 *
146 * This functions cancels the session protection which is an act of good
147 * citizenship. If it is not needed any more it should be canceled because
148 * the other bindings wait for the medium during that time.
149 * This funtions doesn't sleep.
150 */
151void iwl_mvm_stop_session_protection(struct iwl_mvm *mvm,
152				      struct ieee80211_vif *vif);
153
154/*
155 * iwl_mvm_rx_time_event_notif - handles %TIME_EVENT_NOTIFICATION.
156 */
157void iwl_mvm_rx_time_event_notif(struct iwl_mvm *mvm,
158				 struct iwl_rx_cmd_buffer *rxb);
159
160/**
161 * iwl_mvm_start_p2p_roc - start remain on channel for p2p device functionality
162 * @mvm: the mvm component
163 * @vif: the virtual interface for which the roc is requested. It is assumed
164 * that the vif type is NL80211_IFTYPE_P2P_DEVICE
165 * @duration: the requested duration in millisecond for the fw to be on the
166 * channel that is bound to the vif.
167 * @type: the remain on channel request type
168 *
169 * This function can be used to issue a remain on channel session,
170 * which means that the fw will stay in the channel for the request %duration
171 * milliseconds. The function is async, meaning that it only issues the ROC
172 * request but does not wait for it to start. Once the FW is ready to serve the
173 * ROC request, it will issue a notification to the driver that it is on the
174 * requested channel. Once the FW completes the ROC request it will issue
175 * another notification to the driver.
176 */
177int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
178			  int duration, enum ieee80211_roc_type type);
179
180/**
181 * iwl_mvm_stop_roc - stop remain on channel functionality
182 * @mvm: the mvm component
183 * @vif: the virtual interface for which the roc is stopped
184 *
185 * This function can be used to cancel an ongoing ROC session.
186 * The function is async, it will instruct the FW to stop serving the ROC
187 * session, but will not wait for the actual stopping of the session.
188 */
189void iwl_mvm_stop_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
190
191/**
192 * iwl_mvm_remove_time_event - general function to clean up of time event
193 * @mvm: the mvm component
194 * @vif: the vif to which the time event belongs
195 * @te_data: the time event data that corresponds to that time event
196 *
197 * This function can be used to cancel a time event regardless its type.
198 * It is useful for cleaning up time events running before removing an
199 * interface.
200 */
201void iwl_mvm_remove_time_event(struct iwl_mvm *mvm,
202			       struct iwl_mvm_vif *mvmvif,
203			       struct iwl_mvm_time_event_data *te_data);
204
205/**
206 * iwl_mvm_te_clear_data - remove time event from list
207 * @mvm: the mvm component
208 * @te_data: the time event data to remove
209 *
210 * This function is mostly internal, it is made available here only
211 * for firmware restart purposes.
212 */
213void iwl_mvm_te_clear_data(struct iwl_mvm *mvm,
214			   struct iwl_mvm_time_event_data *te_data);
215
216void iwl_mvm_cleanup_roc_te(struct iwl_mvm *mvm);
217void iwl_mvm_roc_done_wk(struct work_struct *wk);
218
219void iwl_mvm_remove_csa_period(struct iwl_mvm *mvm,
220			       struct ieee80211_vif *vif);
221
222/**
223 * iwl_mvm_schedule_csa_period - request channel switch absence period
224 * @mvm: the mvm component
225 * @vif: the virtual interface for which the channel switch is issued
226 * @duration: the duration of the NoA in TU.
227 * @apply_time: NoA start time in GP2.
228 *
229 * This function is used to schedule NoA time event and is used to perform
230 * the channel switch flow.
231 */
232int iwl_mvm_schedule_csa_period(struct iwl_mvm *mvm,
233				struct ieee80211_vif *vif,
234				u32 duration, u32 apply_time);
235
236/**
237 * iwl_mvm_te_scheduled - check if the fw received the TE cmd
238 * @te_data: the time event data that corresponds to that time event
239 *
240 * This function returns true iff this TE is added to the fw.
241 */
242static inline bool
243iwl_mvm_te_scheduled(struct iwl_mvm_time_event_data *te_data)
244{
245	if (!te_data)
246		return false;
247
248	return !!te_data->uid;
249}
250
251/**
252 * iwl_mvm_schedule_session_protection - schedule a session protection
253 * @mvm: the mvm component
254 * @vif: the virtual interface for which the protection issued
255 * @duration: the duration of the protection
256 * @wait_for_notif: if true, will block until the start of the protection
257 */
258void iwl_mvm_schedule_session_protection(struct iwl_mvm *mvm,
259					 struct ieee80211_vif *vif,
260					 u32 duration, u32 min_duration,
261					 bool wait_for_notif);
262
263/**
264 * iwl_mvm_rx_session_protect_notif - handles %SESSION_PROTECTION_NOTIF
265 */
266void iwl_mvm_rx_session_protect_notif(struct iwl_mvm *mvm,
267				      struct iwl_rx_cmd_buffer *rxb);
268
269#endif /* __time_event_h__ */
270