blob: de429d1f4357a89d2a6a9506611a93a6c201fdc6 [file] [log] [blame]
Bryan Venteicher7e054842012-10-16 23:55:54 +10301/*
2 * This header is BSD licensed so anyone can use the definitions to implement
3 * compatible drivers/servers.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010027#ifndef _LINUX_VIRTIO_SCSI_H
28#define _LINUX_VIRTIO_SCSI_H
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010029
30#define VIRTIO_SCSI_CDB_SIZE 32
31#define VIRTIO_SCSI_SENSE_SIZE 96
32
33/* SCSI command request, followed by data-out */
34struct virtio_scsi_cmd_req {
35 u8 lun[8]; /* Logical Unit Number */
36 u64 tag; /* Command identifier */
37 u8 task_attr; /* Task attribute */
Nicholas Bellinger1b49dcf2014-03-16 14:51:35 -070038 u8 prio; /* SAM command priority field */
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010039 u8 crn;
40 u8 cdb[VIRTIO_SCSI_CDB_SIZE];
41} __packed;
42
Nicholas Bellinger1b49dcf2014-03-16 14:51:35 -070043/* SCSI command request, followed by protection information */
44struct virtio_scsi_cmd_req_pi {
45 u8 lun[8]; /* Logical Unit Number */
46 u64 tag; /* Command identifier */
47 u8 task_attr; /* Task attribute */
48 u8 prio; /* SAM command priority field */
49 u8 crn;
50 u32 pi_bytesout; /* DataOUT PI Number of bytes */
51 u32 pi_bytesin; /* DataIN PI Number of bytes */
52 u8 cdb[VIRTIO_SCSI_CDB_SIZE];
53} __packed;
54
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010055/* Response, followed by sense data and data-in */
56struct virtio_scsi_cmd_resp {
57 u32 sense_len; /* Sense data length */
58 u32 resid; /* Residual bytes in data buffer */
59 u16 status_qualifier; /* Status qualifier */
60 u8 status; /* Command completion status */
61 u8 response; /* Response values */
62 u8 sense[VIRTIO_SCSI_SENSE_SIZE];
63} __packed;
64
65/* Task Management Request */
66struct virtio_scsi_ctrl_tmf_req {
67 u32 type;
68 u32 subtype;
69 u8 lun[8];
70 u64 tag;
71} __packed;
72
73struct virtio_scsi_ctrl_tmf_resp {
74 u8 response;
75} __packed;
76
77/* Asynchronous notification query/subscription */
78struct virtio_scsi_ctrl_an_req {
79 u32 type;
80 u8 lun[8];
81 u32 event_requested;
82} __packed;
83
84struct virtio_scsi_ctrl_an_resp {
85 u32 event_actual;
86 u8 response;
87} __packed;
88
89struct virtio_scsi_event {
90 u32 event;
91 u8 lun[8];
92 u32 reason;
93} __packed;
94
95struct virtio_scsi_config {
96 u32 num_queues;
97 u32 seg_max;
98 u32 max_sectors;
99 u32 cmd_per_lun;
100 u32 event_info_size;
101 u32 sense_size;
102 u32 cdb_size;
103 u16 max_channel;
104 u16 max_target;
105 u32 max_lun;
106} __packed;
107
Cong Meng365a7152012-07-05 17:06:43 +0800108/* Feature Bits */
109#define VIRTIO_SCSI_F_INOUT 0
110#define VIRTIO_SCSI_F_HOTPLUG 1
Paolo Bonzini865b58c2012-10-02 17:25:48 +0200111#define VIRTIO_SCSI_F_CHANGE 2
Nicholas Bellinger1b49dcf2014-03-16 14:51:35 -0700112#define VIRTIO_SCSI_F_T10_PI 3
Cong Meng365a7152012-07-05 17:06:43 +0800113
Paolo Bonzini4fe74b12012-02-05 12:16:00 +0100114/* Response codes */
115#define VIRTIO_SCSI_S_OK 0
116#define VIRTIO_SCSI_S_OVERRUN 1
117#define VIRTIO_SCSI_S_ABORTED 2
118#define VIRTIO_SCSI_S_BAD_TARGET 3
119#define VIRTIO_SCSI_S_RESET 4
120#define VIRTIO_SCSI_S_BUSY 5
121#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
122#define VIRTIO_SCSI_S_TARGET_FAILURE 7
123#define VIRTIO_SCSI_S_NEXUS_FAILURE 8
124#define VIRTIO_SCSI_S_FAILURE 9
125#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
126#define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
127#define VIRTIO_SCSI_S_INCORRECT_LUN 12
128
129/* Controlq type codes. */
130#define VIRTIO_SCSI_T_TMF 0
131#define VIRTIO_SCSI_T_AN_QUERY 1
132#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
133
134/* Valid TMF subtypes. */
135#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
136#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
137#define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
138#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
139#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
140#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
141#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
142#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
143
144/* Events. */
145#define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
146#define VIRTIO_SCSI_T_NO_EVENT 0
147#define VIRTIO_SCSI_T_TRANSPORT_RESET 1
148#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
Paolo Bonzini865b58c2012-10-02 17:25:48 +0200149#define VIRTIO_SCSI_T_PARAM_CHANGE 3
Paolo Bonzini4fe74b12012-02-05 12:16:00 +0100150
Cong Meng365a7152012-07-05 17:06:43 +0800151/* Reasons of transport reset event */
152#define VIRTIO_SCSI_EVT_RESET_HARD 0
153#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
154#define VIRTIO_SCSI_EVT_RESET_REMOVED 2
155
Paolo Bonzini4fe74b12012-02-05 12:16:00 +0100156#define VIRTIO_SCSI_S_SIMPLE 0
157#define VIRTIO_SCSI_S_ORDERED 1
158#define VIRTIO_SCSI_S_HEAD 2
159#define VIRTIO_SCSI_S_ACA 3
160
161
162#endif /* _LINUX_VIRTIO_SCSI_H */