win-pvdrivers

view xenvbd/xenvbd_storport.h @ 982:e9011a1ba5bb

started rewriting xenpci<->child interface
author James Harper <james.harper@bendigoit.com.au>
date Mon Aug 13 17:10:03 2012 +1000 (2012-08-13)
parents 4b8b40cda748
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 #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)
51 typedef struct {
52 LIST_ENTRY list_entry;
53 PSCSI_REQUEST_BLOCK srb;
54 ULONG length; /* cached srb length */
55 ULONG offset; /* current srb offset */
56 ULONG outstanding_requests; /* number of requests sent to xen for this srb */
57 BOOLEAN error; /* true if any sub requests have returned an error */
58 } srb_list_entry_t;
60 typedef struct {
61 blkif_request_t req;
62 srb_list_entry_t *srb_list_entry;
63 PSCSI_REQUEST_BLOCK srb;
64 PVOID system_address;
65 ULONG length;
66 BOOLEAN aligned_buffer_in_use;
67 BOOLEAN reset;
68 #if DBG
69 LARGE_INTEGER ring_submit_time;
70 #endif
71 } blkif_shadow_t;
73 #define MAX_SHADOW_ENTRIES 64
74 #define SHADOW_ID_ID_MASK 0x03FF /* maximum of 1024 requests - currently use a maximum of 64 though */
75 #define SHADOW_ID_DUMP_FLAG 0x8000 /* indicates the request was generated by dump mode */
77 #define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, BLK_RING_SIZE)
79 typedef enum {
80 XENVBD_DEVICETYPE_UNKNOWN,
81 XENVBD_DEVICETYPE_DISK,
82 XENVBD_DEVICETYPE_CDROM,
83 XENVBD_DEVICETYPE_CONTROLLER // Not yet used
84 } XENVBD_DEVICETYPE;
86 typedef enum {
87 XENVBD_DEVICEMODE_UNKNOWN,
88 XENVBD_DEVICEMODE_READ,
89 XENVBD_DEVICEMODE_WRITE
90 } XENVBD_DEVICEMODE;
92 /* if this is ever increased to more than 1 then we need a way of tracking it properly */
93 #define DUMP_MODE_UNALIGNED_PAGES 1 /* only for unaligned buffer use */
95 struct
96 {
97 BOOLEAN inactive;
99 blkif_shadow_t shadows[MAX_SHADOW_ENTRIES];
100 USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
101 USHORT shadow_free;
102 USHORT shadow_min_free;
103 ULONG grant_tag;
105 blkif_sring_t *sring;
106 evtchn_port_t event_channel;
107 ULONG *event_channel_ptr;
108 blkif_front_ring_t ring;
109 UCHAR last_sense_key;
110 UCHAR last_additional_sense_code;
111 blkif_response_t tmp_rep;
112 XENVBD_DEVICETYPE device_type;
113 XENVBD_DEVICEMODE device_mode;
114 ULONG bytes_per_sector;
115 ULONGLONG total_sectors;
116 XENPCI_VECTORS vectors;
117 PXENPCI_DEVICE_STATE device_state;
118 LIST_ENTRY srb_list;
119 BOOLEAN aligned_buffer_in_use;
120 ULONG aligned_buffer_size;
121 PVOID aligned_buffer;
122 /*
123 ULONGLONG interrupts;
124 ULONGLONG aligned_requests;
125 ULONGLONG aligned_bytes;
126 ULONGLONG unaligned_requests;
127 ULONGLONG unaligned_bytes;
128 */
129 /* 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 */
130 #define UNALIGNED_BUFFER_DATA_SIZE ((BLKIF_MAX_SEGMENTS_PER_REQUEST + 1) * PAGE_SIZE - 1)
131 #define UNALIGNED_BUFFER_DATA_SIZE_DUMP_MODE ((DUMP_MODE_UNALIGNED_PAGES + 1) * PAGE_SIZE - 1)
132 /* this has to be right at the end of DeviceExtension */
133 /* can't allocate too much data in dump mode so size DeviceExtensionSize accordingly */
134 UCHAR aligned_buffer_data[1];
135 } typedef XENVBD_DEVICE_DATA, *PXENVBD_DEVICE_DATA;
137 #endif