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