win-pvdrivers

view xenvbd/xenvbd_storport.h @ 841:2f4e64007b0f

Hibernation and suspend/resume fixes.
Storport now handles large requests and breaks them up
author James Harper <james.harper@bendigoit.com.au>
date Sat Feb 05 17:32:12 2011 +1100 (2011-02-05)
parents d0130ea66500
children 4b8b40cda748
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 #if defined(__x86_64__)
53 #pragma pack(push, 4)
54 #endif
55 struct blkif_other_request {
56 uint8_t operation;
57 uint8_t nr_segments;
58 blkif_vdev_t handle;
59 uint64_t id;
60 blkif_sector_t sector_number;
61 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
62 };
63 struct blkif_other_response {
64 uint64_t id;
65 uint8_t operation;
66 int16_t status;
67 };
68 #if defined(__x86_64__)
69 #pragma pack(pop)
70 #endif
72 typedef struct blkif_other_request blkif_other_request_t;
73 typedef struct blkif_other_response blkif_other_response_t;
74 DEFINE_RING_TYPES(blkif_other, struct blkif_other_request, struct blkif_other_response);
76 typedef struct {
77 LIST_ENTRY list_entry;
78 PSCSI_REQUEST_BLOCK srb;
79 ULONG length; /* cached srb length */
80 ULONG offset; /* current srb offset */
81 ULONG outstanding_requests; /* number of requests sent to xen for this srb */
82 BOOLEAN error; /* true if any sub requests have returned an error */
83 } srb_list_entry_t;
85 typedef struct {
86 blkif_request_t req;
87 srb_list_entry_t *srb_list_entry;
88 PSCSI_REQUEST_BLOCK srb;
89 PVOID system_address;
90 ULONG length;
91 BOOLEAN aligned_buffer_in_use;
92 } blkif_shadow_t;
94 #define MAX_SHADOW_ENTRIES 64
95 #define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, min(BLK_RING_SIZE, BLK_OTHER_RING_SIZE))
97 typedef enum {
98 XENVBD_DEVICETYPE_UNKNOWN,
99 XENVBD_DEVICETYPE_DISK,
100 XENVBD_DEVICETYPE_CDROM,
101 XENVBD_DEVICETYPE_CONTROLLER // Not yet used
102 } XENVBD_DEVICETYPE;
104 typedef enum {
105 XENVBD_DEVICEMODE_UNKNOWN,
106 XENVBD_DEVICEMODE_READ,
107 XENVBD_DEVICEMODE_WRITE
108 } XENVBD_DEVICEMODE;
110 #define RING_DETECT_STATE_NOT_STARTED 0
111 #define RING_DETECT_STATE_DETECT1 1
112 #define RING_DETECT_STATE_DETECT2 2
113 #define RING_DETECT_STATE_COMPLETE 3
115 /* if this is ever increased to more than 1 then we need a way of tracking it properly */
116 #define DUMP_MODE_UNALIGNED_PAGES 1 /* only for unaligned buffer use */
118 struct
119 {
120 BOOLEAN inactive;
122 blkif_shadow_t shadows[MAX_SHADOW_ENTRIES];
123 USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
124 USHORT shadow_free;
125 USHORT shadow_min_free;
126 ULONG grant_tag;
128 PUCHAR device_base;
130 blkif_sring_t *sring;
131 evtchn_port_t event_channel;
132 ULONG *event_channel_ptr;
133 union {
134 blkif_front_ring_t ring;
135 blkif_other_front_ring_t other_ring;
136 };
137 int ring_detect_state;
138 BOOLEAN use_other;
139 BOOLEAN cached_use_other;
140 UCHAR last_sense_key;
141 UCHAR last_additional_sense_code;
142 blkif_response_t tmp_rep;
143 XENVBD_DEVICETYPE device_type;
144 XENVBD_DEVICEMODE device_mode;
145 ULONG bytes_per_sector;
146 ULONGLONG total_sectors;
147 XENPCI_VECTORS vectors;
148 PXENPCI_DEVICE_STATE device_state;
149 LIST_ENTRY srb_list;
150 BOOLEAN aligned_buffer_in_use;
151 ULONG aligned_buffer_size;
152 PVOID aligned_buffer;
153 /*
154 ULONGLONG interrupts;
155 ULONGLONG aligned_requests;
156 ULONGLONG aligned_bytes;
157 ULONGLONG unaligned_requests;
158 ULONGLONG unaligned_bytes;
159 */
160 /* 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 */
161 #define UNALIGNED_BUFFER_DATA_SIZE ((BLKIF_MAX_SEGMENTS_PER_REQUEST + 1) * PAGE_SIZE - 1)
162 #define UNALIGNED_BUFFER_DATA_SIZE_DUMP_MODE ((DUMP_MODE_UNALIGNED_PAGES + 1) * PAGE_SIZE - 1)
163 /* this has to be right at the end of DeviceExtension */
164 /* can't allocate too much data in dump mode so size DeviceExtensionSize accordingly */
165 UCHAR aligned_buffer_data[1];
166 } typedef XENVBD_DEVICE_DATA, *PXENVBD_DEVICE_DATA;
168 #endif