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) 2014 Intel Corporation. All rights reserved.
9  * Copyright(c) 2014 - 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  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24  * USA
25  *
26  * The full GNU General Public License is included in this distribution
27  * in the file called COPYING.
28  *
29  * Contact Information:
30  *  Intel Linux Wireless <linuxwifi@intel.com>
31  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32  *
33  * BSD LICENSE
34  *
35  * Copyright(c) 2014 Intel Corporation. All rights reserved.
36  * Copyright(c) 2014 - 2015 Intel Mobile Communications GmbH
37  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
38  * All rights reserved.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  *
44  *  * Redistributions of source code must retain the above copyright
45  *    notice, this list of conditions and the following disclaimer.
46  *  * Redistributions in binary form must reproduce the above copyright
47  *    notice, this list of conditions and the following disclaimer in
48  *    the documentation and/or other materials provided with the
49  *    distribution.
50  *  * Neither the name Intel Corporation nor the names of its
51  *    contributors may be used to endorse or promote products derived
52  *    from this software without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65  *****************************************************************************/
66 
67 #ifndef __fw_error_dump_h__
68 #define __fw_error_dump_h__
69 
70 #include <linux/types.h>
71 
72 #define IWL_FW_ERROR_DUMP_BARKER	0x14789632
73 
74 /**
75  * enum iwl_fw_error_dump_type - types of data in the dump file
76  * @IWL_FW_ERROR_DUMP_CSR: Control Status Registers - from offset 0
77  * @IWL_FW_ERROR_DUMP_RXF:
78  * @IWL_FW_ERROR_DUMP_TXCMD: last TX command data, structured as
79  *	&struct iwl_fw_error_dump_txcmd packets
80  * @IWL_FW_ERROR_DUMP_DEV_FW_INFO:  struct %iwl_fw_error_dump_info
81  *	info on the device / firmware.
82  * @IWL_FW_ERROR_DUMP_FW_MONITOR: firmware monitor
83  * @IWL_FW_ERROR_DUMP_PRPH: range of periphery registers - there can be several
84  *	sections like this in a single file.
85  * @IWL_FW_ERROR_DUMP_FH_REGS: range of FH registers
86  * @IWL_FW_ERROR_DUMP_MEM: chunk of memory
87  * @IWL_FW_ERROR_DUMP_ERROR_INFO: description of what triggered this dump.
88  *	Structured as &struct iwl_fw_error_dump_trigger_desc.
89  * @IWL_FW_ERROR_DUMP_RB: the content of an RB structured as
90  *	&struct iwl_fw_error_dump_rb
91  * @IWL_FW_ERROR_PAGING: UMAC's image memory segments which were
92  *	paged to the DRAM.
93  * @IWL_FW_ERROR_DUMP_RADIO_REG: Dump the radio registers.
94  * @IWL_FW_ERROR_DUMP_EXTERNAL: used only by external code utilities, and
95  *	for that reason is not in use in any other place in the Linux Wi-Fi
96  *	stack.
97  * @IWL_FW_ERROR_DUMP_MEM_CFG: the addresses and sizes of fifos in the smem,
98  *	which we get from the fw after ALIVE. The content is structured as
99  *	&struct iwl_fw_error_dump_smem_cfg.
100  */
101 enum iwl_fw_error_dump_type {
102 	/* 0 is deprecated */
103 	IWL_FW_ERROR_DUMP_CSR = 1,
104 	IWL_FW_ERROR_DUMP_RXF = 2,
105 	IWL_FW_ERROR_DUMP_TXCMD = 3,
106 	IWL_FW_ERROR_DUMP_DEV_FW_INFO = 4,
107 	IWL_FW_ERROR_DUMP_FW_MONITOR = 5,
108 	IWL_FW_ERROR_DUMP_PRPH = 6,
109 	IWL_FW_ERROR_DUMP_TXF = 7,
110 	IWL_FW_ERROR_DUMP_FH_REGS = 8,
111 	IWL_FW_ERROR_DUMP_MEM = 9,
112 	IWL_FW_ERROR_DUMP_ERROR_INFO = 10,
113 	IWL_FW_ERROR_DUMP_RB = 11,
114 	IWL_FW_ERROR_DUMP_PAGING = 12,
115 	IWL_FW_ERROR_DUMP_RADIO_REG = 13,
116 	IWL_FW_ERROR_DUMP_INTERNAL_TXF = 14,
117 	IWL_FW_ERROR_DUMP_EXTERNAL = 15, /* Do not move */
118 	IWL_FW_ERROR_DUMP_MEM_CFG = 16,
119 
120 	IWL_FW_ERROR_DUMP_MAX,
121 };
122 
123 /**
124  * struct iwl_fw_error_dump_data - data for one type
125  * @type: &enum iwl_fw_error_dump_type
126  * @len: the length starting from %data
127  * @data: the data itself
128  */
129 struct iwl_fw_error_dump_data {
130 	__le32 type;
131 	__le32 len;
132 	__u8 data[];
133 } __packed;
134 
135 /**
136  * struct iwl_fw_error_dump_file - the layout of the header of the file
137  * @barker: must be %IWL_FW_ERROR_DUMP_BARKER
138  * @file_len: the length of all the file starting from %barker
139  * @data: array of &struct iwl_fw_error_dump_data
140  */
141 struct iwl_fw_error_dump_file {
142 	__le32 barker;
143 	__le32 file_len;
144 	u8 data[0];
145 } __packed;
146 
147 /**
148  * struct iwl_fw_error_dump_txcmd - TX command data
149  * @cmdlen: original length of command
150  * @caplen: captured length of command (may be less)
151  * @data: captured command data, @caplen bytes
152  */
153 struct iwl_fw_error_dump_txcmd {
154 	__le32 cmdlen;
155 	__le32 caplen;
156 	u8 data[];
157 } __packed;
158 
159 /**
160  * struct iwl_fw_error_dump_fifo - RX/TX FIFO data
161  * @fifo_num: number of FIFO (starting from 0)
162  * @available_bytes: num of bytes available in FIFO (may be less than FIFO size)
163  * @wr_ptr: position of write pointer
164  * @rd_ptr: position of read pointer
165  * @fence_ptr: position of fence pointer
166  * @fence_mode: the current mode of the fence (before locking) -
167  *	0=follow RD pointer ; 1 = freeze
168  * @data: all of the FIFO's data
169  */
170 struct iwl_fw_error_dump_fifo {
171 	__le32 fifo_num;
172 	__le32 available_bytes;
173 	__le32 wr_ptr;
174 	__le32 rd_ptr;
175 	__le32 fence_ptr;
176 	__le32 fence_mode;
177 	u8 data[];
178 } __packed;
179 
180 enum iwl_fw_error_dump_family {
181 	IWL_FW_ERROR_DUMP_FAMILY_7 = 7,
182 	IWL_FW_ERROR_DUMP_FAMILY_8 = 8,
183 };
184 
185 /**
186  * struct iwl_fw_error_dump_info - info on the device / firmware
187  * @device_family: the family of the device (7 / 8)
188  * @hw_step: the step of the device
189  * @fw_human_readable: human readable FW version
190  * @dev_human_readable: name of the device
191  * @bus_human_readable: name of the bus used
192  */
193 struct iwl_fw_error_dump_info {
194 	__le32 device_family;
195 	__le32 hw_step;
196 	u8 fw_human_readable[FW_VER_HUMAN_READABLE_SZ];
197 	u8 dev_human_readable[64];
198 	u8 bus_human_readable[8];
199 } __packed;
200 
201 /**
202  * struct iwl_fw_error_dump_fw_mon - FW monitor data
203  * @fw_mon_wr_ptr: the position of the write pointer in the cyclic buffer
204  * @fw_mon_base_ptr: base pointer of the data
205  * @fw_mon_cycle_cnt: number of wraparounds
206  * @reserved: for future use
207  * @data: captured data
208  */
209 struct iwl_fw_error_dump_fw_mon {
210 	__le32 fw_mon_wr_ptr;
211 	__le32 fw_mon_base_ptr;
212 	__le32 fw_mon_cycle_cnt;
213 	__le32 reserved[3];
214 	u8 data[];
215 } __packed;
216 
217 #define MAX_NUM_LMAC 2
218 #define TX_FIFO_INTERNAL_MAX_NUM	6
219 #define TX_FIFO_MAX_NUM			15
220 /**
221  * struct iwl_fw_error_dump_smem_cfg - Dump SMEM configuration
222  *	This must follow &struct iwl_fwrt_shared_mem_cfg.
223  * @num_lmacs: number of lmacs
224  * @num_txfifo_entries: number of tx fifos
225  * @lmac: sizes of lmacs txfifos and rxfifo1
226  * @rxfifo2_size: size of rxfifo2
227  * @internal_txfifo_addr: address of internal tx fifo
228  * @internal_txfifo_size: size of internal tx fifo
229  */
230 struct iwl_fw_error_dump_smem_cfg {
231 	__le32 num_lmacs;
232 	__le32 num_txfifo_entries;
233 	struct {
234 		__le32 txfifo_size[TX_FIFO_MAX_NUM];
235 		__le32 rxfifo1_size;
236 	} lmac[MAX_NUM_LMAC];
237 	__le32 rxfifo2_size;
238 	__le32 internal_txfifo_addr;
239 	__le32 internal_txfifo_size[TX_FIFO_INTERNAL_MAX_NUM];
240 } __packed;
241 /**
242  * struct iwl_fw_error_dump_prph - periphery registers data
243  * @prph_start: address of the first register in this chunk
244  * @data: the content of the registers
245  */
246 struct iwl_fw_error_dump_prph {
247 	__le32 prph_start;
248 	__le32 data[];
249 };
250 
251 enum iwl_fw_error_dump_mem_type {
252 	IWL_FW_ERROR_DUMP_MEM_SRAM,
253 	IWL_FW_ERROR_DUMP_MEM_SMEM,
254 };
255 
256 /**
257  * struct iwl_fw_error_dump_mem - chunk of memory
258  * @type: &enum iwl_fw_error_dump_mem_type
259  * @offset: the offset from which the memory was read
260  * @data: the content of the memory
261  */
262 struct iwl_fw_error_dump_mem {
263 	__le32 type;
264 	__le32 offset;
265 	u8 data[];
266 };
267 
268 /**
269  * struct iwl_fw_error_dump_rb - content of an Receive Buffer
270  * @index: the index of the Receive Buffer in the Rx queue
271  * @rxq: the RB's Rx queue
272  * @reserved:
273  * @data: the content of the Receive Buffer
274  */
275 struct iwl_fw_error_dump_rb {
276 	__le32 index;
277 	__le32 rxq;
278 	__le32 reserved;
279 	u8 data[];
280 };
281 
282 /**
283  * struct iwl_fw_error_dump_paging - content of the UMAC's image page
284  *	block on DRAM
285  * @index: the index of the page block
286  * @reserved:
287  * @data: the content of the page block
288  */
289 struct iwl_fw_error_dump_paging {
290 	__le32 index;
291 	__le32 reserved;
292 	u8 data[];
293 };
294 
295 /**
296  * iwl_fw_error_next_data - advance fw error dump data pointer
297  * @data: previous data block
298  * Returns: next data block
299  */
300 static inline struct iwl_fw_error_dump_data *
301 iwl_fw_error_next_data(struct iwl_fw_error_dump_data *data)
302 {
303 	return (void *)(data->data + le32_to_cpu(data->len));
304 }
305 
306 /**
307  * enum iwl_fw_dbg_trigger - triggers available
308  *
309  * @FW_DBG_TRIGGER_USER: trigger log collection by user
310  *	This should not be defined as a trigger to the driver, but a value the
311  *	driver should set to indicate that the trigger was initiated by the
312  *	user.
313  * @FW_DBG_TRIGGER_FW_ASSERT: trigger log collection when the firmware asserts
314  * @FW_DBG_TRIGGER_MISSED_BEACONS: trigger log collection when beacons are
315  *	missed.
316  * @FW_DBG_TRIGGER_CHANNEL_SWITCH: trigger log collection upon channel switch.
317  * @FW_DBG_TRIGGER_FW_NOTIF: trigger log collection when the firmware sends a
318  *	command response or a notification.
319  * @FW_DBG_TRIGGER_MLME: trigger log collection upon MLME event.
320  * @FW_DBG_TRIGGER_STATS: trigger log collection upon statistics threshold.
321  * @FW_DBG_TRIGGER_RSSI: trigger log collection when the rssi of the beacon
322  *	goes below a threshold.
323  * @FW_DBG_TRIGGER_TXQ_TIMERS: configures the timers for the Tx queue hang
324  *	detection.
325  * @FW_DBG_TRIGGER_TIME_EVENT: trigger log collection upon time events related
326  *	events.
327  * @FW_DBG_TRIGGER_BA: trigger log collection upon BlockAck related events.
328  * @FW_DBG_TX_LATENCY: trigger log collection when the tx latency goes above a
329  *	threshold.
330  * @FW_DBG_TDLS: trigger log collection upon TDLS related events.
331  * @FW_DBG_TRIGGER_TX_STATUS: trigger log collection upon tx status when
332  *  the firmware sends a tx reply.
333  */
334 enum iwl_fw_dbg_trigger {
335 	FW_DBG_TRIGGER_INVALID = 0,
336 	FW_DBG_TRIGGER_USER,
337 	FW_DBG_TRIGGER_FW_ASSERT,
338 	FW_DBG_TRIGGER_MISSED_BEACONS,
339 	FW_DBG_TRIGGER_CHANNEL_SWITCH,
340 	FW_DBG_TRIGGER_FW_NOTIF,
341 	FW_DBG_TRIGGER_MLME,
342 	FW_DBG_TRIGGER_STATS,
343 	FW_DBG_TRIGGER_RSSI,
344 	FW_DBG_TRIGGER_TXQ_TIMERS,
345 	FW_DBG_TRIGGER_TIME_EVENT,
346 	FW_DBG_TRIGGER_BA,
347 	FW_DBG_TRIGGER_TX_LATENCY,
348 	FW_DBG_TRIGGER_TDLS,
349 	FW_DBG_TRIGGER_TX_STATUS,
350 
351 	/* must be last */
352 	FW_DBG_TRIGGER_MAX,
353 };
354 
355 /**
356  * struct iwl_fw_error_dump_trigger_desc - describes the trigger condition
357  * @type: &enum iwl_fw_dbg_trigger
358  * @data: raw data about what happened
359  */
360 struct iwl_fw_error_dump_trigger_desc {
361 	__le32 type;
362 	u8 data[];
363 };
364 
365 #endif /* __fw_error_dump_h__ */
366