win-pvdrivers

view xenvbd/xenvbd_scsiport.h @ 993:61fea9275419

Added tag 0.11.0.369 for changeset 58899e6ed48f
author James Harper <james.harper@bendigoit.com.au>
date Fri Sep 21 23:34:14 2012 +1000 (2012-09-21)
parents dae0e5c1f26c
children
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 #define DDKAPI
25 //#include <ntifs.h>
26 #include <ntddk.h>
27 #include <wdm.h>
28 #include <initguid.h>
29 #define NTSTRSAFE_LIB
30 #include <ntstrsafe.h>
32 #include <ntdddisk.h>
33 #if (NTDDI_VERSION < NTDDI_WINXP) /* srb.h causes warnings under 2K for some reason */
34 #pragma warning(disable:4201) /* nameless struct/union */
35 #pragma warning(disable:4214) /* bit field types other than int */
36 #endif
37 #include <srb.h>
39 #define __DRIVER_NAME "XenVbd"
41 #include <xen_windows.h>
42 #include <memory.h>
43 //#include <grant_table.h>
44 #include <event_channel.h>
45 #include <hvm/params.h>
46 #include <hvm/hvm_op.h>
47 #include <xen_public.h>
48 #include <io/ring.h>
49 #include <io/blkif.h>
50 #include <io/xenbus.h>
52 #define XENVBD_POOL_TAG (ULONG) 'XVBD'
54 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
55 #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
56 #define BLK_OTHER_RING_SIZE __RING_SIZE((blkif_other_sring_t *)0, PAGE_SIZE)
58 #if defined(__x86_64__)
59 #pragma pack(push, 4)
60 #endif
61 struct blkif_other_request {
62 uint8_t operation;
63 uint8_t nr_segments;
64 blkif_vdev_t handle;
65 uint64_t id;
66 blkif_sector_t sector_number;
67 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
68 };
69 struct blkif_other_response {
70 uint64_t id;
71 uint8_t operation;
72 int16_t status;
73 };
74 #if defined(__x86_64__)
75 #pragma pack(pop)
76 #endif
78 typedef struct blkif_other_request blkif_other_request_t;
79 typedef struct blkif_other_response blkif_other_response_t;
80 DEFINE_RING_TYPES(blkif_other, struct blkif_other_request, struct blkif_other_response);
82 typedef struct {
83 LIST_ENTRY list_entry;
84 PSCSI_REQUEST_BLOCK srb;
85 } srb_list_entry_t;
87 typedef struct {
88 blkif_request_t req;
89 PSCSI_REQUEST_BLOCK srb;
90 BOOLEAN aligned_buffer_in_use;
91 BOOLEAN reset;
92 #if DBG && NTDDI_VERSION >= NTDDI_WINXP
93 LARGE_INTEGER ring_submit_time;
94 #endif
95 } blkif_shadow_t;
97 #define MAX_SHADOW_ENTRIES 64
98 #define SHADOW_ID_ID_MASK 0x03FF /* maximum of 1024 requests - currently use a maximum of 64 though */
99 #define SHADOW_ID_DUMP_FLAG 0x8000 /* indicates the request was generated by dump mode */
101 #define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, min(BLK_RING_SIZE, BLK_OTHER_RING_SIZE))
103 typedef enum {
104 XENVBD_DEVICETYPE_UNKNOWN,
105 XENVBD_DEVICETYPE_DISK,
106 XENVBD_DEVICETYPE_CDROM,
107 XENVBD_DEVICETYPE_CONTROLLER // Not yet used
108 } XENVBD_DEVICETYPE;
110 typedef enum {
111 XENVBD_DEVICEMODE_UNKNOWN,
112 XENVBD_DEVICEMODE_READ,
113 XENVBD_DEVICEMODE_WRITE
114 } XENVBD_DEVICEMODE;
116 #define RING_DETECT_STATE_NOT_STARTED 0
117 #define RING_DETECT_STATE_DETECT1 1
118 #define RING_DETECT_STATE_DETECT2 2
119 #define RING_DETECT_STATE_COMPLETE 3
121 struct
122 {
123 BOOLEAN inactive;
125 blkif_shadow_t shadows[MAX_SHADOW_ENTRIES];
126 USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
127 USHORT shadow_free;
128 USHORT shadow_min_free;
130 PUCHAR device_base;
132 blkif_sring_t *sring;
133 evtchn_port_t event_channel;
134 ULONG *event_channel_ptr;
135 union {
136 blkif_front_ring_t ring;
137 blkif_other_front_ring_t other_ring;
138 };
139 int ring_detect_state;
140 BOOLEAN use_other;
141 BOOLEAN cached_use_other;
142 BOOLEAN cached_use_other_valid;
143 UCHAR last_sense_key;
144 UCHAR last_additional_sense_code;
145 blkif_response_t tmp_rep;
146 XENVBD_DEVICETYPE device_type;
147 XENVBD_DEVICEMODE device_mode;
148 ULONG bytes_per_sector;
149 ULONGLONG total_sectors;
150 XENPCI_VECTORS vectors;
151 PXENPCI_DEVICE_STATE device_state;
152 LIST_ENTRY srb_list;
153 grant_ref_t dump_grant_refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
154 BOOLEAN aligned_buffer_in_use;
155 PVOID aligned_buffer;
156 /*
157 ULONGLONG interrupts;
158 ULONGLONG aligned_requests;
159 ULONGLONG aligned_bytes;
160 ULONGLONG unaligned_requests;
161 ULONGLONG unaligned_bytes;
162 */
163 #define BLKIF_MAX_SEGMENTS_PER_REQUEST_DUMP_MODE 1
164 #define UNALIGNED_BUFFER_DATA_SIZE ((BLKIF_MAX_SEGMENTS_PER_REQUEST + 1) * PAGE_SIZE - 1)
165 #define UNALIGNED_BUFFER_DATA_SIZE_DUMP_MODE ((BLKIF_MAX_SEGMENTS_PER_REQUEST_DUMP_MODE + 1) * PAGE_SIZE - 1)
166 /* this has to be right at the end of DeviceExtension */
167 /* can't allocate too much data in dump mode so size DeviceExtensionSize accordingly */
168 UCHAR aligned_buffer_data[1];
169 } typedef XENVBD_DEVICE_DATA, *PXENVBD_DEVICE_DATA;
171 #endif