xref: /freebsd/sys/dev/cxgbe/cudbg/cudbg_lib_common.h (revision c7b2e390de43bb2b1a5918a23310ec5464ee3787)
1 /*-
2  * Copyright (c) 2017 Chelsio Communications, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27 
28 #ifndef __CUDBG_LIB_COMMON_H__
29 #define __CUDBG_LIB_COMMON_H__
30 
31 /* Extended entity
32  *
33  * Layout of the cudbg dump file when extended entity is present.
34  *
35  *
36  *           ----------------
37  *           | Global header |
38  *           |---------------|
39  *           |entity headers |
40  *           |---------------|
41  *           | Entity data   |
42  *           |      *        |
43  *           |      *        |
44  *           |      *        |
45  *           |---------------|
46  *           |extended entity|
47  *           |    header     |
48  *           |---------------|
49  *           |extended entity|
50  *           |     data      |
51  *           -----------------
52  *
53  *
54  * Extended entity: This comes into picture only when cudbg_collect() is called
55  * multiple times.
56  */
57 
58 #ifndef CUDBG_LITE
59 #include "common/t4_hw.h"
60 #endif
61 
62 #define CUDBG_EXT_DATA_BIT          0
63 #define CUDBG_EXT_DATA_VALID        (1 << CUDBG_EXT_DATA_BIT)
64 
65 struct cudbg_hdr {
66 	u32 signature;
67 	u32 hdr_len;
68 	u16 major_ver;
69 	u16 minor_ver;
70 	u32 data_len;
71 	u32 hdr_flags;
72 	u16 max_entities;
73 	u8 chip_ver;
74 	u8 reserved1;
75 	u32 reserved[8];
76 };
77 
78 struct cudbg_entity_hdr {
79 	u32 entity_type;
80 	u32 start_offset;
81 	u32 size;
82 	int hdr_flags;
83 	u32 sys_warn;
84 	u32 sys_err;
85 	u8 num_pad;
86 	u8 flag;		/* bit 0 is used to indicate ext data */
87 	u8 reserved1[2];
88 	u32 next_ext_offset;	/* pointer to next extended entity meta data */
89 	u32 reserved[5];
90 };
91 
92 struct cudbg_ver_hdr {
93 	u32 signature;
94 	u16 revision;
95 	u16 size;
96 };
97 
98 struct cudbg_buffer {
99 	u32 size;
100 	u32 offset;
101 	char *data;
102 };
103 
104 struct cudbg_error {
105 	int sys_err;
106 	int sys_warn;
107 	int app_err;
108 };
109 
110 struct cudbg_flash_sec_info {
111 	int par_sec;		   /* Represent partially filled sector no */
112 	int par_sec_offset;	   /* Offset in partially filled sector */
113 	int cur_seq_no;
114 	u32 max_seq_no;
115 	u32 max_seq_sec;
116 	u32 hdr_data_len;	   /* Total data */
117 	u32 skip_size;		   /* Total size of large entities. */
118 	u64 max_timestamp;
119 	char sec_data[SF_SEC_SIZE];
120 	u8 sec_bitmap[8];
121 };
122 
123 struct cudbg_private {
124 	struct cudbg_init  dbg_init;
125 	struct cudbg_flash_sec_info  sec_info;
126 };
127 
128 #define HTONL_NIBBLE(data) ( \
129 			    (((uint32_t)(data) >> 28) & 0x0000000F) | \
130 			    (((uint32_t)(data) >> 20)  & 0x000000F0) | \
131 			    (((uint32_t)(data) >> 12)  & 0x00000F00) | \
132 			    (((uint32_t)(data) >> 4) & 0x0000F000) | \
133 			    (((uint32_t)(data) << 4) & 0x000F0000) | \
134 			    (((uint32_t)(data) << 12)  & 0x00F00000) | \
135 			    (((uint32_t)(data) << 20)  & 0x0F000000) | \
136 			    (((uint32_t)(data) << 28) & 0xF0000000))
137 
138 #define CDUMP_MAX_COMP_BUF_SIZE    ((64 * 1024) - 1)
139 #define CUDBG_CHUNK_SIZE  ((CDUMP_MAX_COMP_BUF_SIZE/1024) * 1024)
140 
141 #define CUDBG_LEGACY_SIGNATURE 123
142 #define CUDBG_SIGNATURE 67856866 /* CUDB in ascii */
143 #define CUDBG_FL_SIGNATURE 0x4355464c /* CUFL in ascii */
144 
145 #define CUDBG_FL_MAJOR_VERSION	    1
146 #define CUDBG_FL_MINOR_VERSION	    1
147 #define CUDBG_FL_BUILD_VERSION	    0
148 
149 void update_skip_size(struct cudbg_flash_sec_info *, u32);
150 int write_compression_hdr(struct cudbg_buffer *, struct cudbg_buffer *);
151 int compress_buff(struct cudbg_buffer *, struct cudbg_buffer *);
152 int get_scratch_buff(struct cudbg_buffer *, u32, struct cudbg_buffer *);
153 void release_scratch_buff(struct cudbg_buffer *, struct cudbg_buffer *);
154 int decompress_buffer(struct cudbg_buffer *, struct cudbg_buffer *);
155 int validate_buffer(struct cudbg_buffer *compressed_buffer);
156 int decompress_buffer_wrapper(struct cudbg_buffer *pc_buff,
157 			      struct cudbg_buffer *pdc_buff);
158 int get_entity_rev(struct cudbg_ver_hdr *ver_hdr);
159 void sort_t(void *base, int num, int size,
160 	    int (*cmp_func)(const void *, const void *),
161 	    void (*swap_func)(void *, void *, int size));
162 int cudbg_read_flash(void *handle, void *data, u32 size, int data_flag);
163 int cudbg_write_flash(void *handle, u64 timestamp, void *data,
164 		      u32 start_offset, u32 start_hdr_offset,
165 		      u32 cur_entity_size,
166 		      u32 ext_size);
167 #endif
168