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) 2018 - 2019 Intel Corporation
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of version 2 of the GNU General Public License as
12  * published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * The full GNU General Public License is included in this distribution
20  * in the file called COPYING.
21  *
22  * Contact Information:
23  *  Intel Linux Wireless <linuxwifi@intel.com>
24  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25  *
26  * BSD LICENSE
27  *
28  * Copyright (C) 2018 - 2019 Intel Corporation
29  * All rights reserved.
30  *
31  * Redistribution and use in source and binary forms, with or without
32  * modification, are permitted provided that the following conditions
33  * are met:
34  *
35  *  * Redistributions of source code must retain the above copyright
36  *    notice, this list of conditions and the following disclaimer.
37  *  * Redistributions in binary form must reproduce the above copyright
38  *    notice, this list of conditions and the following disclaimer in
39  *    the documentation and/or other materials provided with the
40  *    distribution.
41  *  * Neither the name Intel Corporation nor the names of its
42  *    contributors may be used to endorse or promote products derived
43  *    from this software without specific prior written permission.
44  *
45  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
47  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
48  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
49  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56  *
57  *****************************************************************************/
58 #ifndef __iwl_fw_dbg_tlv_h__
59 #define __iwl_fw_dbg_tlv_h__
60 
61 #include <linux/bitops.h>
62 
63 #define IWL_FW_INI_MAX_REGION_ID		64
64 #define IWL_FW_INI_MAX_NAME			32
65 #define IWL_FW_INI_MAX_CFG_NAME			64
66 #define IWL_FW_INI_DOMAIN_ALWAYS_ON		0
67 
68 /**
69  * struct iwl_fw_ini_hcmd
70  *
71  * @id: the debug configuration command type for instance: 0xf6 / 0xf5 / DHC
72  * @group: the desired cmd group
73  * @reserved: to align to FW struct
74  * @data: all of the relevant command data to be sent
75  */
76 struct iwl_fw_ini_hcmd {
77 	u8 id;
78 	u8 group;
79 	__le16 reserved;
80 	u8 data[0];
81 } __packed; /* FW_DEBUG_TLV_HCMD_DATA_API_S_VER_1 */
82 
83 /**
84  * struct iwl_fw_ini_header - Common Header for all ini debug TLV's structures
85  *
86  * @version: TLV version
87  * @domain: domain of the TLV. One of &enum iwl_fw_ini_dbg_domain
88  * @data: TLV data
89  */
90 struct iwl_fw_ini_header {
91 	__le32 version;
92 	__le32 domain;
93 	u8 data[];
94 } __packed; /* FW_TLV_DEBUG_HEADER_S_VER_1 */
95 
96 /**
97  * struct iwl_fw_ini_region_dev_addr - Configuration to read device addresses
98  *
99  * @size: size of each memory chunk
100  * @offset: offset to add to the base address of each chunk
101  */
102 struct iwl_fw_ini_region_dev_addr {
103 	__le32 size;
104 	__le32 offset;
105 } __packed; /* FW_TLV_DEBUG_DEVICE_ADDR_API_S_VER_1 */
106 
107 /**
108  * struct iwl_fw_ini_region_fifos - Configuration to read Tx/Rx fifos
109  *
110  * @fid: fifos ids array. Used to determine what fifos to collect
111  * @hdr_only: if non zero, collect only the registers
112  * @offset: offset to add to the registers addresses
113  */
114 struct iwl_fw_ini_region_fifos {
115 	__le32 fid[2];
116 	__le32 hdr_only;
117 	__le32 offset;
118 } __packed; /* FW_TLV_DEBUG_REGION_FIFOS_API_S_VER_1 */
119 
120 /**
121  * struct iwl_fw_ini_region_err_table - error table region data
122  *
123  * Configuration to read Umac/Lmac error table
124  *
125  * @version: version of the error table
126  * @base_addr: base address of the error table
127  * @size: size of the error table
128  * @offset: offset to add to &base_addr
129  */
130 struct iwl_fw_ini_region_err_table {
131 	__le32 version;
132 	__le32 base_addr;
133 	__le32 size;
134 	__le32 offset;
135 } __packed; /* FW_TLV_DEBUG_REGION_ERROR_TABLE_API_S_VER_1 */
136 
137 /**
138  * struct iwl_fw_ini_region_internal_buffer - internal buffer region data
139  *
140  * Configuration to read internal monitor buffer
141  *
142  * @alloc_id: allocation id one of &enum iwl_fw_ini_allocation_id
143  * @base_addr: internal buffer base address
144  * @size: size internal buffer size
145  */
146 struct iwl_fw_ini_region_internal_buffer {
147 	__le32 alloc_id;
148 	__le32 base_addr;
149 	__le32 size;
150 } __packed; /* FW_TLV_DEBUG_REGION_INTERNAL_BUFFER_API_S_VER_1 */
151 
152 /**
153  * struct iwl_fw_ini_region_tlv - region TLV
154  *
155  * Configures parameters for region data collection
156  *
157  * @hdr: debug header
158  * @id: region id. Max id is &IWL_FW_INI_MAX_REGION_ID
159  * @type: region type. One of &enum iwl_fw_ini_region_type
160  * @name: region name
161  * @dev_addr: device address configuration. Used by
162  *	&IWL_FW_INI_REGION_DEVICE_MEMORY, &IWL_FW_INI_REGION_PERIPHERY_MAC,
163  *	&IWL_FW_INI_REGION_PERIPHERY_PHY, &IWL_FW_INI_REGION_PERIPHERY_AUX,
164  *	&IWL_FW_INI_REGION_PAGING, &IWL_FW_INI_REGION_CSR,
165  *	&IWL_FW_INI_REGION_DRAM_IMR and &IWL_FW_INI_REGION_PCI_IOSF_CONFIG
166  * @fifos: fifos configuration. Used by &IWL_FW_INI_REGION_TXF and
167  *	&IWL_FW_INI_REGION_RXF
168  * @err_table: error table configuration. Used by
169  *	IWL_FW_INI_REGION_LMAC_ERROR_TABLE and
170  *	IWL_FW_INI_REGION_UMAC_ERROR_TABLE
171  * @internal_buffer: internal monitor buffer configuration. Used by
172  *	&IWL_FW_INI_REGION_INTERNAL_BUFFER
173  * @dram_alloc_id: dram allocation id. One of &enum iwl_fw_ini_allocation_id.
174  *	Used by &IWL_FW_INI_REGION_DRAM_BUFFER
175  * @tlv_mask: tlv collection mask. Used by &IWL_FW_INI_REGION_TLV
176  * @addrs: array of addresses attached to the end of the region tlv
177  */
178 struct iwl_fw_ini_region_tlv {
179 	struct iwl_fw_ini_header hdr;
180 	__le32 id;
181 	__le32 type;
182 	u8 name[IWL_FW_INI_MAX_NAME];
183 	union {
184 		struct iwl_fw_ini_region_dev_addr dev_addr;
185 		struct iwl_fw_ini_region_fifos fifos;
186 		struct iwl_fw_ini_region_err_table err_table;
187 		struct iwl_fw_ini_region_internal_buffer internal_buffer;
188 		__le32 dram_alloc_id;
189 		__le32 tlv_mask;
190 	}; /* FW_TLV_DEBUG_REGION_CONF_PARAMS_API_U_VER_1 */
191 	__le32 addrs[];
192 } __packed; /* FW_TLV_DEBUG_REGION_API_S_VER_1 */
193 
194 /**
195  * struct iwl_fw_ini_debug_info_tlv
196  *
197  * debug configuration name for a specific image
198  *
199  * @hdr: debug header
200  * @image_type: image type
201  * @debug_cfg_name: debug configuration name
202  */
203 struct iwl_fw_ini_debug_info_tlv {
204 	struct iwl_fw_ini_header hdr;
205 	__le32 image_type;
206 	u8 debug_cfg_name[IWL_FW_INI_MAX_CFG_NAME];
207 } __packed; /* FW_TLV_DEBUG_INFO_API_S_VER_1 */
208 
209 /**
210  * struct iwl_fw_ini_allocation_tlv - Allocates DRAM buffers
211  *
212  * @hdr: debug header
213  * @alloc_id: allocation id. One of &enum iwl_fw_ini_allocation_id
214  * @buf_location: buffer location. One of &enum iwl_fw_ini_buffer_location
215  * @req_size: requested buffer size
216  * @max_frags_num: maximum number of fragments
217  * @min_size: minimum buffer size
218  */
219 struct iwl_fw_ini_allocation_tlv {
220 	struct iwl_fw_ini_header hdr;
221 	__le32 alloc_id;
222 	__le32 buf_location;
223 	__le32 req_size;
224 	__le32 max_frags_num;
225 	__le32 min_size;
226 } __packed; /* FW_TLV_DEBUG_BUFFER_ALLOCATION_API_S_VER_1 */
227 
228 /**
229  * struct iwl_fw_ini_trigger_tlv - trigger TLV
230  *
231  * Trigger that upon firing, determines what regions to collect
232  *
233  * @hdr: debug header
234  * @time_point: time point. One of &enum iwl_fw_ini_time_point
235  * @trigger_reason: trigger reason
236  * @apply_policy: uses &enum iwl_fw_ini_trigger_apply_policy
237  * @dump_delay: delay from trigger fire to dump, in usec
238  * @occurrences: max trigger fire occurrences allowed
239  * @reserved: unused
240  * @ignore_consec: ignore consecutive triggers, in usec
241  * @reset_fw: if non zero, will reset and reload the FW
242  * @multi_dut: initiate debug dump data on several DUTs
243  * @regions_mask: mask of regions to collect
244  * @data: trigger data
245  */
246 struct iwl_fw_ini_trigger_tlv {
247 	struct iwl_fw_ini_header hdr;
248 	__le32 time_point;
249 	__le32 trigger_reason;
250 	__le32 apply_policy;
251 	__le32 dump_delay;
252 	__le32 occurrences;
253 	__le32 reserved;
254 	__le32 ignore_consec;
255 	__le32 reset_fw;
256 	__le32 multi_dut;
257 	__le64 regions_mask;
258 	__le32 data[];
259 } __packed; /* FW_TLV_DEBUG_TRIGGER_API_S_VER_1 */
260 
261 /**
262  * struct iwl_fw_ini_hcmd_tlv - Generic Host command pass through TLV
263  *
264  * @hdr: debug header
265  * @time_point: time point. One of &enum iwl_fw_ini_time_point
266  * @period_msec: interval at which the hcmd will be sent to the FW.
267  *	Measured in msec (0 = one time command)
268  * @hcmd: a variable length host-command to be sent to apply the configuration
269  */
270 struct iwl_fw_ini_hcmd_tlv {
271 	struct iwl_fw_ini_header hdr;
272 	__le32 time_point;
273 	__le32 period_msec;
274 	struct iwl_fw_ini_hcmd hcmd;
275 } __packed; /* FW_TLV_DEBUG_HCMD_API_S_VER_1 */
276 
277 /**
278  * enum iwl_fw_ini_allocation_id
279  *
280  * @IWL_FW_INI_ALLOCATION_INVALID: invalid
281  * @IWL_FW_INI_ALLOCATION_ID_DBGC1: allocation meant for DBGC1 configuration
282  * @IWL_FW_INI_ALLOCATION_ID_DBGC2: allocation meant for DBGC2 configuration
283  * @IWL_FW_INI_ALLOCATION_ID_DBGC3: allocation meant for DBGC3 configuration
284  * @IWL_FW_INI_ALLOCATION_NUM: number of allocation ids
285 */
286 enum iwl_fw_ini_allocation_id {
287 	IWL_FW_INI_ALLOCATION_INVALID,
288 	IWL_FW_INI_ALLOCATION_ID_DBGC1,
289 	IWL_FW_INI_ALLOCATION_ID_DBGC2,
290 	IWL_FW_INI_ALLOCATION_ID_DBGC3,
291 	IWL_FW_INI_ALLOCATION_NUM,
292 }; /* FW_DEBUG_TLV_ALLOCATION_ID_E_VER_1 */
293 
294 /**
295  * enum iwl_fw_ini_buffer_location
296  *
297  * @IWL_FW_INI_LOCATION_INVALID: invalid
298  * @IWL_FW_INI_LOCATION_SRAM_PATH: SRAM location
299  * @IWL_FW_INI_LOCATION_DRAM_PATH: DRAM location
300  * @IWL_FW_INI_LOCATION_NPK_PATH: NPK location
301  */
302 enum iwl_fw_ini_buffer_location {
303 	IWL_FW_INI_LOCATION_INVALID,
304 	IWL_FW_INI_LOCATION_SRAM_PATH,
305 	IWL_FW_INI_LOCATION_DRAM_PATH,
306 	IWL_FW_INI_LOCATION_NPK_PATH,
307 }; /* FW_DEBUG_TLV_BUFFER_LOCATION_E_VER_1 */
308 
309 /**
310  * enum iwl_fw_ini_region_type
311  *
312  * @IWL_FW_INI_REGION_INVALID: invalid
313  * @IWL_FW_INI_REGION_TLV: uCode and debug TLVs
314  * @IWL_FW_INI_REGION_INTERNAL_BUFFER: monitor SMEM buffer
315  * @IWL_FW_INI_REGION_DRAM_BUFFER: monitor DRAM buffer
316  * @IWL_FW_INI_REGION_TXF: TX fifos
317  * @IWL_FW_INI_REGION_RXF: RX fifo
318  * @IWL_FW_INI_REGION_LMAC_ERROR_TABLE: lmac error table
319  * @IWL_FW_INI_REGION_UMAC_ERROR_TABLE: umac error table
320  * @IWL_FW_INI_REGION_RSP_OR_NOTIF: FW response or notification data
321  * @IWL_FW_INI_REGION_DEVICE_MEMORY: device internal memory
322  * @IWL_FW_INI_REGION_PERIPHERY_MAC: periphery registers of MAC
323  * @IWL_FW_INI_REGION_PERIPHERY_PHY: periphery registers of PHY
324  * @IWL_FW_INI_REGION_PERIPHERY_AUX: periphery registers of AUX
325  * @IWL_FW_INI_REGION_PAGING: paging memory
326  * @IWL_FW_INI_REGION_CSR: CSR registers
327  * @IWL_FW_INI_REGION_DRAM_IMR: IMR memory
328  * @IWL_FW_INI_REGION_PCI_IOSF_CONFIG: PCI/IOSF config
329  * @IWL_FW_INI_REGION_NUM: number of region types
330  */
331 enum iwl_fw_ini_region_type {
332 	IWL_FW_INI_REGION_INVALID,
333 	IWL_FW_INI_REGION_TLV,
334 	IWL_FW_INI_REGION_INTERNAL_BUFFER,
335 	IWL_FW_INI_REGION_DRAM_BUFFER,
336 	IWL_FW_INI_REGION_TXF,
337 	IWL_FW_INI_REGION_RXF,
338 	IWL_FW_INI_REGION_LMAC_ERROR_TABLE,
339 	IWL_FW_INI_REGION_UMAC_ERROR_TABLE,
340 	IWL_FW_INI_REGION_RSP_OR_NOTIF,
341 	IWL_FW_INI_REGION_DEVICE_MEMORY,
342 	IWL_FW_INI_REGION_PERIPHERY_MAC,
343 	IWL_FW_INI_REGION_PERIPHERY_PHY,
344 	IWL_FW_INI_REGION_PERIPHERY_AUX,
345 	IWL_FW_INI_REGION_PAGING,
346 	IWL_FW_INI_REGION_CSR,
347 	IWL_FW_INI_REGION_DRAM_IMR,
348 	IWL_FW_INI_REGION_PCI_IOSF_CONFIG,
349 	IWL_FW_INI_REGION_NUM
350 }; /* FW_TLV_DEBUG_REGION_TYPE_API_E */
351 
352 /**
353  * enum iwl_fw_ini_time_point
354  *
355  * Hard coded time points in which the driver can send hcmd or perform dump
356  * collection
357  *
358  * @IWL_FW_INI_TIME_POINT_EARLY: pre loading the FW
359  * @IWL_FW_INI_TIME_POINT_AFTER_ALIVE: first cmd from host after alive notif
360  * @IWL_FW_INI_TIME_POINT_POST_INIT: last cmd in series of init sequence
361  * @IWL_FW_INI_TIME_POINT_FW_ASSERT: FW assert
362  * @IWL_FW_INI_TIME_POINT_FW_HW_ERROR: FW HW error
363  * @IWL_FW_INI_TIME_POINT_FW_TFD_Q_HANG: TFD queue hang
364  * @IWL_FW_INI_TIME_POINT_FW_DHC_NOTIFOCATION: DHC cmd response and notif
365  * @IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF: FW response or notification.
366  *	data field holds id and group
367  * @IWL_FW_INI_TIME_POINT_USER_TRIGGER: user trigger time point
368  * @IWL_FW_INI_TIME_POINT_PERIODIC: periodic timepoint that fires in constant
369  *	intervals. data field holds the interval time in msec
370  * @IWL_FW_INI_TIME_POINT_WDG_TIMEOUT: watchdog timeout
371  * @IWL_FW_INI_TIME_POINT_HOST_ASSERT: Unused
372  * @IWL_FW_INI_TIME_POINT_HOST_ALIVE_TIMEOUT: alive timeout
373  * @IWL_FW_INI_TIME_POINT_HOST_DEVICE_ENABLE: device enable
374  * @IWL_FW_INI_TIME_POINT_HOST_DEVICE_DISABLE: device disable
375  * @IWL_FW_INI_TIME_POINT_HOST_D3_START: D3 start
376  * @IWL_FW_INI_TIME_POINT_HOST_D3_END: D3 end
377  * @IWL_FW_INI_TIME_POINT_MISSED_BEACONS: missed beacons
378  * @IWL_FW_INI_TIME_POINT_ASSOC_FAILED: association failure
379  * @IWL_FW_INI_TIME_POINT_TX_FAILED: Tx frame failed
380  * @IWL_FW_INI_TIME_POINT_TX_WFD_ACTION_FRAME_FAILED: wifi direct action
381  *	frame failed
382  * @IWL_FW_INI_TIME_POINT_TX_LATENCY_THRESHOLD: Tx latency threshold
383  * @IWL_FW_INI_TIME_POINT_HANG_OCCURRED: hang occurred
384  * @IWL_FW_INI_TIME_POINT_EAPOL_FAILED: EAPOL failed
385  * @IWL_FW_INI_TIME_POINT_FAKE_TX: fake Tx
386  * @IWL_FW_INI_TIME_POINT_DEASSOC: de association
387  * @IWL_FW_INI_TIME_POINT_NUM: number of time points
388  */
389 enum iwl_fw_ini_time_point {
390 	IWL_FW_INI_TIME_POINT_INVALID,
391 	IWL_FW_INI_TIME_POINT_EARLY,
392 	IWL_FW_INI_TIME_POINT_AFTER_ALIVE,
393 	IWL_FW_INI_TIME_POINT_POST_INIT,
394 	IWL_FW_INI_TIME_POINT_FW_ASSERT,
395 	IWL_FW_INI_TIME_POINT_FW_HW_ERROR,
396 	IWL_FW_INI_TIME_POINT_FW_TFD_Q_HANG,
397 	IWL_FW_INI_TIME_POINT_FW_DHC_NOTIFOCATION,
398 	IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF,
399 	IWL_FW_INI_TIME_POINT_USER_TRIGGER,
400 	IWL_FW_INI_TIME_POINT_PERIODIC,
401 	IWL_FW_INI_TIME_POINT_WDG_TIMEOUT,
402 	IWL_FW_INI_TIME_POINT_HOST_ASSERT,
403 	IWL_FW_INI_TIME_POINT_HOST_ALIVE_TIMEOUT,
404 	IWL_FW_INI_TIME_POINT_HOST_DEVICE_ENABLE,
405 	IWL_FW_INI_TIME_POINT_HOST_DEVICE_DISABLE,
406 	IWL_FW_INI_TIME_POINT_HOST_D3_START,
407 	IWL_FW_INI_TIME_POINT_HOST_D3_END,
408 	IWL_FW_INI_TIME_POINT_MISSED_BEACONS,
409 	IWL_FW_INI_TIME_POINT_ASSOC_FAILED,
410 	IWL_FW_INI_TIME_POINT_TX_FAILED,
411 	IWL_FW_INI_TIME_POINT_TX_WFD_ACTION_FRAME_FAILED,
412 	IWL_FW_INI_TIME_POINT_TX_LATENCY_THRESHOLD,
413 	IWL_FW_INI_TIME_POINT_HANG_OCCURRED,
414 	IWL_FW_INI_TIME_POINT_EAPOL_FAILED,
415 	IWL_FW_INI_TIME_POINT_FAKE_TX,
416 	IWL_FW_INI_TIME_POINT_DEASSOC,
417 	IWL_FW_INI_TIME_POINT_NUM,
418 }; /* FW_TLV_DEBUG_TIME_POINT_API_E */
419 
420 /**
421  * enum iwl_fw_ini_trigger_apply_policy - Determines how to apply triggers
422  *
423  * @IWL_FW_INI_APPLY_POLICY_MATCH_TIME_POINT: match by time point
424  * @IWL_FW_INI_APPLY_POLICY_MATCH_DATA: match by trigger data
425  * @IWL_FW_INI_APPLY_POLICY_OVERRIDE_REGIONS: override regions mask.
426  *	Append otherwise
427  * @IWL_FW_INI_APPLY_POLICY_OVERRIDE_CFG: override trigger configuration
428  * @IWL_FW_INI_APPLY_POLICY_OVERRIDE_DATA: override trigger data.
429  *	Append otherwise
430  */
431 enum iwl_fw_ini_trigger_apply_policy {
432 	IWL_FW_INI_APPLY_POLICY_MATCH_TIME_POINT	= BIT(0),
433 	IWL_FW_INI_APPLY_POLICY_MATCH_DATA		= BIT(1),
434 	IWL_FW_INI_APPLY_POLICY_OVERRIDE_REGIONS	= BIT(8),
435 	IWL_FW_INI_APPLY_POLICY_OVERRIDE_CFG		= BIT(9),
436 	IWL_FW_INI_APPLY_POLICY_OVERRIDE_DATA		= BIT(10),
437 };
438 #endif
439