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 - 2020 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 - 2020 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 	IWL_FW_INI_LOCATION_NUM,
308 }; /* FW_DEBUG_TLV_BUFFER_LOCATION_E_VER_1 */
309 
310 /**
311  * enum iwl_fw_ini_region_type
312  *
313  * @IWL_FW_INI_REGION_INVALID: invalid
314  * @IWL_FW_INI_REGION_TLV: uCode and debug TLVs
315  * @IWL_FW_INI_REGION_INTERNAL_BUFFER: monitor SMEM buffer
316  * @IWL_FW_INI_REGION_DRAM_BUFFER: monitor DRAM buffer
317  * @IWL_FW_INI_REGION_TXF: TX fifos
318  * @IWL_FW_INI_REGION_RXF: RX fifo
319  * @IWL_FW_INI_REGION_LMAC_ERROR_TABLE: lmac error table
320  * @IWL_FW_INI_REGION_UMAC_ERROR_TABLE: umac error table
321  * @IWL_FW_INI_REGION_RSP_OR_NOTIF: FW response or notification data
322  * @IWL_FW_INI_REGION_DEVICE_MEMORY: device internal memory
323  * @IWL_FW_INI_REGION_PERIPHERY_MAC: periphery registers of MAC
324  * @IWL_FW_INI_REGION_PERIPHERY_PHY: periphery registers of PHY
325  * @IWL_FW_INI_REGION_PERIPHERY_AUX: periphery registers of AUX
326  * @IWL_FW_INI_REGION_PAGING: paging memory
327  * @IWL_FW_INI_REGION_CSR: CSR registers
328  * @IWL_FW_INI_REGION_DRAM_IMR: IMR memory
329  * @IWL_FW_INI_REGION_PCI_IOSF_CONFIG: PCI/IOSF config
330  * @IWL_FW_INI_REGION_NUM: number of region types
331  */
332 enum iwl_fw_ini_region_type {
333 	IWL_FW_INI_REGION_INVALID,
334 	IWL_FW_INI_REGION_TLV,
335 	IWL_FW_INI_REGION_INTERNAL_BUFFER,
336 	IWL_FW_INI_REGION_DRAM_BUFFER,
337 	IWL_FW_INI_REGION_TXF,
338 	IWL_FW_INI_REGION_RXF,
339 	IWL_FW_INI_REGION_LMAC_ERROR_TABLE,
340 	IWL_FW_INI_REGION_UMAC_ERROR_TABLE,
341 	IWL_FW_INI_REGION_RSP_OR_NOTIF,
342 	IWL_FW_INI_REGION_DEVICE_MEMORY,
343 	IWL_FW_INI_REGION_PERIPHERY_MAC,
344 	IWL_FW_INI_REGION_PERIPHERY_PHY,
345 	IWL_FW_INI_REGION_PERIPHERY_AUX,
346 	IWL_FW_INI_REGION_PAGING,
347 	IWL_FW_INI_REGION_CSR,
348 	IWL_FW_INI_REGION_DRAM_IMR,
349 	IWL_FW_INI_REGION_PCI_IOSF_CONFIG,
350 	IWL_FW_INI_REGION_NUM
351 }; /* FW_TLV_DEBUG_REGION_TYPE_API_E */
352 
353 /**
354  * enum iwl_fw_ini_time_point
355  *
356  * Hard coded time points in which the driver can send hcmd or perform dump
357  * collection
358  *
359  * @IWL_FW_INI_TIME_POINT_EARLY: pre loading the FW
360  * @IWL_FW_INI_TIME_POINT_AFTER_ALIVE: first cmd from host after alive notif
361  * @IWL_FW_INI_TIME_POINT_POST_INIT: last cmd in series of init sequence
362  * @IWL_FW_INI_TIME_POINT_FW_ASSERT: FW assert
363  * @IWL_FW_INI_TIME_POINT_FW_HW_ERROR: FW HW error
364  * @IWL_FW_INI_TIME_POINT_FW_TFD_Q_HANG: TFD queue hang
365  * @IWL_FW_INI_TIME_POINT_FW_DHC_NOTIFOCATION: DHC cmd response and notif
366  * @IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF: FW response or notification.
367  *	data field holds id and group
368  * @IWL_FW_INI_TIME_POINT_USER_TRIGGER: user trigger time point
369  * @IWL_FW_INI_TIME_POINT_PERIODIC: periodic timepoint that fires in constant
370  *	intervals. data field holds the interval time in msec
371  * @IWL_FW_INI_TIME_POINT_WDG_TIMEOUT: watchdog timeout
372  * @IWL_FW_INI_TIME_POINT_HOST_ASSERT: Unused
373  * @IWL_FW_INI_TIME_POINT_HOST_ALIVE_TIMEOUT: alive timeout
374  * @IWL_FW_INI_TIME_POINT_HOST_DEVICE_ENABLE: device enable
375  * @IWL_FW_INI_TIME_POINT_HOST_DEVICE_DISABLE: device disable
376  * @IWL_FW_INI_TIME_POINT_HOST_D3_START: D3 start
377  * @IWL_FW_INI_TIME_POINT_HOST_D3_END: D3 end
378  * @IWL_FW_INI_TIME_POINT_MISSED_BEACONS: missed beacons
379  * @IWL_FW_INI_TIME_POINT_ASSOC_FAILED: association failure
380  * @IWL_FW_INI_TIME_POINT_TX_FAILED: Tx frame failed
381  * @IWL_FW_INI_TIME_POINT_TX_WFD_ACTION_FRAME_FAILED: wifi direct action
382  *	frame failed
383  * @IWL_FW_INI_TIME_POINT_TX_LATENCY_THRESHOLD: Tx latency threshold
384  * @IWL_FW_INI_TIME_POINT_HANG_OCCURRED: hang occurred
385  * @IWL_FW_INI_TIME_POINT_EAPOL_FAILED: EAPOL failed
386  * @IWL_FW_INI_TIME_POINT_FAKE_TX: fake Tx
387  * @IWL_FW_INI_TIME_POINT_DEASSOC: de association
388  * @IWL_FW_INI_TIME_POINT_NUM: number of time points
389  */
390 enum iwl_fw_ini_time_point {
391 	IWL_FW_INI_TIME_POINT_INVALID,
392 	IWL_FW_INI_TIME_POINT_EARLY,
393 	IWL_FW_INI_TIME_POINT_AFTER_ALIVE,
394 	IWL_FW_INI_TIME_POINT_POST_INIT,
395 	IWL_FW_INI_TIME_POINT_FW_ASSERT,
396 	IWL_FW_INI_TIME_POINT_FW_HW_ERROR,
397 	IWL_FW_INI_TIME_POINT_FW_TFD_Q_HANG,
398 	IWL_FW_INI_TIME_POINT_FW_DHC_NOTIFOCATION,
399 	IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF,
400 	IWL_FW_INI_TIME_POINT_USER_TRIGGER,
401 	IWL_FW_INI_TIME_POINT_PERIODIC,
402 	IWL_FW_INI_TIME_POINT_WDG_TIMEOUT,
403 	IWL_FW_INI_TIME_POINT_HOST_ASSERT,
404 	IWL_FW_INI_TIME_POINT_HOST_ALIVE_TIMEOUT,
405 	IWL_FW_INI_TIME_POINT_HOST_DEVICE_ENABLE,
406 	IWL_FW_INI_TIME_POINT_HOST_DEVICE_DISABLE,
407 	IWL_FW_INI_TIME_POINT_HOST_D3_START,
408 	IWL_FW_INI_TIME_POINT_HOST_D3_END,
409 	IWL_FW_INI_TIME_POINT_MISSED_BEACONS,
410 	IWL_FW_INI_TIME_POINT_ASSOC_FAILED,
411 	IWL_FW_INI_TIME_POINT_TX_FAILED,
412 	IWL_FW_INI_TIME_POINT_TX_WFD_ACTION_FRAME_FAILED,
413 	IWL_FW_INI_TIME_POINT_TX_LATENCY_THRESHOLD,
414 	IWL_FW_INI_TIME_POINT_HANG_OCCURRED,
415 	IWL_FW_INI_TIME_POINT_EAPOL_FAILED,
416 	IWL_FW_INI_TIME_POINT_FAKE_TX,
417 	IWL_FW_INI_TIME_POINT_DEASSOC,
418 	IWL_FW_INI_TIME_POINT_NUM,
419 }; /* FW_TLV_DEBUG_TIME_POINT_API_E */
420 
421 /**
422  * enum iwl_fw_ini_trigger_apply_policy - Determines how to apply triggers
423  *
424  * @IWL_FW_INI_APPLY_POLICY_MATCH_TIME_POINT: match by time point
425  * @IWL_FW_INI_APPLY_POLICY_MATCH_DATA: match by trigger data
426  * @IWL_FW_INI_APPLY_POLICY_OVERRIDE_REGIONS: override regions mask.
427  *	Append otherwise
428  * @IWL_FW_INI_APPLY_POLICY_OVERRIDE_CFG: override trigger configuration
429  * @IWL_FW_INI_APPLY_POLICY_OVERRIDE_DATA: override trigger data.
430  *	Append otherwise
431  */
432 enum iwl_fw_ini_trigger_apply_policy {
433 	IWL_FW_INI_APPLY_POLICY_MATCH_TIME_POINT	= BIT(0),
434 	IWL_FW_INI_APPLY_POLICY_MATCH_DATA		= BIT(1),
435 	IWL_FW_INI_APPLY_POLICY_OVERRIDE_REGIONS	= BIT(8),
436 	IWL_FW_INI_APPLY_POLICY_OVERRIDE_CFG		= BIT(9),
437 	IWL_FW_INI_APPLY_POLICY_OVERRIDE_DATA		= BIT(10),
438 };
439 #endif
440