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