#ifndef __HV_VSTORAGE_H__
#define __HV_VSTORAGE_H__
#define VMSTOR_PROTOCOL_MAJOR(VERSION_) (((VERSION_) >> 8) & 0xff)
#define VMSTOR_PROTOCOL_MINOR(VERSION_) (((VERSION_) ) & 0xff)
#define VMSTOR_PROTOCOL_VERSION(MAJOR_, MINOR_) ((((MAJOR_) & 0xff) << 8) | \
(((MINOR_) & 0xff) ))
#define VMSTOR_PROTOCOL_VERSION_WIN6 VMSTOR_PROTOCOL_VERSION(2, 0)
#define VMSTOR_PROTOCOL_VERSION_WIN7 VMSTOR_PROTOCOL_VERSION(4, 2)
#define VMSTOR_PROTOCOL_VERSION_WIN8 VMSTOR_PROTOCOL_VERSION(5, 1)
#define VMSTOR_PROTOCOL_VERSION_WIN8_1 VMSTOR_PROTOCOL_VERSION(6, 0)
#define VMSTOR_PROTOCOL_VERSION_WIN10 VMSTOR_PROTOCOL_VERSION(6, 2)
#define VMSTOR_INVALID_PROTOCOL_VERSION -1
#define VMSTOR_PROTOCOL_VERSION_CURRENT VMSTOR_PROTOCOL_VERSION(5, 1)
enum vstor_packet_ops {
VSTOR_OPERATION_COMPLETEIO = 1,
VSTOR_OPERATION_REMOVEDEVICE = 2,
VSTOR_OPERATION_EXECUTESRB = 3,
VSTOR_OPERATION_RESETLUN = 4,
VSTOR_OPERATION_RESETADAPTER = 5,
VSTOR_OPERATION_RESETBUS = 6,
VSTOR_OPERATION_BEGININITIALIZATION = 7,
VSTOR_OPERATION_ENDINITIALIZATION = 8,
VSTOR_OPERATION_QUERYPROTOCOLVERSION = 9,
VSTOR_OPERATION_QUERYPROPERTIES = 10,
VSTOR_OPERATION_ENUMERATE_BUS = 11,
VSTOR_OPERATION_FCHBA_DATA = 12,
VSTOR_OPERATION_CREATE_MULTI_CHANNELS = 13,
VSTOR_OPERATION_MAXIMUM = 13
};
#define CDB16GENERIC_LENGTH 0x10
#define SENSE_BUFFER_SIZE 0x14
#define MAX_DATA_BUFFER_LENGTH_WITH_PADDING 0x14
#define POST_WIN7_STORVSC_SENSE_BUFFER_SIZE 0x14
#define PRE_WIN8_STORVSC_SENSE_BUFFER_SIZE 0x12
struct vmscsi_win8_extension {
uint16_t reserve;
uint8_t queue_tag;
uint8_t queue_action;
uint32_t srb_flags;
uint32_t time_out_value;
uint32_t queue_sort_ey;
} __packed;
struct vmscsi_req {
uint16_t length;
uint8_t srb_status;
uint8_t scsi_status;
uint8_t port;
uint8_t path_id;
uint8_t target_id;
uint8_t lun;
uint8_t cdb_len;
uint8_t sense_info_len;
uint8_t data_in;
uint8_t reserved;
uint32_t transfer_len;
union {
uint8_t cdb[CDB16GENERIC_LENGTH];
uint8_t sense_data[SENSE_BUFFER_SIZE];
uint8_t reserved_array[MAX_DATA_BUFFER_LENGTH_WITH_PADDING];
} u;
struct vmscsi_win8_extension win8_extension;
} __packed;
struct vmstor_chan_props {
uint16_t proto_ver;
uint8_t path_id;
uint8_t target_id;
uint16_t max_channel_cnt;
uint16_t port;
uint32_t flags;
uint32_t max_transfer_bytes;
uint64_t unique_id;
} __packed;
struct vmstor_proto_ver
{
uint16_t major_minor;
uint16_t revision;
} __packed;
#define STORAGE_CHANNEL_REMOVABLE_FLAG 0x1
#define STORAGE_CHANNEL_EMULATED_IDE_FLAG 0x2
struct vstor_packet {
enum vstor_packet_ops operation;
uint32_t flags;
uint32_t status;
union
{
struct vmscsi_req vm_srb;
struct vmstor_chan_props chan_props;
struct vmstor_proto_ver version;
uint16_t multi_channels_cnt;
} u;
} __packed;
#define SRB_STATUS_PENDING 0x00
#define SRB_STATUS_SUCCESS 0x01
#define SRB_STATUS_ABORTED 0x02
#define SRB_STATUS_ABORT_FAILED 0x03
#define SRB_STATUS_ERROR 0x04
#define SRB_STATUS_BUSY 0x05
#define SRB_STATUS_INVALID_REQUEST 0x06
#define SRB_STATUS_INVALID_PATH_ID 0x07
#define SRB_STATUS_NO_DEVICE 0x08
#define SRB_STATUS_TIMEOUT 0x09
#define SRB_STATUS_SELECTION_TIMEOUT 0x0A
#define SRB_STATUS_COMMAND_TIMEOUT 0x0B
#define SRB_STATUS_MESSAGE_REJECTED 0x0D
#define SRB_STATUS_BUS_RESET 0x0E
#define SRB_STATUS_PARITY_ERROR 0x0F
#define SRB_STATUS_REQUEST_SENSE_FAILED 0x10
#define SRB_STATUS_NO_HBA 0x11
#define SRB_STATUS_DATA_OVERRUN 0x12
#define SRB_STATUS_UNEXPECTED_BUS_FREE 0x13
#define SRB_STATUS_PHASE_SEQUENCE_FAILURE 0x14
#define SRB_STATUS_BAD_SRB_BLOCK_LENGTH 0x15
#define SRB_STATUS_REQUEST_FLUSHED 0x16
#define SRB_STATUS_INVALID_LUN 0x20
#define SRB_STATUS_INVALID_TARGET_ID 0x21
#define SRB_STATUS_BAD_FUNCTION 0x22
#define SRB_STATUS_ERROR_RECOVERY 0x23
#define SRB_STATUS_NOT_POWERED 0x24
#define SRB_STATUS_LINK_DOWN 0x25
#define SRB_STATUS_QUEUE_FROZEN 0x40
#define SRB_STATUS_AUTOSENSE_VALID 0x80
#define SRB_STATUS(status) \
((status) & ~(SRB_STATUS_AUTOSENSE_VALID | SRB_STATUS_QUEUE_FROZEN))
#define SRB_FLAGS_QUEUE_ACTION_ENABLE 0x00000002
#define SRB_FLAGS_DISABLE_DISCONNECT 0x00000004
#define SRB_FLAGS_DISABLE_SYNCH_TRANSFER 0x00000008
#define SRB_FLAGS_BYPASS_FROZEN_QUEUE 0x00000010
#define SRB_FLAGS_DISABLE_AUTOSENSE 0x00000020
#define SRB_FLAGS_DATA_IN 0x00000040
#define SRB_FLAGS_DATA_OUT 0x00000080
#define SRB_FLAGS_NO_DATA_TRANSFER 0x00000000
#define SRB_FLAGS_UNSPECIFIED_DIRECTION (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)
#define SRB_FLAGS_NO_QUEUE_FREEZE 0x00000100
#define SRB_FLAGS_ADAPTER_CACHE_ENABLE 0x00000200
#define SRB_FLAGS_FREE_SENSE_BUFFER 0x00000400
#define REQUEST_COMPLETION_FLAG 0x1
#define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG)
#endif