1250199Sgrehan/*- 2250199Sgrehan * Copyright (c) 2009-2012 Microsoft Corp. 3250199Sgrehan * Copyright (c) 2012 NetApp Inc. 4250199Sgrehan * Copyright (c) 2012 Citrix Inc. 5250199Sgrehan * All rights reserved. 6250199Sgrehan * 7250199Sgrehan * Redistribution and use in source and binary forms, with or without 8250199Sgrehan * modification, are permitted provided that the following conditions 9250199Sgrehan * are met: 10250199Sgrehan * 1. Redistributions of source code must retain the above copyright 11250199Sgrehan * notice unmodified, this list of conditions, and the following 12250199Sgrehan * disclaimer. 13250199Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 14250199Sgrehan * notice, this list of conditions and the following disclaimer in the 15250199Sgrehan * documentation and/or other materials provided with the distribution. 16250199Sgrehan * 17250199Sgrehan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18250199Sgrehan * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19250199Sgrehan * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20250199Sgrehan * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21250199Sgrehan * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22250199Sgrehan * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23250199Sgrehan * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24250199Sgrehan * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25250199Sgrehan * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26250199Sgrehan * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27256276Sdim * 28256276Sdim * $FreeBSD$ 29250199Sgrehan */ 30250199Sgrehan 31250199Sgrehan#ifndef __HV_VSTORAGE_H__ 32250199Sgrehan#define __HV_VSTORAGE_H__ 33250199Sgrehan 34250199Sgrehan/* 35250199Sgrehan * Major/minor macros. Minor version is in LSB, meaning that earlier flat 36250199Sgrehan * version numbers will be interpreted as "0.x" (i.e., 1 becomes 0.1). 37250199Sgrehan */ 38250199Sgrehan 39250199Sgrehan#define VMSTOR_PROTOCOL_MAJOR(VERSION_) (((VERSION_) >> 8) & 0xff) 40250199Sgrehan#define VMSTOR_PROTOCOL_MINOR(VERSION_) (((VERSION_) ) & 0xff) 41250199Sgrehan#define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \ 42250199Sgrehan (((MINOR_) & 0xff) )) 43250199Sgrehan 44250199Sgrehan/* 45250199Sgrehan * Invalid version. 46250199Sgrehan */ 47250199Sgrehan#define VMSTOR_INVALID_PROTOCOL_VERSION -1 48250199Sgrehan 49250199Sgrehan/* 50250199Sgrehan * Version history: 51250199Sgrehan * V1 Beta 0.1 52250199Sgrehan * V1 RC < 2008/1/31 1.0 53250199Sgrehan * V1 RC > 2008/1/31 2.0 54250199Sgrehan */ 55250199Sgrehan 56250199Sgrehan#define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(2, 0) 57250199Sgrehan 58250199Sgrehan/** 59250199Sgrehan * Packet structure ops describing virtual storage requests. 60250199Sgrehan */ 61250199Sgrehanenum vstor_packet_ops { 62250199Sgrehan VSTOR_OPERATION_COMPLETEIO = 1, 63250199Sgrehan VSTOR_OPERATION_REMOVEDEVICE = 2, 64250199Sgrehan VSTOR_OPERATION_EXECUTESRB = 3, 65250199Sgrehan VSTOR_OPERATION_RESETLUN = 4, 66250199Sgrehan VSTOR_OPERATION_RESETADAPTER = 5, 67250199Sgrehan VSTOR_OPERATION_RESETBUS = 6, 68250199Sgrehan VSTOR_OPERATION_BEGININITIALIZATION = 7, 69250199Sgrehan VSTOR_OPERATION_ENDINITIALIZATION = 8, 70250199Sgrehan VSTOR_OPERATION_QUERYPROTOCOLVERSION = 9, 71250199Sgrehan VSTOR_OPERATION_QUERYPROPERTIES = 10, 72250199Sgrehan VSTOR_OPERATION_MAXIMUM = 10 73250199Sgrehan}; 74250199Sgrehan 75250199Sgrehan 76250199Sgrehan/* 77250199Sgrehan * Platform neutral description of a scsi request - 78250199Sgrehan * this remains the same across the write regardless of 32/64 bit 79250199Sgrehan * note: it's patterned off the Windows DDK SCSI_PASS_THROUGH structure 80250199Sgrehan */ 81250199Sgrehan 82250199Sgrehan#define CDB16GENERIC_LENGTH 0x10 83250199Sgrehan#define SENSE_BUFFER_SIZE 0x12 84250199Sgrehan#define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14 85250199Sgrehan 86250199Sgrehanstruct vmscsi_req { 87250199Sgrehan uint16_t length; 88250199Sgrehan uint8_t srb_status; 89250199Sgrehan uint8_t scsi_status; 90250199Sgrehan 91250199Sgrehan /* HBA number, set to the order number detected by initiator. */ 92250199Sgrehan uint8_t port; 93250199Sgrehan /* SCSI bus number or bus_id, different from CAM's path_id. */ 94250199Sgrehan uint8_t path_id; 95250199Sgrehan 96250199Sgrehan uint8_t target_id; 97250199Sgrehan uint8_t lun; 98250199Sgrehan 99250199Sgrehan uint8_t cdb_len; 100250199Sgrehan uint8_t sense_info_len; 101250199Sgrehan uint8_t data_in; 102250199Sgrehan uint8_t reserved; 103250199Sgrehan 104250199Sgrehan uint32_t transfer_len; 105250199Sgrehan 106250199Sgrehan union { 107250199Sgrehan uint8_t cdb[CDB16GENERIC_LENGTH]; 108250199Sgrehan 109250199Sgrehan uint8_t sense_data[SENSE_BUFFER_SIZE]; 110250199Sgrehan 111250199Sgrehan uint8_t reserved_array[MAX_DATA_BUFFER_LENGTH_WITH_PADDING]; 112256276Sdim } u; 113250199Sgrehan 114250199Sgrehan} __packed; 115250199Sgrehan 116250199Sgrehan/** 117250199Sgrehan * This structure is sent during the initialization phase to get the different 118250199Sgrehan * properties of the channel. 119250199Sgrehan */ 120250199Sgrehan 121250199Sgrehanstruct vmstor_chan_props { 122250199Sgrehan uint16_t proto_ver; 123250199Sgrehan uint8_t path_id; 124250199Sgrehan uint8_t target_id; 125250199Sgrehan 126250199Sgrehan /** 127250199Sgrehan * Note: port number is only really known on the client side 128250199Sgrehan */ 129250199Sgrehan uint32_t port; 130250199Sgrehan uint32_t flags; 131250199Sgrehan uint32_t max_transfer_bytes; 132250199Sgrehan 133250199Sgrehan /** 134250199Sgrehan * This id is unique for each channel and will correspond with 135250199Sgrehan * vendor specific data in the inquiry_ata 136250199Sgrehan */ 137250199Sgrehan uint64_t unique_id; 138250199Sgrehan 139250199Sgrehan} __packed; 140250199Sgrehan 141250199Sgrehan/** 142250199Sgrehan * This structure is sent during the storage protocol negotiations. 143250199Sgrehan */ 144250199Sgrehan 145250199Sgrehanstruct vmstor_proto_ver 146250199Sgrehan{ 147250199Sgrehan /** 148250199Sgrehan * Major (MSW) and minor (LSW) version numbers. 149250199Sgrehan */ 150250199Sgrehan uint16_t major_minor; 151250199Sgrehan 152250199Sgrehan uint16_t revision; /* always zero */ 153250199Sgrehan} __packed; 154250199Sgrehan 155250199Sgrehan/** 156250199Sgrehan * Channel Property Flags 157250199Sgrehan */ 158250199Sgrehan 159250199Sgrehan#define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1 160250199Sgrehan#define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2 161250199Sgrehan 162250199Sgrehan 163250199Sgrehanstruct vstor_packet { 164250199Sgrehan /** 165250199Sgrehan * Requested operation type 166250199Sgrehan */ 167250199Sgrehan enum vstor_packet_ops operation; 168250199Sgrehan 169250199Sgrehan /* 170250199Sgrehan * Flags - see below for values 171250199Sgrehan */ 172250199Sgrehan uint32_t flags; 173250199Sgrehan 174250199Sgrehan /** 175250199Sgrehan * Status of the request returned from the server side. 176250199Sgrehan */ 177250199Sgrehan uint32_t status; 178250199Sgrehan 179250199Sgrehan union 180250199Sgrehan { 181250199Sgrehan /** 182250199Sgrehan * Structure used to forward SCSI commands from the client to 183250199Sgrehan * the server. 184250199Sgrehan */ 185250199Sgrehan struct vmscsi_req vm_srb; 186250199Sgrehan 187250199Sgrehan /** 188250199Sgrehan * Structure used to query channel properties. 189250199Sgrehan */ 190250199Sgrehan struct vmstor_chan_props chan_props; 191250199Sgrehan 192250199Sgrehan /** 193250199Sgrehan * Used during version negotiations. 194250199Sgrehan */ 195250199Sgrehan struct vmstor_proto_ver version; 196256276Sdim } u; 197250199Sgrehan 198250199Sgrehan} __packed; 199250199Sgrehan 200250199Sgrehan 201250199Sgrehan/** 202250199Sgrehan * SRB (SCSI Request Block) Status Codes 203250199Sgrehan */ 204250199Sgrehan#define SRB_STATUS_PENDING 0x00 205250199Sgrehan#define SRB_STATUS_SUCCESS 0x01 206250199Sgrehan#define SRB_STATUS_ABORTED 0x02 207250199Sgrehan#define SRB_STATUS_ABORT_FAILED 0x03 208250199Sgrehan#define SRB_STATUS_ERROR 0x04 209250199Sgrehan#define SRB_STATUS_BUSY 0x05 210250199Sgrehan 211250199Sgrehan/** 212250199Sgrehan * SRB Status Masks (can be combined with above status codes) 213250199Sgrehan */ 214250199Sgrehan#define SRB_STATUS_QUEUE_FROZEN 0x40 215250199Sgrehan#define SRB_STATUS_AUTOSENSE_VALID 0x80 216250199Sgrehan 217250199Sgrehan 218250199Sgrehan/** 219250199Sgrehan * Packet flags 220250199Sgrehan */ 221250199Sgrehan 222250199Sgrehan/** 223250199Sgrehan * This flag indicates that the server should send back a completion for this 224250199Sgrehan * packet. 225250199Sgrehan */ 226250199Sgrehan#define REQUEST_COMPLETION_FLAG 0x1 227250199Sgrehan 228250199Sgrehan/** 229250199Sgrehan * This is the set of flags that the vsc can set in any packets it sends 230250199Sgrehan */ 231250199Sgrehan#define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG) 232250199Sgrehan 233250199Sgrehan#endif /* __HV_VSTORAGE_H__ */ 234