virtio_scsi.h 5.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*
 * This header is BSD licensed so anyone can use the definitions to implement
 * compatible drivers/servers.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

27 28 29
#ifndef _LINUX_VIRTIO_SCSI_H
#define _LINUX_VIRTIO_SCSI_H

M
Michael S. Tsirkin 已提交
30 31
#include <linux/virtio_types.h>

32 33 34 35 36
#define VIRTIO_SCSI_CDB_SIZE   32
#define VIRTIO_SCSI_SENSE_SIZE 96

/* SCSI command request, followed by data-out */
struct virtio_scsi_cmd_req {
37
	__u8 lun[8];		/* Logical Unit Number */
M
Michael S. Tsirkin 已提交
38
	__virtio64 tag;		/* Command identifier */
39 40 41 42 43
	__u8 task_attr;		/* Task attribute */
	__u8 prio;		/* SAM command priority field */
	__u8 crn;
	__u8 cdb[VIRTIO_SCSI_CDB_SIZE];
} __attribute__((packed));
44

45 46
/* SCSI command request, followed by protection information */
struct virtio_scsi_cmd_req_pi {
47
	__u8 lun[8];		/* Logical Unit Number */
M
Michael S. Tsirkin 已提交
48
	__virtio64 tag;		/* Command identifier */
49 50 51
	__u8 task_attr;		/* Task attribute */
	__u8 prio;		/* SAM command priority field */
	__u8 crn;
M
Michael S. Tsirkin 已提交
52 53
	__virtio32 pi_bytesout;	/* DataOUT PI Number of bytes */
	__virtio32 pi_bytesin;		/* DataIN PI Number of bytes */
54 55
	__u8 cdb[VIRTIO_SCSI_CDB_SIZE];
} __attribute__((packed));
56

57 58
/* Response, followed by sense data and data-in */
struct virtio_scsi_cmd_resp {
M
Michael S. Tsirkin 已提交
59 60 61
	__virtio32 sense_len;		/* Sense data length */
	__virtio32 resid;		/* Residual bytes in data buffer */
	__virtio16 status_qualifier;	/* Status qualifier */
62 63 64 65
	__u8 status;		/* Command completion status */
	__u8 response;		/* Response values */
	__u8 sense[VIRTIO_SCSI_SENSE_SIZE];
} __attribute__((packed));
66 67 68

/* Task Management Request */
struct virtio_scsi_ctrl_tmf_req {
M
Michael S. Tsirkin 已提交
69 70
	__virtio32 type;
	__virtio32 subtype;
71
	__u8 lun[8];
M
Michael S. Tsirkin 已提交
72
	__virtio64 tag;
73
} __attribute__((packed));
74 75

struct virtio_scsi_ctrl_tmf_resp {
76 77
	__u8 response;
} __attribute__((packed));
78 79 80

/* Asynchronous notification query/subscription */
struct virtio_scsi_ctrl_an_req {
M
Michael S. Tsirkin 已提交
81
	__virtio32 type;
82
	__u8 lun[8];
M
Michael S. Tsirkin 已提交
83
	__virtio32 event_requested;
84
} __attribute__((packed));
85 86

struct virtio_scsi_ctrl_an_resp {
M
Michael S. Tsirkin 已提交
87
	__virtio32 event_actual;
88 89
	__u8 response;
} __attribute__((packed));
90 91

struct virtio_scsi_event {
M
Michael S. Tsirkin 已提交
92
	__virtio32 event;
93
	__u8 lun[8];
M
Michael S. Tsirkin 已提交
94
	__virtio32 reason;
95
} __attribute__((packed));
96 97

struct virtio_scsi_config {
98 99 100 101 102 103 104 105 106 107 108
	__u32 num_queues;
	__u32 seg_max;
	__u32 max_sectors;
	__u32 cmd_per_lun;
	__u32 event_info_size;
	__u32 sense_size;
	__u32 cdb_size;
	__u16 max_channel;
	__u16 max_target;
	__u32 max_lun;
} __attribute__((packed));
109

110 111 112
/* Feature Bits */
#define VIRTIO_SCSI_F_INOUT                    0
#define VIRTIO_SCSI_F_HOTPLUG                  1
113
#define VIRTIO_SCSI_F_CHANGE                   2
114
#define VIRTIO_SCSI_F_T10_PI                   3
115

116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
/* Response codes */
#define VIRTIO_SCSI_S_OK                       0
#define VIRTIO_SCSI_S_OVERRUN                  1
#define VIRTIO_SCSI_S_ABORTED                  2
#define VIRTIO_SCSI_S_BAD_TARGET               3
#define VIRTIO_SCSI_S_RESET                    4
#define VIRTIO_SCSI_S_BUSY                     5
#define VIRTIO_SCSI_S_TRANSPORT_FAILURE        6
#define VIRTIO_SCSI_S_TARGET_FAILURE           7
#define VIRTIO_SCSI_S_NEXUS_FAILURE            8
#define VIRTIO_SCSI_S_FAILURE                  9
#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED       10
#define VIRTIO_SCSI_S_FUNCTION_REJECTED        11
#define VIRTIO_SCSI_S_INCORRECT_LUN            12

/* Controlq type codes.  */
#define VIRTIO_SCSI_T_TMF                      0
#define VIRTIO_SCSI_T_AN_QUERY                 1
#define VIRTIO_SCSI_T_AN_SUBSCRIBE             2

/* Valid TMF subtypes.  */
#define VIRTIO_SCSI_T_TMF_ABORT_TASK           0
#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET       1
#define VIRTIO_SCSI_T_TMF_CLEAR_ACA            2
#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET       3
#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET      4
#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET   5
#define VIRTIO_SCSI_T_TMF_QUERY_TASK           6
#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET       7

/* Events.  */
#define VIRTIO_SCSI_T_EVENTS_MISSED            0x80000000
#define VIRTIO_SCSI_T_NO_EVENT                 0
#define VIRTIO_SCSI_T_TRANSPORT_RESET          1
#define VIRTIO_SCSI_T_ASYNC_NOTIFY             2
151
#define VIRTIO_SCSI_T_PARAM_CHANGE             3
152

153 154 155 156 157
/* Reasons of transport reset event */
#define VIRTIO_SCSI_EVT_RESET_HARD             0
#define VIRTIO_SCSI_EVT_RESET_RESCAN           1
#define VIRTIO_SCSI_EVT_RESET_REMOVED          2

158 159 160 161 162 163 164
#define VIRTIO_SCSI_S_SIMPLE                   0
#define VIRTIO_SCSI_S_ORDERED                  1
#define VIRTIO_SCSI_S_HEAD                     2
#define VIRTIO_SCSI_S_ACA                      3


#endif /* _LINUX_VIRTIO_SCSI_H */