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 - 2015 Intel Mobile Communications GmbH
10  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of version 2 of the GNU General Public License as
14  * published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * General Public License for more details.
20  *
21  * The full GNU General Public License is included in this distribution
22  * in the file called COPYING.
23  *
24  * Contact Information:
25  *  Intel Linux Wireless <linuxwifi@intel.com>
26  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27  *
28  * BSD LICENSE
29  *
30  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
31  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
32  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
33  * All rights reserved.
34  *
35  * Redistribution and use in source and binary forms, with or without
36  * modification, are permitted provided that the following conditions
37  * are met:
38  *
39  *  * Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  *  * Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in
43  *    the documentation and/or other materials provided with the
44  *    distribution.
45  *  * Neither the name Intel Corporation nor the names of its
46  *    contributors may be used to endorse or promote products derived
47  *    from this software without specific prior written permission.
48  *
49  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60  *
61  *****************************************************************************/
62 
63 #ifndef __iwl_fw_api_time_event_h__
64 #define __iwl_fw_api_time_event_h__
65 
66 #include "fw/api/phy-ctxt.h"
67 
68 /* Time Event types, according to MAC type */
69 enum iwl_time_event_type {
70 	/* BSS Station Events */
71 	TE_BSS_STA_AGGRESSIVE_ASSOC,
72 	TE_BSS_STA_ASSOC,
73 	TE_BSS_EAP_DHCP_PROT,
74 	TE_BSS_QUIET_PERIOD,
75 
76 	/* P2P Device Events */
77 	TE_P2P_DEVICE_DISCOVERABLE,
78 	TE_P2P_DEVICE_LISTEN,
79 	TE_P2P_DEVICE_ACTION_SCAN,
80 	TE_P2P_DEVICE_FULL_SCAN,
81 
82 	/* P2P Client Events */
83 	TE_P2P_CLIENT_AGGRESSIVE_ASSOC,
84 	TE_P2P_CLIENT_ASSOC,
85 	TE_P2P_CLIENT_QUIET_PERIOD,
86 
87 	/* P2P GO Events */
88 	TE_P2P_GO_ASSOC_PROT,
89 	TE_P2P_GO_REPETITIVET_NOA,
90 	TE_P2P_GO_CT_WINDOW,
91 
92 	/* WiDi Sync Events */
93 	TE_WIDI_TX_SYNC,
94 
95 	/* Channel Switch NoA */
96 	TE_CHANNEL_SWITCH_PERIOD,
97 
98 	TE_MAX
99 }; /* MAC_EVENT_TYPE_API_E_VER_1 */
100 
101 /* Time event - defines for command API v1 */
102 
103 /*
104  * @TE_V1_FRAG_NONE: fragmentation of the time event is NOT allowed.
105  * @TE_V1_FRAG_SINGLE: fragmentation of the time event is allowed, but only
106  *	the first fragment is scheduled.
107  * @TE_V1_FRAG_DUAL: fragmentation of the time event is allowed, but only
108  *	the first 2 fragments are scheduled.
109  * @TE_V1_FRAG_ENDLESS: fragmentation of the time event is allowed, and any
110  *	number of fragments are valid.
111  *
112  * Other than the constant defined above, specifying a fragmentation value 'x'
113  * means that the event can be fragmented but only the first 'x' will be
114  * scheduled.
115  */
116 enum {
117 	TE_V1_FRAG_NONE = 0,
118 	TE_V1_FRAG_SINGLE = 1,
119 	TE_V1_FRAG_DUAL = 2,
120 	TE_V1_FRAG_ENDLESS = 0xffffffff
121 };
122 
123 /* If a Time Event can be fragmented, this is the max number of fragments */
124 #define TE_V1_FRAG_MAX_MSK	0x0fffffff
125 /* Repeat the time event endlessly (until removed) */
126 #define TE_V1_REPEAT_ENDLESS	0xffffffff
127 /* If a Time Event has bounded repetitions, this is the maximal value */
128 #define TE_V1_REPEAT_MAX_MSK_V1	0x0fffffff
129 
130 /* Time Event dependencies: none, on another TE, or in a specific time */
131 enum {
132 	TE_V1_INDEPENDENT		= 0,
133 	TE_V1_DEP_OTHER			= BIT(0),
134 	TE_V1_DEP_TSF			= BIT(1),
135 	TE_V1_EVENT_SOCIOPATHIC		= BIT(2),
136 }; /* MAC_EVENT_DEPENDENCY_POLICY_API_E_VER_2 */
137 
138 /*
139  * @TE_V1_NOTIF_NONE: no notifications
140  * @TE_V1_NOTIF_HOST_EVENT_START: request/receive notification on event start
141  * @TE_V1_NOTIF_HOST_EVENT_END:request/receive notification on event end
142  * @TE_V1_NOTIF_INTERNAL_EVENT_START: internal FW use
143  * @TE_V1_NOTIF_INTERNAL_EVENT_END: internal FW use.
144  * @TE_V1_NOTIF_HOST_FRAG_START: request/receive notification on frag start
145  * @TE_V1_NOTIF_HOST_FRAG_END:request/receive notification on frag end
146  * @TE_V1_NOTIF_INTERNAL_FRAG_START: internal FW use.
147  * @TE_V1_NOTIF_INTERNAL_FRAG_END: internal FW use.
148  *
149  * Supported Time event notifications configuration.
150  * A notification (both event and fragment) includes a status indicating weather
151  * the FW was able to schedule the event or not. For fragment start/end
152  * notification the status is always success. There is no start/end fragment
153  * notification for monolithic events.
154  */
155 enum {
156 	TE_V1_NOTIF_NONE = 0,
157 	TE_V1_NOTIF_HOST_EVENT_START = BIT(0),
158 	TE_V1_NOTIF_HOST_EVENT_END = BIT(1),
159 	TE_V1_NOTIF_INTERNAL_EVENT_START = BIT(2),
160 	TE_V1_NOTIF_INTERNAL_EVENT_END = BIT(3),
161 	TE_V1_NOTIF_HOST_FRAG_START = BIT(4),
162 	TE_V1_NOTIF_HOST_FRAG_END = BIT(5),
163 	TE_V1_NOTIF_INTERNAL_FRAG_START = BIT(6),
164 	TE_V1_NOTIF_INTERNAL_FRAG_END = BIT(7),
165 }; /* MAC_EVENT_ACTION_API_E_VER_2 */
166 
167 /* Time event - defines for command API */
168 
169 /*
170  * @TE_V2_FRAG_NONE: fragmentation of the time event is NOT allowed.
171  * @TE_V2_FRAG_SINGLE: fragmentation of the time event is allowed, but only
172  *  the first fragment is scheduled.
173  * @TE_V2_FRAG_DUAL: fragmentation of the time event is allowed, but only
174  *  the first 2 fragments are scheduled.
175  * @TE_V2_FRAG_ENDLESS: fragmentation of the time event is allowed, and any
176  *  number of fragments are valid.
177  *
178  * Other than the constant defined above, specifying a fragmentation value 'x'
179  * means that the event can be fragmented but only the first 'x' will be
180  * scheduled.
181  */
182 enum {
183 	TE_V2_FRAG_NONE = 0,
184 	TE_V2_FRAG_SINGLE = 1,
185 	TE_V2_FRAG_DUAL = 2,
186 	TE_V2_FRAG_MAX = 0xfe,
187 	TE_V2_FRAG_ENDLESS = 0xff
188 };
189 
190 /* Repeat the time event endlessly (until removed) */
191 #define TE_V2_REPEAT_ENDLESS	0xff
192 /* If a Time Event has bounded repetitions, this is the maximal value */
193 #define TE_V2_REPEAT_MAX	0xfe
194 
195 #define TE_V2_PLACEMENT_POS	12
196 #define TE_V2_ABSENCE_POS	15
197 
198 /**
199  * enum iwl_time_event_policy - Time event policy values
200  * A notification (both event and fragment) includes a status indicating weather
201  * the FW was able to schedule the event or not. For fragment start/end
202  * notification the status is always success. There is no start/end fragment
203  * notification for monolithic events.
204  *
205  * @TE_V2_DEFAULT_POLICY: independent, social, present, unoticable
206  * @TE_V2_NOTIF_HOST_EVENT_START: request/receive notification on event start
207  * @TE_V2_NOTIF_HOST_EVENT_END:request/receive notification on event end
208  * @TE_V2_NOTIF_INTERNAL_EVENT_START: internal FW use
209  * @TE_V2_NOTIF_INTERNAL_EVENT_END: internal FW use.
210  * @TE_V2_NOTIF_HOST_FRAG_START: request/receive notification on frag start
211  * @TE_V2_NOTIF_HOST_FRAG_END:request/receive notification on frag end
212  * @TE_V2_NOTIF_INTERNAL_FRAG_START: internal FW use.
213  * @TE_V2_NOTIF_INTERNAL_FRAG_END: internal FW use.
214  * @T2_V2_START_IMMEDIATELY: start time event immediately
215  * @TE_V2_DEP_OTHER: depends on another time event
216  * @TE_V2_DEP_TSF: depends on a specific time
217  * @TE_V2_EVENT_SOCIOPATHIC: can't co-exist with other events of tha same MAC
218  * @TE_V2_ABSENCE: are we present or absent during the Time Event.
219  */
220 enum iwl_time_event_policy {
221 	TE_V2_DEFAULT_POLICY = 0x0,
222 
223 	/* notifications (event start/stop, fragment start/stop) */
224 	TE_V2_NOTIF_HOST_EVENT_START = BIT(0),
225 	TE_V2_NOTIF_HOST_EVENT_END = BIT(1),
226 	TE_V2_NOTIF_INTERNAL_EVENT_START = BIT(2),
227 	TE_V2_NOTIF_INTERNAL_EVENT_END = BIT(3),
228 
229 	TE_V2_NOTIF_HOST_FRAG_START = BIT(4),
230 	TE_V2_NOTIF_HOST_FRAG_END = BIT(5),
231 	TE_V2_NOTIF_INTERNAL_FRAG_START = BIT(6),
232 	TE_V2_NOTIF_INTERNAL_FRAG_END = BIT(7),
233 	T2_V2_START_IMMEDIATELY = BIT(11),
234 
235 	/* placement characteristics */
236 	TE_V2_DEP_OTHER = BIT(TE_V2_PLACEMENT_POS),
237 	TE_V2_DEP_TSF = BIT(TE_V2_PLACEMENT_POS + 1),
238 	TE_V2_EVENT_SOCIOPATHIC = BIT(TE_V2_PLACEMENT_POS + 2),
239 
240 	/* are we present or absent during the Time Event. */
241 	TE_V2_ABSENCE = BIT(TE_V2_ABSENCE_POS),
242 };
243 
244 /**
245  * struct iwl_time_event_cmd - configuring Time Events
246  * with struct MAC_TIME_EVENT_DATA_API_S_VER_2 (see also
247  * with version 1. determined by IWL_UCODE_TLV_FLAGS)
248  * ( TIME_EVENT_CMD = 0x29 )
249  * @id_and_color: ID and color of the relevant MAC,
250  *	&enum iwl_ctxt_id_and_color
251  * @action: action to perform, one of &enum iwl_ctxt_action
252  * @id: this field has two meanings, depending on the action:
253  *	If the action is ADD, then it means the type of event to add.
254  *	For all other actions it is the unique event ID assigned when the
255  *	event was added by the FW.
256  * @apply_time: When to start the Time Event (in GP2)
257  * @max_delay: maximum delay to event's start (apply time), in TU
258  * @depends_on: the unique ID of the event we depend on (if any)
259  * @interval: interval between repetitions, in TU
260  * @duration: duration of event in TU
261  * @repeat: how many repetitions to do, can be TE_REPEAT_ENDLESS
262  * @max_frags: maximal number of fragments the Time Event can be divided to
263  * @policy: defines whether uCode shall notify the host or other uCode modules
264  *	on event and/or fragment start and/or end
265  *	using one of TE_INDEPENDENT, TE_DEP_OTHER, TE_DEP_TSF
266  *	TE_EVENT_SOCIOPATHIC
267  *	using TE_ABSENCE and using TE_NOTIF_*,
268  *	&enum iwl_time_event_policy
269  */
270 struct iwl_time_event_cmd {
271 	/* COMMON_INDEX_HDR_API_S_VER_1 */
272 	__le32 id_and_color;
273 	__le32 action;
274 	__le32 id;
275 	/* MAC_TIME_EVENT_DATA_API_S_VER_2 */
276 	__le32 apply_time;
277 	__le32 max_delay;
278 	__le32 depends_on;
279 	__le32 interval;
280 	__le32 duration;
281 	u8 repeat;
282 	u8 max_frags;
283 	__le16 policy;
284 } __packed; /* MAC_TIME_EVENT_CMD_API_S_VER_2 */
285 
286 /**
287  * struct iwl_time_event_resp - response structure to iwl_time_event_cmd
288  * @status: bit 0 indicates success, all others specify errors
289  * @id: the Time Event type
290  * @unique_id: the unique ID assigned (in ADD) or given (others) to the TE
291  * @id_and_color: ID and color of the relevant MAC,
292  *	&enum iwl_ctxt_id_and_color
293  */
294 struct iwl_time_event_resp {
295 	__le32 status;
296 	__le32 id;
297 	__le32 unique_id;
298 	__le32 id_and_color;
299 } __packed; /* MAC_TIME_EVENT_RSP_API_S_VER_1 */
300 
301 /**
302  * struct iwl_time_event_notif - notifications of time event start/stop
303  * ( TIME_EVENT_NOTIFICATION = 0x2a )
304  * @timestamp: action timestamp in GP2
305  * @session_id: session's unique id
306  * @unique_id: unique id of the Time Event itself
307  * @id_and_color: ID and color of the relevant MAC
308  * @action: &enum iwl_time_event_policy
309  * @status: true if scheduled, false otherwise (not executed)
310  */
311 struct iwl_time_event_notif {
312 	__le32 timestamp;
313 	__le32 session_id;
314 	__le32 unique_id;
315 	__le32 id_and_color;
316 	__le32 action;
317 	__le32 status;
318 } __packed; /* MAC_TIME_EVENT_NTFY_API_S_VER_1 */
319 
320 /*
321  * Aux ROC command
322  *
323  * Command requests the firmware to create a time event for a certain duration
324  * and remain on the given channel. This is done by using the Aux framework in
325  * the FW.
326  * The command was first used for Hot Spot issues - but can be used regardless
327  * to Hot Spot.
328  *
329  * ( HOT_SPOT_CMD 0x53 )
330  *
331  * @id_and_color: ID and color of the MAC
332  * @action: action to perform, one of FW_CTXT_ACTION_*
333  * @event_unique_id: If the action FW_CTXT_ACTION_REMOVE then the
334  *	event_unique_id should be the id of the time event assigned by ucode.
335  *	Otherwise ignore the event_unique_id.
336  * @sta_id_and_color: station id and color, resumed during "Remain On Channel"
337  *	activity.
338  * @channel_info: channel info
339  * @node_addr: Our MAC Address
340  * @reserved: reserved for alignment
341  * @apply_time: GP2 value to start (should always be the current GP2 value)
342  * @apply_time_max_delay: Maximum apply time delay value in TU. Defines max
343  *	time by which start of the event is allowed to be postponed.
344  * @duration: event duration in TU To calculate event duration:
345  *	timeEventDuration = min(duration, remainingQuota)
346  */
347 struct iwl_hs20_roc_req {
348 	/* COMMON_INDEX_HDR_API_S_VER_1 hdr */
349 	__le32 id_and_color;
350 	__le32 action;
351 	__le32 event_unique_id;
352 	__le32 sta_id_and_color;
353 	struct iwl_fw_channel_info channel_info;
354 	u8 node_addr[ETH_ALEN];
355 	__le16 reserved;
356 	__le32 apply_time;
357 	__le32 apply_time_max_delay;
358 	__le32 duration;
359 } __packed; /* HOT_SPOT_CMD_API_S_VER_1 */
360 
361 /*
362  * values for AUX ROC result values
363  */
364 enum iwl_mvm_hot_spot {
365 	HOT_SPOT_RSP_STATUS_OK,
366 	HOT_SPOT_RSP_STATUS_TOO_MANY_EVENTS,
367 	HOT_SPOT_MAX_NUM_OF_SESSIONS,
368 };
369 
370 /*
371  * Aux ROC command response
372  *
373  * In response to iwl_hs20_roc_req the FW sends this command to notify the
374  * driver the uid of the timevent.
375  *
376  * ( HOT_SPOT_CMD 0x53 )
377  *
378  * @event_unique_id: Unique ID of time event assigned by ucode
379  * @status: Return status 0 is success, all the rest used for specific errors
380  */
381 struct iwl_hs20_roc_res {
382 	__le32 event_unique_id;
383 	__le32 status;
384 } __packed; /* HOT_SPOT_RSP_API_S_VER_1 */
385 
386 #endif /* __iwl_fw_api_time_event_h__ */
387