1 /*
2  * This file contains definitions and data structures, common between
3  * NDIS driver and debugger helper unit, processing crash dump with built-in
4  * data provided by the driver.
5  *
6  * Included in NetKVM NDIS kernel driver for Windows.
7  * Included in NetKVMDumpParser application.
8  *
9  * Copyright (c) 2008-2017 Red Hat, Inc.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met :
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and / or other materials provided with the distribution.
19  * 3. Neither the names of the copyright holders nor the names of their contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 
35 #ifndef PARANDIS_DEBUG_DATA_H
36 #define PARANDIS_DEBUG_DATA_H
37 
38 typedef enum _etagHistoryLogOperation
39 {
40     hopPowerOff,                // common::PowerOff, 1/0 - entry/exit (none, entry, none, none)
41     hopPowerOn,                 // common::PowerOn, 1/0 - entry/exit (none, entry, none, none)
42     hopSysPause,                // ndis6::Pause, 1/0 - entry/completion
43     hopSysResume,               // ndis6::Restart, 1/0 - entry/completion
44     hopInternalSendPause,       // implementation, 1/0 - entry/completion
45     hopInternalReceivePause,    // implementation, 1/0 - entry/completion
46     hopInternalSendResume,      // implementation
47     hopInternalReceiveResume,   // implementation
48     hopSysReset,                // implementation driver, 1/0 - entry/completion
49     hopHalt,                    // implementation driver, 1/0 - entry/completion
50     hopConnectIndication,       // implementation
51     hopDPC,                     // common::DpcWorkBody (1, none, none, none) (0, left, free buffers, free desc)
52     hopSend,                    // implementation, when Send requested (nbl, nof lists, nof bufs, nof bytes) (packet, 1, nof packets, none)
53     hopSendNBLRequest,          // ndis6 implementation (nbl, nof packets, none, none)
54     hopSendPacketRequest,       // not used
55     hopSendPacketMapped,        // implementation, before the packet inserted into queue (nbl, which packet, nof frags, none)
56     hopSubmittedPacket,         // implementation, when the packet submitted (nbl, which packet, result, flags)
57     hopBufferSent,              // implementation, when the packet returned from VirtIO queue (nbl, packet no., free buf, free desc)
58     hopReceiveStat,             // common: RX (none, retrieved, reported, ready rx buffers)
59     hopBufferReturned,          // not used
60     hopSendComplete,            // implementation, when the packet completed
61     hopTxProcess,
62     hopPacketReceived,          // implementation, when the packet prepared for indication (nbl, length, prio tag, type)
63     hopOidRequest,              // implementation, none, OID, on entry(type, 1), on exit (status, 0), on complete (status, 2)
64     hopPnpEvent                 // common, none, event, 0, 0
65 }eHistoryLogOperation;
66 
67 // {E51FCE18-B3E7-441e-B18C-D9E9B71616F3}
68 static const GUID ParaNdis_CrashGuid =
69 { 0xe51fce18, 0xb3e7, 0x441e, { 0xb1, 0x8c, 0xd9, 0xe9, 0xb7, 0x16, 0x16, 0xf3 } };
70 
71 /* This structure is NOT changeable */
72 typedef struct _tagBugCheckStaticDataHeader
73 {
74     USHORT              SizeOfPointer;
75     USHORT              StaticDataVersion;
76     USHORT              PerNicDataVersion;
77     USHORT              ulMaxContexts;
78     LARGE_INTEGER       qCrashTime;
79     UINT64              PerNicData;
80     UINT64              DataArea;
81     UINT64              DataAreaSize;
82 }tBugCheckStaticDataHeader;
83 
84 /* This structure is NOT changeable */
85 typedef struct _tagBugCheckDataLocation
86 {
87     UINT64              Address;
88     UINT64              Size;
89 }tBugCheckDataLocation;
90 
91 #define PARANDIS_DEBUG_STATIC_DATA_VERSION          0
92 #define PARANDIS_DEBUG_PER_NIC_DATA_VERSION         0
93 #define PARANDIS_DEBUG_HISTORY_DATA_VERSION         1
94 /* This structure is NOT changeable */
95 typedef struct _tagBugCheckStaticDataContent_V0
96 {
97     ULONG               SizeOfHistory;
98     ULONG               SizeOfHistoryEntry;
99     LONG                CurrentHistoryIndex;
100     ULONG               HistoryDataVersion;
101     ULONG64             HistoryData;
102 }tBugCheckStaticDataContent_V0;
103 
104 #define PARANDIS_DEBUG_INTERRUPTS
105 
106 #ifdef PARANDIS_DEBUG_INTERRUPTS
107 #   define PARANDIS_STORE_LAST_INTERRUPT_TIMESTAMP(p) \
108         NdisGetCurrentSystemTime(&(p)->LastInterruptTimeStamp)
109 #   define PARANDIS_GET_LAST_INTERRUPT_TIMESTAMP(p) \
110         (p)->LastInterruptTimeStamp.QuadPart
111 #else
112 #   define PARANDIS_STORE_LAST_INTERRUPT_TIMESTAMP(p)
113 #   define PARANDIS_GET_LAST_INTERRUPT_TIMESTAMP(p) (0)
114 #endif
115 
116 typedef struct _tagBugCheckPerNicDataContent_V0
117 {
118     UINT64              Context;
119     LARGE_INTEGER       LastInterruptTimeStamp;
120     LARGE_INTEGER       LastTxCompletionTimeStamp;
121     ULONG               nofPacketsToComplete;
122     ULONG               nofReadyTxBuffers;
123 }tBugCheckPerNicDataContent_V0;
124 
125 typedef struct _tagBugCheckHistoryDataEntry_V0
126 {
127     LARGE_INTEGER       TimeStamp;
128     UINT64              Context;
129     UINT64              pParam1;
130     ULONG               operation;
131     ULONG               lParam2;
132     ULONG               lParam3;
133     ULONG               lParam4;
134 }tBugCheckHistoryDataEntry_V0;
135 
136 typedef struct _tagBugCheckHistoryDataEntry_V1
137 {
138     LARGE_INTEGER       TimeStamp;
139     UINT64              Context;
140     ULONG               uIRQL;
141     ULONG               uProcessor;
142     UINT64              pParam1;
143     ULONG               operation;
144     ULONG               lParam2;
145     ULONG               lParam3;
146     ULONG               lParam4;
147 }tBugCheckHistoryDataEntry_V1;
148 
149 
150 #if (PARANDIS_DEBUG_STATIC_DATA_VERSION == 0)
151 typedef tBugCheckStaticDataContent_V0 tBugCheckStaticDataContent;
152 #endif
153 
154 #if (PARANDIS_DEBUG_PER_NIC_DATA_VERSION == 0)
155 typedef tBugCheckPerNicDataContent_V0 tBugCheckPerNicDataContent;
156 #endif
157 
158 #if (PARANDIS_DEBUG_HISTORY_DATA_VERSION == 0)
159 typedef tBugCheckHistoryDataEntry_V0 tBugCheckHistoryDataEntry;
160 #elif (PARANDIS_DEBUG_HISTORY_DATA_VERSION == 1)
161 typedef tBugCheckHistoryDataEntry_V1 tBugCheckHistoryDataEntry;
162 #endif
163 
164 typedef struct _tagBugCheckStaticDataContent_V1
165 {
166     UINT64              res1;
167     UINT64              res2;
168     UINT64              History;
169 }tBugCheckStaticDataContent_V1;
170 
171 typedef struct _tagBugCheckPerNicDataContent_V1
172 {
173     UINT64              Context;
174     LARGE_INTEGER       LastInterruptTimeStamp;
175     LARGE_INTEGER       LastTxCompletionTimeStamp;
176     ULONG               nofPacketsToComplete;
177     ULONG               nofReadyTxBuffers;
178 }tBugCheckPerNicDataContent_V1;
179 
180 
181 #if (PARANDIS_DEBUG_HEADER_VERSION == 1)
182 typedef tBugCheckStaticDataContent_V1 tBugCheckStaticDataContent;
183 #endif
184 
185 #if (PARANDIS_DEBUG_PER_NIC_DATA_VERSION == 1)
186 typedef tBugCheckPerNicDataContent_V1 tBugCheckPerNicDataContent;
187 #endif
188 
189 // etc
190 
191 
192 
193 #endif
194