1 /*
2  *  Copyright (C) 2017 Chelsio Communications.  All rights reserved.
3  *
4  *  This program is free software; you can redistribute it and/or modify it
5  *  under the terms and conditions of the GNU General Public License,
6  *  version 2, as published by the Free Software Foundation.
7  *
8  *  This program is distributed in the hope it will be useful, but WITHOUT
9  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11  *  more details.
12  *
13  *  The full GNU General Public License is included in this distribution in
14  *  the file called "COPYING".
15  *
16  */
17 
18 #ifndef __CUDBG_LIB_COMMON_H__
19 #define __CUDBG_LIB_COMMON_H__
20 
21 #define CUDBG_SIGNATURE 67856866 /* CUDB in ascii */
22 
23 enum cudbg_dump_type {
24 	CUDBG_DUMP_TYPE_MINI = 1,
25 };
26 
27 enum cudbg_compression_type {
28 	CUDBG_COMPRESSION_NONE = 1,
29 };
30 
31 struct cudbg_hdr {
32 	u32 signature;
33 	u32 hdr_len;
34 	u16 major_ver;
35 	u16 minor_ver;
36 	u32 data_len;
37 	u32 hdr_flags;
38 	u16 max_entities;
39 	u8 chip_ver;
40 	u8 dump_type:3;
41 	u8 reserved1:1;
42 	u8 compress_type:4;
43 	u32 reserved[8];
44 };
45 
46 struct cudbg_entity_hdr {
47 	u32 entity_type;
48 	u32 start_offset;
49 	u32 size;
50 	int hdr_flags;
51 	u32 sys_warn;
52 	u32 sys_err;
53 	u8 num_pad;
54 	u8 flag;             /* bit 0 is used to indicate ext data */
55 	u8 reserved1[2];
56 	u32 next_ext_offset; /* pointer to next extended entity meta data */
57 	u32 reserved[5];
58 };
59 
60 struct cudbg_ver_hdr {
61 	u32 signature;
62 	u16 revision;
63 	u16 size;
64 };
65 
66 struct cudbg_buffer {
67 	u32 size;
68 	u32 offset;
69 	char *data;
70 };
71 
72 struct cudbg_error {
73 	int sys_err;
74 	int sys_warn;
75 	int app_err;
76 };
77 
78 #define CDUMP_MAX_COMP_BUF_SIZE ((64 * 1024) - 1)
79 #define CUDBG_CHUNK_SIZE ((CDUMP_MAX_COMP_BUF_SIZE / 1024) * 1024)
80 
81 int cudbg_get_buff(struct cudbg_buffer *pdbg_buff, u32 size,
82 		   struct cudbg_buffer *pin_buff);
83 void cudbg_put_buff(struct cudbg_buffer *pin_buff,
84 		    struct cudbg_buffer *pdbg_buff);
85 void cudbg_update_buff(struct cudbg_buffer *pin_buff,
86 		       struct cudbg_buffer *pout_buff);
87 #endif /* __CUDBG_LIB_COMMON_H__ */
88