win-pvdrivers

view xenvbd/xenvbd_storport.h @ 1002:c454b24f92b8

testing UNMAP
author James Harper <james.harper@bendigoit.com.au>
date Fri Dec 14 21:27:05 2012 +1100 (2012-12-14)
parents aefd5458e6c3
children a5d1d333e0e2
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2007 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #if !defined(_XENVBD_H_)
21 #define _XENVBD_H_
23 #include <ntddk.h>
24 #include <wdm.h>
25 #include <initguid.h>
26 #define NTSTRSAFE_LIB
27 #include <ntstrsafe.h>
28 #include <storport.h>
29 #include <ntddscsi.h>
30 #include <ntdddisk.h>
31 #include <stdlib.h>
33 #define __DRIVER_NAME "XenVbd"
35 #include <xen_windows.h>
36 #include <xen_public.h>
37 #include <io/protocols.h>
38 #include <memory.h>
39 #include <event_channel.h>
40 #include <hvm/params.h>
41 #include <hvm/hvm_op.h>
42 #include <io/ring.h>
43 #include <io/blkif.h>
44 #include <io/xenbus.h>
46 #define XENVBD_POOL_TAG (ULONG) 'XVBD'
48 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
49 #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
50 #define BLK_OTHER_RING_SIZE __RING_SIZE((blkif_other_sring_t *)0, PAGE_SIZE)
52 #define SCSIOP_UNMAP 0x42
54 #define VPD_BLOCK_LIMITS 0xB0
56 #if defined(__x86_64__)
57 #pragma pack(push, 4)
58 #endif
59 struct blkif_other_request {
60 uint8_t operation;
61 uint8_t nr_segments;
62 blkif_vdev_t handle;
63 uint64_t id;
64 blkif_sector_t sector_number;
65 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
66 };
67 struct blkif_other_response {
68 uint64_t id;
69 uint8_t operation;
70 int16_t status;
71 };
72 #if defined(__x86_64__)
73 #pragma pack(pop)
74 #endif
76 typedef struct blkif_other_request blkif_other_request_t;
77 typedef struct blkif_other_response blkif_other_response_t;
78 DEFINE_RING_TYPES(blkif_other, struct blkif_other_request, struct blkif_other_response);
80 typedef struct {
81 LIST_ENTRY list_entry;
82 PSCSI_REQUEST_BLOCK srb;
83 ULONG length; /* cached srb length */
84 ULONG offset; /* current srb offset */
85 ULONG outstanding_requests; /* number of requests sent to xen for this srb */
86 BOOLEAN error; /* true if any sub requests have returned an error */
87 } srb_list_entry_t;
89 typedef struct {
90 blkif_request_t req;
91 srb_list_entry_t *srb_list_entry;
92 PSCSI_REQUEST_BLOCK srb;
93 PVOID system_address;
94 ULONG length;
95 BOOLEAN aligned_buffer_in_use;
96 BOOLEAN reset;
97 #if DBG && NTDDI_VERSION >= NTDDI_WINXP
98 LARGE_INTEGER ring_submit_time;
99 #endif
100 } blkif_shadow_t;
102 #define MAX_SHADOW_ENTRIES 64
103 #define SHADOW_ID_ID_MASK 0x03FF /* maximum of 1024 requests - currently use a maximum of 64 though */
104 #define SHADOW_ID_DUMP_FLAG 0x8000 /* indicates the request was generated by dump mode */
106 #define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, min(BLK_RING_SIZE, BLK_OTHER_RING_SIZE))
108 typedef enum {
109 XENVBD_DEVICETYPE_UNKNOWN,
110 XENVBD_DEVICETYPE_DISK,
111 XENVBD_DEVICETYPE_CDROM,
112 XENVBD_DEVICETYPE_CONTROLLER // Not yet used
113 } XENVBD_DEVICETYPE;
115 typedef enum {
116 XENVBD_DEVICEMODE_UNKNOWN,
117 XENVBD_DEVICEMODE_READ,
118 XENVBD_DEVICEMODE_WRITE
119 } XENVBD_DEVICEMODE;
121 #define RING_DETECT_STATE_NOT_STARTED 0
122 #define RING_DETECT_STATE_DETECT1 1
123 #define RING_DETECT_STATE_DETECT2 2
124 #define RING_DETECT_STATE_COMPLETE 3
126 /* if this is ever increased to more than 1 then we need a way of tracking it properly */
127 #define DUMP_MODE_UNALIGNED_PAGES 1 /* only for unaligned buffer use */
129 struct
130 {
131 BOOLEAN inactive;
133 blkif_shadow_t shadows[MAX_SHADOW_ENTRIES];
134 USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
135 USHORT shadow_free;
136 USHORT shadow_min_free;
137 ULONG grant_tag;
139 PUCHAR device_base;
141 blkif_sring_t *sring;
142 evtchn_port_t event_channel;
143 ULONG *event_channel_ptr;
144 union {
145 blkif_front_ring_t ring;
146 blkif_other_front_ring_t other_ring;
147 };
148 int ring_detect_state;
149 BOOLEAN use_other;
150 BOOLEAN cached_use_other;
151 UCHAR last_sense_key;
152 UCHAR last_additional_sense_code;
153 blkif_response_t tmp_rep;
154 XENVBD_DEVICETYPE device_type;
155 XENVBD_DEVICEMODE device_mode;
156 ULONG bytes_per_sector; /* 512 for disk, 2048 for CDROM) */
157 ULONG hw_bytes_per_sector; /* underlying hardware format, eg 4K */
158 ULONGLONG total_sectors;
159 XENPCI_VECTORS vectors;
160 PXENPCI_DEVICE_STATE device_state;
161 LIST_ENTRY srb_list;
162 BOOLEAN aligned_buffer_in_use;
163 ULONG aligned_buffer_size;
164 PVOID aligned_buffer;
165 /*
166 ULONGLONG interrupts;
167 ULONGLONG aligned_requests;
168 ULONGLONG aligned_bytes;
169 ULONGLONG unaligned_requests;
170 ULONGLONG unaligned_bytes;
171 */
172 /* this is the size of the buffer to allocate at the end of DeviceExtenstion. It includes an extra PAGE_SIZE-1 bytes to assure that we can always align to PAGE_SIZE */
173 #define UNALIGNED_BUFFER_DATA_SIZE ((BLKIF_MAX_SEGMENTS_PER_REQUEST + 1) * PAGE_SIZE - 1)
174 #define UNALIGNED_BUFFER_DATA_SIZE_DUMP_MODE ((DUMP_MODE_UNALIGNED_PAGES + 1) * PAGE_SIZE - 1)
175 /* this has to be right at the end of DeviceExtension */
176 /* can't allocate too much data in dump mode so size DeviceExtensionSize accordingly */
177 UCHAR aligned_buffer_data[1];
178 } typedef XENVBD_DEVICE_DATA, *PXENVBD_DEVICE_DATA;
180 #endif