win-pvdrivers

annotate 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
rev   line source
james@267 1 /*
james@267 2 PV Drivers for Windows Xen HVM Domains
james@267 3 Copyright (C) 2007 James Harper
james@267 4
james@267 5 This program is free software; you can redistribute it and/or
james@267 6 modify it under the terms of the GNU General Public License
james@267 7 as published by the Free Software Foundation; either version 2
james@267 8 of the License, or (at your option) any later version.
james@267 9
james@267 10 This program is distributed in the hope that it will be useful,
james@267 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
james@267 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
james@267 13 GNU General Public License for more details.
james@267 14
james@267 15 You should have received a copy of the GNU General Public License
james@267 16 along with this program; if not, write to the Free Software
james@267 17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
james@267 18 */
james@267 19
james@48 20 #if !defined(_XENVBD_H_)
james@48 21 #define _XENVBD_H_
andy@378 22
andy@378 23 #define DDKAPI
james@0 24
james@716 25 //#include <ntifs.h>
james@0 26 #include <ntddk.h>
james@0 27 #include <wdm.h>
james@0 28 #include <initguid.h>
andy@378 29 #define NTSTRSAFE_LIB
andy@378 30 #include <ntstrsafe.h>
andy@378 31
james@0 32 #include <ntdddisk.h>
james@816 33 #if (NTDDI_VERSION < NTDDI_WINXP) /* srb.h causes warnings under 2K for some reason */
james@816 34 #pragma warning(disable:4201) /* nameless struct/union */
james@816 35 #pragma warning(disable:4214) /* bit field types other than int */
james@816 36 #endif
james@48 37 #include <srb.h>
james@0 38
james@74 39 #define __DRIVER_NAME "XenVbd"
james@74 40
james@0 41 #include <xen_windows.h>
james@0 42 #include <memory.h>
james@534 43 //#include <grant_table.h>
james@0 44 #include <event_channel.h>
james@0 45 #include <hvm/params.h>
james@0 46 #include <hvm/hvm_op.h>
james@48 47 #include <xen_public.h>
james@0 48 #include <io/ring.h>
james@0 49 #include <io/blkif.h>
james@803 50 #include <io/xenbus.h>
james@74 51
james@48 52 #define XENVBD_POOL_TAG (ULONG) 'XVBD'
james@0 53
james@0 54 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
james@0 55 #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
james@162 56 #define BLK_OTHER_RING_SIZE __RING_SIZE((blkif_other_sring_t *)0, PAGE_SIZE)
james@162 57
james@162 58 #if defined(__x86_64__)
james@162 59 #pragma pack(push, 4)
james@162 60 #endif
james@162 61 struct blkif_other_request {
james@162 62 uint8_t operation;
james@162 63 uint8_t nr_segments;
james@162 64 blkif_vdev_t handle;
james@162 65 uint64_t id;
james@162 66 blkif_sector_t sector_number;
james@162 67 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
james@162 68 };
james@162 69 struct blkif_other_response {
james@162 70 uint64_t id;
james@162 71 uint8_t operation;
james@162 72 int16_t status;
james@162 73 };
james@162 74 #if defined(__x86_64__)
james@162 75 #pragma pack(pop)
james@162 76 #endif
james@162 77
james@162 78 typedef struct blkif_other_request blkif_other_request_t;
james@162 79 typedef struct blkif_other_response blkif_other_response_t;
james@162 80 DEFINE_RING_TYPES(blkif_other, struct blkif_other_request, struct blkif_other_response);
james@0 81
james@0 82 typedef struct {
james@781 83 LIST_ENTRY list_entry;
james@781 84 PSCSI_REQUEST_BLOCK srb;
james@781 85 } srb_list_entry_t;
james@781 86
james@781 87 typedef struct {
james@0 88 blkif_request_t req;
james@280 89 PSCSI_REQUEST_BLOCK srb;
james@766 90 BOOLEAN aligned_buffer_in_use;
james@871 91 BOOLEAN reset;
james@882 92 #if DBG && NTDDI_VERSION >= NTDDI_WINXP
james@871 93 LARGE_INTEGER ring_submit_time;
james@871 94 #endif
james@0 95 } blkif_shadow_t;
james@0 96
james@876 97 #define MAX_SHADOW_ENTRIES 64
james@876 98 #define SHADOW_ID_ID_MASK 0x03FF /* maximum of 1024 requests - currently use a maximum of 64 though */
james@876 99 #define SHADOW_ID_DUMP_FLAG 0x8000 /* indicates the request was generated by dump mode */
james@876 100
james@425 101 #define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, min(BLK_RING_SIZE, BLK_OTHER_RING_SIZE))
james@0 102
james@9 103 typedef enum {
james@9 104 XENVBD_DEVICETYPE_UNKNOWN,
james@9 105 XENVBD_DEVICETYPE_DISK,
james@48 106 XENVBD_DEVICETYPE_CDROM,
james@48 107 XENVBD_DEVICETYPE_CONTROLLER // Not yet used
james@9 108 } XENVBD_DEVICETYPE;
james@9 109
wayne@363 110 typedef enum {
wayne@363 111 XENVBD_DEVICEMODE_UNKNOWN,
wayne@363 112 XENVBD_DEVICEMODE_READ,
wayne@363 113 XENVBD_DEVICEMODE_WRITE
wayne@363 114 } XENVBD_DEVICEMODE;
wayne@363 115
james@577 116 #define RING_DETECT_STATE_NOT_STARTED 0
james@577 117 #define RING_DETECT_STATE_DETECT1 1
james@577 118 #define RING_DETECT_STATE_DETECT2 2
james@577 119 #define RING_DETECT_STATE_COMPLETE 3
james@577 120
james@48 121 struct
james@48 122 {
james@425 123 BOOLEAN inactive;
james@425 124
james@425 125 blkif_shadow_t shadows[MAX_SHADOW_ENTRIES];
james@425 126 USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
james@267 127 USHORT shadow_free;
james@284 128 USHORT shadow_min_free;
james@267 129
james@342 130 PUCHAR device_base;
james@267 131
james@342 132 blkif_sring_t *sring;
james@267 133 evtchn_port_t event_channel;
james@435 134 ULONG *event_channel_ptr;
james@162 135 union {
james@267 136 blkif_front_ring_t ring;
james@267 137 blkif_other_front_ring_t other_ring;
james@162 138 };
james@162 139 int ring_detect_state;
james@162 140 BOOLEAN use_other;
james@435 141 BOOLEAN cached_use_other;
james@913 142 BOOLEAN cached_use_other_valid;
james@284 143 UCHAR last_sense_key;
james@291 144 UCHAR last_additional_sense_code;
james@162 145 blkif_response_t tmp_rep;
james@267 146 XENVBD_DEVICETYPE device_type;
wayne@363 147 XENVBD_DEVICEMODE device_mode;
james@267 148 ULONG bytes_per_sector;
james@267 149 ULONGLONG total_sectors;
james@267 150 XENPCI_VECTORS vectors;
james@342 151 PXENPCI_DEVICE_STATE device_state;
james@781 152 LIST_ENTRY srb_list;
james@790 153 grant_ref_t dump_grant_refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
james@766 154 BOOLEAN aligned_buffer_in_use;
james@766 155 PVOID aligned_buffer;
james@425 156 /*
james@293 157 ULONGLONG interrupts;
james@293 158 ULONGLONG aligned_requests;
james@293 159 ULONGLONG aligned_bytes;
james@293 160 ULONGLONG unaligned_requests;
james@293 161 ULONGLONG unaligned_bytes;
james@425 162 */
james@810 163 #define BLKIF_MAX_SEGMENTS_PER_REQUEST_DUMP_MODE 1
james@810 164 #define UNALIGNED_BUFFER_DATA_SIZE ((BLKIF_MAX_SEGMENTS_PER_REQUEST + 1) * PAGE_SIZE - 1)
james@810 165 #define UNALIGNED_BUFFER_DATA_SIZE_DUMP_MODE ((BLKIF_MAX_SEGMENTS_PER_REQUEST_DUMP_MODE + 1) * PAGE_SIZE - 1)
james@810 166 /* this has to be right at the end of DeviceExtension */
james@810 167 /* can't allocate too much data in dump mode so size DeviceExtensionSize accordingly */
james@810 168 UCHAR aligned_buffer_data[1];
james@48 169 } typedef XENVBD_DEVICE_DATA, *PXENVBD_DEVICE_DATA;
james@0 170
andy@378 171 #endif
andy@378 172