1*8e99ea8dSJohannes Berg /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2*8e99ea8dSJohannes Berg /*
3*8e99ea8dSJohannes Berg * Copyright (C) 2012-2014, 2019-2020 Intel Corporation
4*8e99ea8dSJohannes Berg * Copyright (C) 2013-2014 Intel Mobile Communications GmbH
5*8e99ea8dSJohannes 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 /**
104e705c121SKalle Valo * iwl_mvm_start_p2p_roc - start remain on channel for p2p device functionality
105e705c121SKalle Valo * @mvm: the mvm component
106e705c121SKalle Valo * @vif: the virtual interface for which the roc is requested. It is assumed
107e705c121SKalle Valo * that the vif type is NL80211_IFTYPE_P2P_DEVICE
108e705c121SKalle Valo * @duration: the requested duration in millisecond for the fw to be on the
109e705c121SKalle Valo * channel that is bound to the vif.
110e705c121SKalle Valo * @type: the remain on channel request type
111e705c121SKalle Valo *
112e705c121SKalle Valo * This function can be used to issue a remain on channel session,
113e705c121SKalle Valo * which means that the fw will stay in the channel for the request %duration
114e705c121SKalle Valo * milliseconds. The function is async, meaning that it only issues the ROC
115e705c121SKalle Valo * request but does not wait for it to start. Once the FW is ready to serve the
116e705c121SKalle Valo * ROC request, it will issue a notification to the driver that it is on the
117e705c121SKalle Valo * requested channel. Once the FW completes the ROC request it will issue
118e705c121SKalle Valo * another notification to the driver.
119e705c121SKalle Valo */
120e705c121SKalle Valo int iwl_mvm_start_p2p_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
121e705c121SKalle Valo int duration, enum ieee80211_roc_type type);
122e705c121SKalle Valo
123e705c121SKalle Valo /**
124e705c121SKalle Valo * iwl_mvm_stop_roc - stop remain on channel functionality
125e705c121SKalle Valo * @mvm: the mvm component
126fe959c7bSEmmanuel Grumbach * @vif: the virtual interface for which the roc is stopped
127e705c121SKalle Valo *
128e705c121SKalle Valo * This function can be used to cancel an ongoing ROC session.
129e705c121SKalle Valo * The function is async, it will instruct the FW to stop serving the ROC
130e705c121SKalle Valo * session, but will not wait for the actual stopping of the session.
131e705c121SKalle Valo */
132fe959c7bSEmmanuel Grumbach void iwl_mvm_stop_roc(struct iwl_mvm *mvm, struct ieee80211_vif *vif);
133e705c121SKalle Valo
134e705c121SKalle Valo /**
135e705c121SKalle Valo * iwl_mvm_remove_time_event - general function to clean up of time event
136e705c121SKalle Valo * @mvm: the mvm component
137e705c121SKalle Valo * @vif: the vif to which the time event belongs
138e705c121SKalle Valo * @te_data: the time event data that corresponds to that time event
139e705c121SKalle Valo *
140e705c121SKalle Valo * This function can be used to cancel a time event regardless its type.
141e705c121SKalle Valo * It is useful for cleaning up time events running before removing an
142e705c121SKalle Valo * interface.
143e705c121SKalle Valo */
144e705c121SKalle Valo void iwl_mvm_remove_time_event(struct iwl_mvm *mvm,
145e705c121SKalle Valo struct iwl_mvm_vif *mvmvif,
146e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data);
147e705c121SKalle Valo
148e705c121SKalle Valo /**
149e705c121SKalle Valo * iwl_mvm_te_clear_data - remove time event from list
150e705c121SKalle Valo * @mvm: the mvm component
151e705c121SKalle Valo * @te_data: the time event data to remove
152e705c121SKalle Valo *
153e705c121SKalle Valo * This function is mostly internal, it is made available here only
154e705c121SKalle Valo * for firmware restart purposes.
155e705c121SKalle Valo */
156e705c121SKalle Valo void iwl_mvm_te_clear_data(struct iwl_mvm *mvm,
157e705c121SKalle Valo struct iwl_mvm_time_event_data *te_data);
158e705c121SKalle Valo
159305d236eSEliad Peller void iwl_mvm_cleanup_roc_te(struct iwl_mvm *mvm);
160e705c121SKalle Valo void iwl_mvm_roc_done_wk(struct work_struct *wk);
161e705c121SKalle Valo
16258ddd9b6SEmmanuel Grumbach void iwl_mvm_remove_csa_period(struct iwl_mvm *mvm,
16358ddd9b6SEmmanuel Grumbach struct ieee80211_vif *vif);
16458ddd9b6SEmmanuel Grumbach
165e705c121SKalle Valo /**
166e705c121SKalle Valo * iwl_mvm_schedule_csa_period - request channel switch absence period
167e705c121SKalle Valo * @mvm: the mvm component
168e705c121SKalle Valo * @vif: the virtual interface for which the channel switch is issued
169e705c121SKalle Valo * @duration: the duration of the NoA in TU.
170e705c121SKalle Valo * @apply_time: NoA start time in GP2.
171e705c121SKalle Valo *
172e705c121SKalle Valo * This function is used to schedule NoA time event and is used to perform
173e705c121SKalle Valo * the channel switch flow.
174e705c121SKalle Valo */
175e705c121SKalle Valo int iwl_mvm_schedule_csa_period(struct iwl_mvm *mvm,
176e705c121SKalle Valo struct ieee80211_vif *vif,
177e705c121SKalle Valo u32 duration, u32 apply_time);
178e705c121SKalle Valo
179e705c121SKalle Valo /**
180e705c121SKalle Valo * iwl_mvm_te_scheduled - check if the fw received the TE cmd
181e705c121SKalle Valo * @te_data: the time event data that corresponds to that time event
182e705c121SKalle Valo *
183e705c121SKalle Valo * This function returns true iff this TE is added to the fw.
184e705c121SKalle Valo */
185e705c121SKalle Valo static inline bool
iwl_mvm_te_scheduled(struct iwl_mvm_time_event_data * te_data)186e705c121SKalle Valo iwl_mvm_te_scheduled(struct iwl_mvm_time_event_data *te_data)
187e705c121SKalle Valo {
188e705c121SKalle Valo if (!te_data)
189e705c121SKalle Valo return false;
190e705c121SKalle Valo
191e705c121SKalle Valo return !!te_data->uid;
192e705c121SKalle Valo }
193e705c121SKalle Valo
194fe959c7bSEmmanuel Grumbach /**
195fe959c7bSEmmanuel Grumbach * iwl_mvm_schedule_session_protection - schedule a session protection
196fe959c7bSEmmanuel Grumbach * @mvm: the mvm component
197fe959c7bSEmmanuel Grumbach * @vif: the virtual interface for which the protection issued
198fe959c7bSEmmanuel Grumbach * @duration: the duration of the protection
199b5b878e3SEmmanuel Grumbach * @wait_for_notif: if true, will block until the start of the protection
200fe959c7bSEmmanuel Grumbach */
201fe959c7bSEmmanuel Grumbach void iwl_mvm_schedule_session_protection(struct iwl_mvm *mvm,
202fe959c7bSEmmanuel Grumbach struct ieee80211_vif *vif,
203b5b878e3SEmmanuel Grumbach u32 duration, u32 min_duration,
204b5b878e3SEmmanuel Grumbach bool wait_for_notif);
205fe959c7bSEmmanuel Grumbach
206fe959c7bSEmmanuel Grumbach /**
207fe959c7bSEmmanuel Grumbach * iwl_mvm_rx_session_protect_notif - handles %SESSION_PROTECTION_NOTIF
208fe959c7bSEmmanuel Grumbach */
209fe959c7bSEmmanuel Grumbach void iwl_mvm_rx_session_protect_notif(struct iwl_mvm *mvm,
210fe959c7bSEmmanuel Grumbach struct iwl_rx_cmd_buffer *rxb);
211fe959c7bSEmmanuel Grumbach
212e705c121SKalle Valo #endif /* __time_event_h__ */
213