-
Notifications
You must be signed in to change notification settings - Fork 9
/
virtio_stor_hw_helper.h
executable file
·181 lines (158 loc) · 5.43 KB
/
virtio_stor_hw_helper.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* Virtio block device include module.
*
* Copyright (c) 2008-2017 Red Hat, Inc.
*
* Author(s):
* Vadim Rozenfeld <[email protected]>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met :
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of their contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef ___VIOSTOR_HW_HELPER_H___
#define ___VIOSTOR_HW_HELPER_H___
#include <ntddk.h>
#include <storport.h>
#include "osdep.h"
#include "virtio_pci.h"
#include "virtio.h"
#include "virtio_stor.h"
#include <srbhelper.h>
FORCEINLINE ULONG
SrbGetCdbLenght(_In_ PVOID Srb) {
ULONG CdbLen32 = 0;
UCHAR CdbLen8 = 0;
SrbGetScsiData(Srb, &CdbLen8, &CdbLen32, NULL, NULL, NULL);
return (CdbLen8 != 0) ? CdbLen8 : CdbLen32;
}
FORCEINLINE VOID
SrbGetPnpInfo(_In_ PVOID Srb, ULONG* PnPFlags, ULONG* PnPAction) {
PSCSI_PNP_REQUEST_BLOCK pPnpSrb = NULL;
PSRBEX_DATA_PNP pSrbExPnp = NULL;
pSrbExPnp = (PSRBEX_DATA_PNP)SrbGetSrbExDataByType(
(PSTORAGE_REQUEST_BLOCK)Srb, SrbExDataTypePnP);
if (pSrbExPnp != NULL) {
*PnPFlags = pSrbExPnp->SrbPnPFlags;
*PnPAction = pSrbExPnp->PnPAction;
}
else {
pPnpSrb = (PSCSI_PNP_REQUEST_BLOCK)Srb;
*PnPFlags = pPnpSrb->SrbPnPFlags;
*PnPAction = pPnpSrb->PnPAction;
}
}
#define PSRB_TYPE PSTORAGE_REQUEST_BLOCK
#define PSRB_WMI_DATA PSRBEX_DATA_WMI
#define PSTOR_DEVICE_CAPABILITIES_TYPE PSTOR_DEVICE_CAPABILITIES_EX
#define SRB_EXTENSION(Srb) SrbGetMiniportContext(Srb)
#define SRB_FUNCTION(Srb) SrbGetSrbFunction(Srb)
#define SRB_CDB(Srb) SrbGetCdb(Srb)
#define SRB_CDB_LENGTH(Srb) SrbGetCdbLenght(Srb)
#define SRB_FLAGS(Srb) SrbGetSrbFlags(Srb)
#define SRB_PATH_ID(Srb) SrbGetPathId(Srb)
#define SRB_TARGET_ID(Srb) SrbGetTargetId(Srb)
#define SRB_LUN(Srb) SrbGetLun(Srb)
#define SRB_DATA_BUFFER(Srb) SrbGetDataBuffer(Srb)
#define SRB_DATA_TRANSFER_LENGTH(Srb) SrbGetDataTransferLength(Srb)
#define SRB_LENGTH(Srb) SrbGetSrbLength(Srb)
#define SRB_WMI_DATA(Srb) (PSRBEX_DATA_WMI)SrbGetSrbExDataByType((PSTORAGE_REQUEST_BLOCK)Srb, SrbExDataTypeWmi)
#define SRB_PNP_DATA(Srb) (PSRBEX_DATA_PNP)SrbGetSrbExDataByType((PSTORAGE_REQUEST_BLOCK)Srb, SrbExDataTypePnP)
#define SRB_GET_SENSE_INFO(Srb, senseInfoBuffer, senseInfoBufferLen) SrbGetScsiData(Srb, NULL, NULL, NULL, &senseInfoBuffer, &senseInfoBufferLen)
#define SRB_GET_SENSE_INFO_BUFFER(Srb, senseInfoBuffer) senseInfoBuffer = SrbGetSenseInfoBuffer(Srb)
#define SRB_GET_SENSE_INFO_BUFFER_LENGTH(Srb, senseInfoBufferLength) senseInfoBufferLength = SrbGetSenseInfoBufferLength(Srb)
#define SRB_GET_PNP_INFO(Srb, PnPFlags, PnPAction) SrbGetPnpInfo(Srb, &PnPFlags, &PnPAction)
#define SRB_SET_SCSI_STATUS(Srb, status) SrbSetScsiData(Srb, NULL, NULL, &status, NULL, NULL)
#define SRB_SET_SRB_STATUS(Srb, status) SrbSetSrbStatus(Srb, status)
#define SRB_SET_DATA_TRANSFER_LENGTH(Srb, Len) SrbSetDataTransferLength(Srb, Len)
BOOLEAN
RhelDoReadWrite(
IN PVOID DeviceExtension,
IN PSRB_TYPE Srb
);
BOOLEAN
RhelDoFlush(
IN PVOID DeviceExtension,
IN PSRB_TYPE Srb,
IN BOOLEAN resend,
BOOLEAN bIsr
);
BOOLEAN
RhelDoUnMap(
IN PVOID DeviceExtension,
IN PSRB_TYPE Srb
);
VOID
RhelShutDown(
IN PVOID DeviceExtension
);
ULONGLONG
RhelGetLba(
IN PVOID DeviceExtension,
IN PCDB Cdb
);
ULONG
RhelGetSectors(
IN PVOID DeviceExtension,
IN PCDB Cdb
);
BOOLEAN
RhelGetSerialNumber(
IN PVOID DeviceExtension,
IN PSRB_TYPE Srb);
VOID
RhelGetDiskGeometry(
IN PVOID DeviceExtension
);
VOID
VioStorCompleteRequest(
IN PVOID DeviceExtension,
IN ULONG MessageID,
IN BOOLEAN bIsr
);
PVOID
VioStorPoolAlloc(
IN PVOID DeviceExtension,
IN SIZE_T size
);
VOID
VioStorVQLock(
IN PVOID DeviceExtension,
IN ULONG MessageID,
IN OUT PSTOR_LOCK_HANDLE LockHandle,
IN BOOLEAN isr
);
VOID
VioStorVQUnlock(
IN PVOID DeviceExtension,
IN ULONG MessageID,
IN PSTOR_LOCK_HANDLE LockHandle,
IN BOOLEAN isr
);
VOID
CompleteRequestWithStatus(
IN PVOID DeviceExtension,
IN PSRB_TYPE Srb,
IN UCHAR status
);
extern VirtIOSystemOps VioStorSystemOps;
#endif ___VIOSTOR_HW_HELPER_H___