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