1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2018-2021 Intel Corporation
4  */
5 #ifndef __iwl_fw_dbg_tlv_h__
6 #define __iwl_fw_dbg_tlv_h__
7 
8 #include <linux/bitops.h>
9 
10 #define IWL_FW_INI_MAX_REGION_ID		64
11 #define IWL_FW_INI_MAX_NAME			32
12 #define IWL_FW_INI_MAX_CFG_NAME			64
13 #define IWL_FW_INI_DOMAIN_ALWAYS_ON		0
14 #define IWL_FW_INI_REGION_V2_MASK		0x0000FFFF
15 
16 /**
17  * struct iwl_fw_ini_hcmd
18  *
19  * @id: the debug configuration command type for instance: 0xf6 / 0xf5 / DHC
20  * @group: the desired cmd group
21  * @reserved: to align to FW struct
22  * @data: all of the relevant command data to be sent
23  */
24 struct iwl_fw_ini_hcmd {
25 	u8 id;
26 	u8 group;
27 	__le16 reserved;
28 	u8 data[0];
29 } __packed; /* FW_DEBUG_TLV_HCMD_DATA_API_S_VER_1 */
30 
31 /**
32  * struct iwl_fw_ini_header - Common Header for all ini debug TLV's structures
33  *
34  * @version: TLV version
35  * @domain: domain of the TLV. One of &enum iwl_fw_ini_dbg_domain
36  * @data: TLV data
37  */
38 struct iwl_fw_ini_header {
39 	__le32 version;
40 	__le32 domain;
41 	u8 data[];
42 } __packed; /* FW_TLV_DEBUG_HEADER_S_VER_1 */
43 
44 /**
45  * struct iwl_fw_ini_region_dev_addr - Configuration to read device addresses
46  *
47  * @size: size of each memory chunk
48  * @offset: offset to add to the base address of each chunk
49  */
50 struct iwl_fw_ini_region_dev_addr {
51 	__le32 size;
52 	__le32 offset;
53 } __packed; /* FW_TLV_DEBUG_DEVICE_ADDR_API_S_VER_1 */
54 
55 /**
56  * struct iwl_fw_ini_region_fifos - Configuration to read Tx/Rx fifos
57  *
58  * @fid: fifos ids array. Used to determine what fifos to collect
59  * @hdr_only: if non zero, collect only the registers
60  * @offset: offset to add to the registers addresses
61  */
62 struct iwl_fw_ini_region_fifos {
63 	__le32 fid[2];
64 	__le32 hdr_only;
65 	__le32 offset;
66 } __packed; /* FW_TLV_DEBUG_REGION_FIFOS_API_S_VER_1 */
67 
68 /**
69  * struct iwl_fw_ini_region_err_table - error table region data
70  *
71  * Configuration to read Umac/Lmac error table
72  *
73  * @version: version of the error table
74  * @base_addr: base address of the error table
75  * @size: size of the error table
76  * @offset: offset to add to &base_addr
77  */
78 struct iwl_fw_ini_region_err_table {
79 	__le32 version;
80 	__le32 base_addr;
81 	__le32 size;
82 	__le32 offset;
83 } __packed; /* FW_TLV_DEBUG_REGION_ERROR_TABLE_API_S_VER_1 */
84 
85 /**
86  * struct iwl_fw_ini_region_special_device_memory - special device memory
87  *
88  * Configuration to read a special memory
89  *
90  * @type: type of the special memory
91  * @version: version of the special memory
92  * @base_addr: base address of the error table
93  * @size: size of the error table
94  * @offset: offset to add to &base_addr
95  */
96 struct iwl_fw_ini_region_special_device_memory {
97 	__le16 type;
98 	__le16 version;
99 	__le32 base_addr;
100 	__le32 size;
101 	__le32 offset;
102 } __packed; /* FW_TLV_DEBUG_REGION_SPECIAL_DEVICE_ADDR_API_S_VER_1 */
103 
104 /**
105  * struct iwl_fw_ini_region_internal_buffer - internal buffer region data
106  *
107  * Configuration to read internal monitor buffer
108  *
109  * @alloc_id: allocation id one of &enum iwl_fw_ini_allocation_id
110  * @base_addr: internal buffer base address
111  * @size: size internal buffer size
112  */
113 struct iwl_fw_ini_region_internal_buffer {
114 	__le32 alloc_id;
115 	__le32 base_addr;
116 	__le32 size;
117 } __packed; /* FW_TLV_DEBUG_REGION_INTERNAL_BUFFER_API_S_VER_1 */
118 
119 /**
120  * struct iwl_fw_ini_region_tlv - region TLV
121  *
122  * Configures parameters for region data collection
123  *
124  * @hdr: debug header
125  * @id: region id. Max id is &IWL_FW_INI_MAX_REGION_ID
126  * @type: region type. One of &enum iwl_fw_ini_region_type
127  * @name: region name
128  * @dev_addr: device address configuration. Used by
129  *	&IWL_FW_INI_REGION_DEVICE_MEMORY, &IWL_FW_INI_REGION_PERIPHERY_MAC,
130  *	&IWL_FW_INI_REGION_PERIPHERY_PHY, &IWL_FW_INI_REGION_PERIPHERY_AUX,
131  *	&IWL_FW_INI_REGION_PAGING, &IWL_FW_INI_REGION_CSR,
132  *	&IWL_FW_INI_REGION_DRAM_IMR and &IWL_FW_INI_REGION_PCI_IOSF_CONFIG
133  * @fifos: fifos configuration. Used by &IWL_FW_INI_REGION_TXF and
134  *	&IWL_FW_INI_REGION_RXF
135  * @err_table: error table configuration. Used by
136  *	IWL_FW_INI_REGION_LMAC_ERROR_TABLE and
137  *	IWL_FW_INI_REGION_UMAC_ERROR_TABLE
138  * @internal_buffer: internal monitor buffer configuration. Used by
139  *	&IWL_FW_INI_REGION_INTERNAL_BUFFER
140  * @dram_alloc_id: dram allocation id. One of &enum iwl_fw_ini_allocation_id.
141  *	Used by &IWL_FW_INI_REGION_DRAM_BUFFER
142  * @tlv_mask: tlv collection mask. Used by &IWL_FW_INI_REGION_TLV
143  * @addrs: array of addresses attached to the end of the region tlv
144  */
145 struct iwl_fw_ini_region_tlv {
146 	struct iwl_fw_ini_header hdr;
147 	__le32 id;
148 	__le32 type;
149 	u8 name[IWL_FW_INI_MAX_NAME];
150 	union {
151 		struct iwl_fw_ini_region_dev_addr dev_addr;
152 		struct iwl_fw_ini_region_fifos fifos;
153 		struct iwl_fw_ini_region_err_table err_table;
154 		struct iwl_fw_ini_region_internal_buffer internal_buffer;
155 		struct iwl_fw_ini_region_special_device_memory special_mem;
156 		__le32 dram_alloc_id;
157 		__le32 tlv_mask;
158 	}; /* FW_TLV_DEBUG_REGION_CONF_PARAMS_API_U_VER_1 */
159 	__le32 addrs[];
160 } __packed; /* FW_TLV_DEBUG_REGION_API_S_VER_1 */
161 
162 /**
163  * struct iwl_fw_ini_debug_info_tlv
164  *
165  * debug configuration name for a specific image
166  *
167  * @hdr: debug header
168  * @image_type: image type
169  * @debug_cfg_name: debug configuration name
170  */
171 struct iwl_fw_ini_debug_info_tlv {
172 	struct iwl_fw_ini_header hdr;
173 	__le32 image_type;
174 	u8 debug_cfg_name[IWL_FW_INI_MAX_CFG_NAME];
175 } __packed; /* FW_TLV_DEBUG_INFO_API_S_VER_1 */
176 
177 /**
178  * struct iwl_fw_ini_allocation_tlv - Allocates DRAM buffers
179  *
180  * @hdr: debug header
181  * @alloc_id: allocation id. One of &enum iwl_fw_ini_allocation_id
182  * @buf_location: buffer location. One of &enum iwl_fw_ini_buffer_location
183  * @req_size: requested buffer size
184  * @max_frags_num: maximum number of fragments
185  * @min_size: minimum buffer size
186  */
187 struct iwl_fw_ini_allocation_tlv {
188 	struct iwl_fw_ini_header hdr;
189 	__le32 alloc_id;
190 	__le32 buf_location;
191 	__le32 req_size;
192 	__le32 max_frags_num;
193 	__le32 min_size;
194 } __packed; /* FW_TLV_DEBUG_BUFFER_ALLOCATION_API_S_VER_1 */
195 
196 /**
197  * struct iwl_fw_ini_trigger_tlv - trigger TLV
198  *
199  * Trigger that upon firing, determines what regions to collect
200  *
201  * @hdr: debug header
202  * @time_point: time point. One of &enum iwl_fw_ini_time_point
203  * @trigger_reason: trigger reason
204  * @apply_policy: uses &enum iwl_fw_ini_trigger_apply_policy
205  * @dump_delay: delay from trigger fire to dump, in usec
206  * @occurrences: max trigger fire occurrences allowed
207  * @reserved: unused
208  * @ignore_consec: ignore consecutive triggers, in usec
209  * @reset_fw: if non zero, will reset and reload the FW
210  * @multi_dut: initiate debug dump data on several DUTs
211  * @regions_mask: mask of regions to collect
212  * @data: trigger data
213  */
214 struct iwl_fw_ini_trigger_tlv {
215 	struct iwl_fw_ini_header hdr;
216 	__le32 time_point;
217 	__le32 trigger_reason;
218 	__le32 apply_policy;
219 	__le32 dump_delay;
220 	__le32 occurrences;
221 	__le32 reserved;
222 	__le32 ignore_consec;
223 	__le32 reset_fw;
224 	__le32 multi_dut;
225 	__le64 regions_mask;
226 	__le32 data[];
227 } __packed; /* FW_TLV_DEBUG_TRIGGER_API_S_VER_1 */
228 
229 /**
230  * struct iwl_fw_ini_hcmd_tlv - Generic Host command pass through TLV
231  *
232  * @hdr: debug header
233  * @time_point: time point. One of &enum iwl_fw_ini_time_point
234  * @period_msec: interval at which the hcmd will be sent to the FW.
235  *	Measured in msec (0 = one time command)
236  * @hcmd: a variable length host-command to be sent to apply the configuration
237  */
238 struct iwl_fw_ini_hcmd_tlv {
239 	struct iwl_fw_ini_header hdr;
240 	__le32 time_point;
241 	__le32 period_msec;
242 	struct iwl_fw_ini_hcmd hcmd;
243 } __packed; /* FW_TLV_DEBUG_HCMD_API_S_VER_1 */
244 
245 /**
246  * enum iwl_fw_ini_allocation_id
247  *
248  * @IWL_FW_INI_ALLOCATION_INVALID: invalid
249  * @IWL_FW_INI_ALLOCATION_ID_DBGC1: allocation meant for DBGC1 configuration
250  * @IWL_FW_INI_ALLOCATION_ID_DBGC2: allocation meant for DBGC2 configuration
251  * @IWL_FW_INI_ALLOCATION_ID_DBGC3: allocation meant for DBGC3 configuration
252  * @IWL_FW_INI_ALLOCATION_ID_INTERNAL: allocation meant for Intreanl SMEM in D3
253  * @IWL_FW_INI_ALLOCATION_NUM: number of allocation ids
254 */
255 enum iwl_fw_ini_allocation_id {
256 	IWL_FW_INI_ALLOCATION_INVALID,
257 	IWL_FW_INI_ALLOCATION_ID_DBGC1,
258 	IWL_FW_INI_ALLOCATION_ID_DBGC2,
259 	IWL_FW_INI_ALLOCATION_ID_DBGC3,
260 	IWL_FW_INI_ALLOCATION_ID_INTERNAL,
261 	IWL_FW_INI_ALLOCATION_NUM,
262 }; /* FW_DEBUG_TLV_ALLOCATION_ID_E_VER_1 */
263 
264 /**
265  * enum iwl_fw_ini_buffer_location
266  *
267  * @IWL_FW_INI_LOCATION_INVALID: invalid
268  * @IWL_FW_INI_LOCATION_SRAM_PATH: SRAM location
269  * @IWL_FW_INI_LOCATION_DRAM_PATH: DRAM location
270  * @IWL_FW_INI_LOCATION_NPK_PATH: NPK location
271  */
272 enum iwl_fw_ini_buffer_location {
273 	IWL_FW_INI_LOCATION_INVALID,
274 	IWL_FW_INI_LOCATION_SRAM_PATH,
275 	IWL_FW_INI_LOCATION_DRAM_PATH,
276 	IWL_FW_INI_LOCATION_NPK_PATH,
277 	IWL_FW_INI_LOCATION_NUM,
278 }; /* FW_DEBUG_TLV_BUFFER_LOCATION_E_VER_1 */
279 
280 /**
281  * enum iwl_fw_ini_region_type
282  *
283  * @IWL_FW_INI_REGION_INVALID: invalid
284  * @IWL_FW_INI_REGION_TLV: uCode and debug TLVs
285  * @IWL_FW_INI_REGION_INTERNAL_BUFFER: monitor SMEM buffer
286  * @IWL_FW_INI_REGION_DRAM_BUFFER: monitor DRAM buffer
287  * @IWL_FW_INI_REGION_TXF: TX fifos
288  * @IWL_FW_INI_REGION_RXF: RX fifo
289  * @IWL_FW_INI_REGION_LMAC_ERROR_TABLE: lmac error table
290  * @IWL_FW_INI_REGION_UMAC_ERROR_TABLE: umac error table
291  * @IWL_FW_INI_REGION_RSP_OR_NOTIF: FW response or notification data
292  * @IWL_FW_INI_REGION_DEVICE_MEMORY: device internal memory
293  * @IWL_FW_INI_REGION_PERIPHERY_MAC: periphery registers of MAC
294  * @IWL_FW_INI_REGION_PERIPHERY_PHY: periphery registers of PHY
295  * @IWL_FW_INI_REGION_PERIPHERY_AUX: periphery registers of AUX
296  * @IWL_FW_INI_REGION_PAGING: paging memory
297  * @IWL_FW_INI_REGION_CSR: CSR registers
298  * @IWL_FW_INI_REGION_DRAM_IMR: IMR memory
299  * @IWL_FW_INI_REGION_PCI_IOSF_CONFIG: PCI/IOSF config
300  * @IWL_FW_INI_REGION_SPECIAL_DEVICE_MEMORY: special device memory
301  * @IWL_FW_INI_REGION_NUM: number of region types
302  */
303 enum iwl_fw_ini_region_type {
304 	IWL_FW_INI_REGION_INVALID,
305 	IWL_FW_INI_REGION_TLV,
306 	IWL_FW_INI_REGION_INTERNAL_BUFFER,
307 	IWL_FW_INI_REGION_DRAM_BUFFER,
308 	IWL_FW_INI_REGION_TXF,
309 	IWL_FW_INI_REGION_RXF,
310 	IWL_FW_INI_REGION_LMAC_ERROR_TABLE,
311 	IWL_FW_INI_REGION_UMAC_ERROR_TABLE,
312 	IWL_FW_INI_REGION_RSP_OR_NOTIF,
313 	IWL_FW_INI_REGION_DEVICE_MEMORY,
314 	IWL_FW_INI_REGION_PERIPHERY_MAC,
315 	IWL_FW_INI_REGION_PERIPHERY_PHY,
316 	IWL_FW_INI_REGION_PERIPHERY_AUX,
317 	IWL_FW_INI_REGION_PAGING,
318 	IWL_FW_INI_REGION_CSR,
319 	IWL_FW_INI_REGION_DRAM_IMR,
320 	IWL_FW_INI_REGION_PCI_IOSF_CONFIG,
321 	IWL_FW_INI_REGION_SPECIAL_DEVICE_MEMORY,
322 	IWL_FW_INI_REGION_NUM
323 }; /* FW_TLV_DEBUG_REGION_TYPE_API_E */
324 
325 /**
326  * enum iwl_fw_ini_time_point
327  *
328  * Hard coded time points in which the driver can send hcmd or perform dump
329  * collection
330  *
331  * @IWL_FW_INI_TIME_POINT_EARLY: pre loading the FW
332  * @IWL_FW_INI_TIME_POINT_AFTER_ALIVE: first cmd from host after alive notif
333  * @IWL_FW_INI_TIME_POINT_POST_INIT: last cmd in series of init sequence
334  * @IWL_FW_INI_TIME_POINT_FW_ASSERT: FW assert
335  * @IWL_FW_INI_TIME_POINT_FW_HW_ERROR: FW HW error
336  * @IWL_FW_INI_TIME_POINT_FW_TFD_Q_HANG: TFD queue hang
337  * @IWL_FW_INI_TIME_POINT_FW_DHC_NOTIFICATION: DHC cmd response and notif
338  * @IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF: FW response or notification.
339  *	data field holds id and group
340  * @IWL_FW_INI_TIME_POINT_USER_TRIGGER: user trigger time point
341  * @IWL_FW_INI_TIME_POINT_PERIODIC: periodic timepoint that fires in constant
342  *	intervals. data field holds the interval time in msec
343  * @IWL_FW_INI_TIME_POINT_RESERVED: reserved
344  * @IWL_FW_INI_TIME_POINT_HOST_ASSERT: Unused
345  * @IWL_FW_INI_TIME_POINT_HOST_ALIVE_TIMEOUT: alive timeout
346  * @IWL_FW_INI_TIME_POINT_HOST_DEVICE_ENABLE: device enable
347  * @IWL_FW_INI_TIME_POINT_HOST_DEVICE_DISABLE: device disable
348  * @IWL_FW_INI_TIME_POINT_HOST_D3_START: D3 start
349  * @IWL_FW_INI_TIME_POINT_HOST_D3_END: D3 end
350  * @IWL_FW_INI_TIME_POINT_MISSED_BEACONS: missed beacons
351  * @IWL_FW_INI_TIME_POINT_ASSOC_FAILED: association failure
352  * @IWL_FW_INI_TIME_POINT_TX_FAILED: Tx frame failed
353  * @IWL_FW_INI_TIME_POINT_TX_WFD_ACTION_FRAME_FAILED: wifi direct action
354  *	frame failed
355  * @IWL_FW_INI_TIME_POINT_TX_LATENCY_THRESHOLD: Tx latency threshold
356  * @IWL_FW_INI_TIME_POINT_HANG_OCCURRED: hang occurred
357  * @IWL_FW_INI_TIME_POINT_EAPOL_FAILED: EAPOL failed
358  * @IWL_FW_INI_TIME_POINT_FAKE_TX: fake Tx
359  * @IWL_FW_INI_TIME_POINT_DEASSOC: de association
360  * @IWL_FW_INI_TIME_POINT_NUM: number of time points
361  */
362 enum iwl_fw_ini_time_point {
363 	IWL_FW_INI_TIME_POINT_INVALID,
364 	IWL_FW_INI_TIME_POINT_EARLY,
365 	IWL_FW_INI_TIME_POINT_AFTER_ALIVE,
366 	IWL_FW_INI_TIME_POINT_POST_INIT,
367 	IWL_FW_INI_TIME_POINT_FW_ASSERT,
368 	IWL_FW_INI_TIME_POINT_FW_HW_ERROR,
369 	IWL_FW_INI_TIME_POINT_FW_TFD_Q_HANG,
370 	IWL_FW_INI_TIME_POINT_FW_DHC_NOTIFICATION,
371 	IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF,
372 	IWL_FW_INI_TIME_POINT_USER_TRIGGER,
373 	IWL_FW_INI_TIME_POINT_PERIODIC,
374 	IWL_FW_INI_TIME_POINT_RESERVED,
375 	IWL_FW_INI_TIME_POINT_HOST_ASSERT,
376 	IWL_FW_INI_TIME_POINT_HOST_ALIVE_TIMEOUT,
377 	IWL_FW_INI_TIME_POINT_HOST_DEVICE_ENABLE,
378 	IWL_FW_INI_TIME_POINT_HOST_DEVICE_DISABLE,
379 	IWL_FW_INI_TIME_POINT_HOST_D3_START,
380 	IWL_FW_INI_TIME_POINT_HOST_D3_END,
381 	IWL_FW_INI_TIME_POINT_MISSED_BEACONS,
382 	IWL_FW_INI_TIME_POINT_ASSOC_FAILED,
383 	IWL_FW_INI_TIME_POINT_TX_FAILED,
384 	IWL_FW_INI_TIME_POINT_TX_WFD_ACTION_FRAME_FAILED,
385 	IWL_FW_INI_TIME_POINT_TX_LATENCY_THRESHOLD,
386 	IWL_FW_INI_TIME_POINT_HANG_OCCURRED,
387 	IWL_FW_INI_TIME_POINT_EAPOL_FAILED,
388 	IWL_FW_INI_TIME_POINT_FAKE_TX,
389 	IWL_FW_INI_TIME_POINT_DEASSOC,
390 	IWL_FW_INI_TIME_POINT_NUM,
391 }; /* FW_TLV_DEBUG_TIME_POINT_API_E */
392 
393 /**
394  * enum iwl_fw_ini_trigger_apply_policy - Determines how to apply triggers
395  *
396  * @IWL_FW_INI_APPLY_POLICY_MATCH_TIME_POINT: match by time point
397  * @IWL_FW_INI_APPLY_POLICY_MATCH_DATA: match by trigger data
398  * @IWL_FW_INI_APPLY_POLICY_OVERRIDE_REGIONS: override regions mask.
399  *	Append otherwise
400  * @IWL_FW_INI_APPLY_POLICY_OVERRIDE_CFG: override trigger configuration
401  * @IWL_FW_INI_APPLY_POLICY_OVERRIDE_DATA: override trigger data.
402  *	Append otherwise
403  */
404 enum iwl_fw_ini_trigger_apply_policy {
405 	IWL_FW_INI_APPLY_POLICY_MATCH_TIME_POINT	= BIT(0),
406 	IWL_FW_INI_APPLY_POLICY_MATCH_DATA		= BIT(1),
407 	IWL_FW_INI_APPLY_POLICY_OVERRIDE_REGIONS	= BIT(8),
408 	IWL_FW_INI_APPLY_POLICY_OVERRIDE_CFG		= BIT(9),
409 	IWL_FW_INI_APPLY_POLICY_OVERRIDE_DATA		= BIT(10),
410 };
411 #endif
412