xref: /linux/drivers/net/wireless/intel/iwlwifi/mvm/time-event.h (revision 67ac248e4db0a754ee85a7e41fa363b330df00e5)
18e99ea8dSJohannes Berg /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
28e99ea8dSJohannes Berg /*
3e110bf0cSJohannes Berg  * Copyright (C) 2012-2014, 2019-2020, 2023 Intel Corporation
48e99ea8dSJohannes Berg  * Copyright (C) 2013-2014 Intel Mobile Communications GmbH
58e99ea8dSJohannes Berg  */
6e705c121SKalle Valo #ifndef __time_event_h__
7e705c121SKalle Valo #define __time_event_h__
8e705c121SKalle Valo 
9e705c121SKalle Valo #include "fw-api.h"
10e705c121SKalle Valo 
11e705c121SKalle Valo #include "mvm.h"
12e705c121SKalle Valo 
13e705c121SKalle Valo /**
14e705c121SKalle Valo  * DOC: Time Events - what is it?
15e705c121SKalle Valo  *
16e705c121SKalle Valo  * Time Events are a fw feature that allows the driver to control the presence
17e705c121SKalle Valo  * of the device on the channel. Since the fw supports multiple channels
18e705c121SKalle Valo  * concurrently, the fw may choose to jump to another channel at any time.
19e705c121SKalle Valo  * In order to make sure that the fw is on a specific channel at a certain time
20e705c121SKalle Valo  * and for a certain duration, the driver needs to issue a time event.
21e705c121SKalle Valo  *
22e705c121SKalle Valo  * The simplest example is for BSS association. The driver issues a time event,
23e705c121SKalle Valo  * waits for it to start, and only then tells mac80211 that we can start the
24e705c121SKalle Valo  * association. This way, we make sure that the association will be done
25e705c121SKalle Valo  * smoothly and won't be interrupted by channel switch decided within the fw.
26e705c121SKalle Valo  */
27e705c121SKalle Valo 
28e705c121SKalle Valo  /**
29e705c121SKalle Valo  * DOC: The flow against the fw
30e705c121SKalle Valo  *
31e705c121SKalle Valo  * When the driver needs to make sure we are in a certain channel, at a certain
32e705c121SKalle Valo  * time and for a certain duration, it sends a Time Event. The flow against the
33e705c121SKalle Valo  * fw goes like this:
34e705c121SKalle Valo  *	1) Driver sends a TIME_EVENT_CMD to the fw
35e705c121SKalle Valo  *	2) Driver gets the response for that command. This response contains the
36e705c121SKalle Valo  *	   Unique ID (UID) of the event.
37e705c121SKalle Valo  *	3) The fw sends notification when the event starts.
38e705c121SKalle Valo  *
39e705c121SKalle Valo  * Of course the API provides various options that allow to cover parameters
40e705c121SKalle Valo  * of the flow.
41e705c121SKalle Valo  *	What is the duration of the event?
42e705c121SKalle Valo  *	What is the start time of the event?
43e705c121SKalle Valo  *	Is there an end-time for the event?
44e705c121SKalle Valo  *	How much can the event be delayed?
45e705c121SKalle Valo  *	Can the event be split?
46e705c121SKalle Valo  *	If yes what is the maximal number of chunks?
47e705c121SKalle Valo  *	etc...
48e705c121SKalle Valo  */
49e705c121SKalle Valo 
50e705c121SKalle Valo /**
51e705c121SKalle Valo  * DOC: Abstraction to the driver
52e705c121SKalle Valo  *
53e705c121SKalle Valo  * In order to simplify the use of time events to the rest of the driver,
54e705c121SKalle Valo  * we abstract the use of time events. This component provides the functions
55e705c121SKalle Valo  * needed by the driver.
56e705c121SKalle Valo  */
57e705c121SKalle Valo 
587c70fee5SSara Sharon #define IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS 600
59e705c121SKalle Valo #define IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS 400
60e705c121SKalle Valo 
61e705c121SKalle Valo /**
62e705c121SKalle Valo  * iwl_mvm_protect_session - start / extend the session protection.
63e705c121SKalle Valo  * @mvm: the mvm component
64e705c121SKalle Valo  * @vif: the virtual interface for which the session is issued
65e705c121SKalle Valo  * @duration: the duration of the session in TU.
66e705c121SKalle Valo  * @min_duration: will start a new session if the current session will end
67e705c121SKalle Valo  *	in less than min_duration.
68e705c121SKalle Valo  * @max_delay: maximum delay before starting the time event (in TU)
69e705c121SKalle Valo  * @wait_for_notif: true if it is required that a time event notification be
70e705c121SKalle Valo  *	waited for (that the time event has been scheduled before returning)
71e705c121SKalle Valo  *
72e705c121SKalle Valo  * This function can be used to start a session protection which means that the
73e705c121SKalle Valo  * fw will stay on the channel for %duration_ms milliseconds. This function
74e705c121SKalle Valo  * can block (sleep) until the session starts. This function can also be used
75e705c121SKalle Valo  * to extend a currently running session.
76e705c121SKalle Valo  * This function is meant to be used for BSS association for example, where we
77e705c121SKalle Valo  * want to make sure that the fw stays on the channel during the association.
78e705c121SKalle Valo  */
79e705c121SKalle Valo void iwl_mvm_protect_session(struct iwl_mvm *mvm,
80e705c121SKalle Valo 			     struct ieee80211_vif *vif,
81e705c121SKalle Valo 			     u32 duration, u32 min_duration,
82e705c121SKalle Valo 			     u32 max_delay, bool wait_for_notif);
83e705c121SKalle Valo 
84e705c121SKalle Valo /**
85e705c121SKalle Valo  * iwl_mvm_stop_session_protection - cancel the session protection.
86e705c121SKalle Valo  * @mvm: the mvm component
87e705c121SKalle Valo  * @vif: the virtual interface for which the session is issued
88e705c121SKalle Valo  *
89e705c121SKalle Valo  * This functions cancels the session protection which is an act of good
90e705c121SKalle Valo  * citizenship. If it is not needed any more it should be canceled because
91e705c121SKalle Valo  * the other bindings wait for the medium during that time.
92e705c121SKalle Valo  * This funtions doesn't sleep.
93e705c121SKalle Valo  */
94e705c121SKalle Valo void iwl_mvm_stop_session_protection(struct iwl_mvm *mvm,
95e705c121SKalle Valo 				      struct ieee80211_vif *vif);
96e705c121SKalle Valo 
97e705c121SKalle Valo /*
98e705c121SKalle Valo  * iwl_mvm_rx_time_event_notif - handles %TIME_EVENT_NOTIFICATION.
99e705c121SKalle Valo  */
100e705c121SKalle Valo void iwl_mvm_rx_time_event_notif(struct iwl_mvm *mvm,
101e705c121SKalle Valo 				 struct iwl_rx_cmd_buffer *rxb);
102e705c121SKalle Valo 
103e705c121SKalle Valo /**
104*67ac248eSShaul Triebitz  * iwl_mvm_rx_roc_notif - handles %DISCOVERY_ROC_NTF.
105*67ac248eSShaul Triebitz  * @mvm: the mvm component
106*67ac248eSShaul Triebitz  * @rxb: RX buffer
107*67ac248eSShaul Triebitz  */
108*67ac248eSShaul Triebitz void iwl_mvm_rx_roc_notif(struct iwl_mvm *mvm,
109*67ac248eSShaul Triebitz 			  struct iwl_rx_cmd_buffer *rxb);
110*67ac248eSShaul Triebitz 
111*67ac248eSShaul Triebitz /**
112e705c121SKalle Valo  * iwl_mvm_start_p2p_roc - start remain on channel for p2p device functionality
113e705c121SKalle Valo  * @mvm: the mvm component
114e705c121SKalle Valo  * @vif: the virtual interface for which the roc is requested. It is assumed
115e705c121SKalle Valo  * that the vif type is NL80211_IFTYPE_P2P_DEVICE
116e705c121SKalle Valo  * @duration: the requested duration in millisecond for the fw to be on the
117e705c121SKalle Valo  * channel that is bound to the vif.
118e705c121SKalle Valo  * @type: the remain on channel request type
119e705c121SKalle Valo  *
120e705c121SKalle Valo  * This function can be used to issue a remain on channel session,
121e705c121SKalle Valo  * which means that the fw will stay in the channel for the request %duration
122e705c121SKalle Valo  * milliseconds. The function is async, meaning that it only issues the ROC
123e705c121SKalle Valo  * request but does not wait for it to start. Once the FW is ready to serve the
124e705c121SKalle Valo  * ROC request, it will issue a notification to the driver that it is on the
125e705c121SKalle Valo  * requested channel. Once the FW completes the ROC request it will issue
126e705c121SKalle Valo  * another notification to the driver.
127e705c121SKalle Valo  */
128e705c121SKalle Valo int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
129e705c121SKalle Valo 			  int duration, enum ieee80211_roc_type type);
130e705c121SKalle Valo 
131e705c121SKalle Valo /**
132e705c121SKalle Valo  * iwl_mvm_stop_roc - stop remain on channel functionality
133e705c121SKalle Valo  * @mvm: the mvm component
134fe959c7bSEmmanuel Grumbach  * @vif: the virtual interface for which the roc is stopped
135e705c121SKalle Valo  *
136e705c121SKalle Valo  * This function can be used to cancel an ongoing ROC session.
137e705c121SKalle Valo  * The function is async, it will instruct the FW to stop serving the ROC
138e705c121SKalle Valo  * session, but will not wait for the actual stopping of the session.
139e705c121SKalle Valo  */
140fe959c7bSEmmanuel Grumbach void iwl_mvm_stop_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
141e705c121SKalle Valo 
142e705c121SKalle Valo /**
143e705c121SKalle Valo  * iwl_mvm_remove_time_event - general function to clean up of time event
144e705c121SKalle Valo  * @mvm: the mvm component
145e110bf0cSJohannes Berg  * @mvmvif: the vif to which the time event belongs
146e705c121SKalle Valo  * @te_data: the time event data that corresponds to that time event
147e705c121SKalle Valo  *
148e705c121SKalle Valo  * This function can be used to cancel a time event regardless its type.
149e705c121SKalle Valo  * It is useful for cleaning up time events running before removing an
150e705c121SKalle Valo  * interface.
151e705c121SKalle Valo  */
152e705c121SKalle Valo void iwl_mvm_remove_time_event(struct iwl_mvm *mvm,
153e705c121SKalle Valo 			       struct iwl_mvm_vif *mvmvif,
154e705c121SKalle Valo 			       struct iwl_mvm_time_event_data *te_data);
155e705c121SKalle Valo 
156e705c121SKalle Valo /**
157e705c121SKalle Valo  * iwl_mvm_te_clear_data - remove time event from list
158e705c121SKalle Valo  * @mvm: the mvm component
159e705c121SKalle Valo  * @te_data: the time event data to remove
160e705c121SKalle Valo  *
161e705c121SKalle Valo  * This function is mostly internal, it is made available here only
162e705c121SKalle Valo  * for firmware restart purposes.
163e705c121SKalle Valo  */
164e705c121SKalle Valo void iwl_mvm_te_clear_data(struct iwl_mvm *mvm,
165e705c121SKalle Valo 			   struct iwl_mvm_time_event_data *te_data);
166e705c121SKalle Valo 
167305d236eSEliad Peller void iwl_mvm_cleanup_roc_te(struct iwl_mvm *mvm);
168e705c121SKalle Valo void iwl_mvm_roc_done_wk(struct work_struct *wk);
169e705c121SKalle Valo 
17058ddd9b6SEmmanuel Grumbach void iwl_mvm_remove_csa_period(struct iwl_mvm *mvm,
17158ddd9b6SEmmanuel Grumbach 			       struct ieee80211_vif *vif);
17258ddd9b6SEmmanuel Grumbach 
173e705c121SKalle Valo /**
174e705c121SKalle Valo  * iwl_mvm_schedule_csa_period - request channel switch absence period
175e705c121SKalle Valo  * @mvm: the mvm component
176e705c121SKalle Valo  * @vif: the virtual interface for which the channel switch is issued
177e705c121SKalle Valo  * @duration: the duration of the NoA in TU.
178e705c121SKalle Valo  * @apply_time: NoA start time in GP2.
179e705c121SKalle Valo  *
180e705c121SKalle Valo  * This function is used to schedule NoA time event and is used to perform
181e705c121SKalle Valo  * the channel switch flow.
182e705c121SKalle Valo  */
183e705c121SKalle Valo int iwl_mvm_schedule_csa_period(struct iwl_mvm *mvm,
184e705c121SKalle Valo 				struct ieee80211_vif *vif,
185e705c121SKalle Valo 				u32 duration, u32 apply_time);
186e705c121SKalle Valo 
187e705c121SKalle Valo /**
188e705c121SKalle Valo  * iwl_mvm_te_scheduled - check if the fw received the TE cmd
189e705c121SKalle Valo  * @te_data: the time event data that corresponds to that time event
190e705c121SKalle Valo  *
191e705c121SKalle Valo  * This function returns true iff this TE is added to the fw.
192e705c121SKalle Valo  */
193e705c121SKalle Valo static inline bool
194e705c121SKalle Valo iwl_mvm_te_scheduled(struct iwl_mvm_time_event_data *te_data)
195e705c121SKalle Valo {
196e705c121SKalle Valo 	if (!te_data)
197e705c121SKalle Valo 		return false;
198e705c121SKalle Valo 
199e705c121SKalle Valo 	return !!te_data->uid;
200e705c121SKalle Valo }
201e705c121SKalle Valo 
202fe959c7bSEmmanuel Grumbach /**
203fe959c7bSEmmanuel Grumbach  * iwl_mvm_schedule_session_protection - schedule a session protection
204fe959c7bSEmmanuel Grumbach  * @mvm: the mvm component
205fe959c7bSEmmanuel Grumbach  * @vif: the virtual interface for which the protection issued
206e110bf0cSJohannes Berg  * @duration: the requested duration of the protection
207e110bf0cSJohannes Berg  * @min_duration: the minimum duration of the protection
208b5b878e3SEmmanuel Grumbach  * @wait_for_notif: if true, will block until the start of the protection
209fe959c7bSEmmanuel Grumbach  */
210fe959c7bSEmmanuel Grumbach void iwl_mvm_schedule_session_protection(struct iwl_mvm *mvm,
211fe959c7bSEmmanuel Grumbach 					 struct ieee80211_vif *vif,
212b5b878e3SEmmanuel Grumbach 					 u32 duration, u32 min_duration,
213b5b878e3SEmmanuel Grumbach 					 bool wait_for_notif);
214fe959c7bSEmmanuel Grumbach 
215fe959c7bSEmmanuel Grumbach /**
216fe959c7bSEmmanuel Grumbach  * iwl_mvm_rx_session_protect_notif - handles %SESSION_PROTECTION_NOTIF
217e110bf0cSJohannes Berg  * @mvm: the mvm component
218e110bf0cSJohannes Berg  * @rxb: the RX buffer containing the notification
219fe959c7bSEmmanuel Grumbach  */
220fe959c7bSEmmanuel Grumbach void iwl_mvm_rx_session_protect_notif(struct iwl_mvm *mvm,
221fe959c7bSEmmanuel Grumbach 				      struct iwl_rx_cmd_buffer *rxb);
222fe959c7bSEmmanuel Grumbach 
223e705c121SKalle Valo #endif /* __time_event_h__ */
224