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