blob: 42b9370771b014d4b959cd4c0c67a7bcc7eee41d [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
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020030#include <linux/virtio_types.h>
31
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010032#define VIRTIO_SCSI_CDB_SIZE 32
33#define VIRTIO_SCSI_SENSE_SIZE 96
34
35/* SCSI command request, followed by data-out */
36struct virtio_scsi_cmd_req {
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020037 __u8 lun[8]; /* Logical Unit Number */
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020038 __virtio64 tag; /* Command identifier */
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020039 __u8 task_attr; /* Task attribute */
40 __u8 prio; /* SAM command priority field */
41 __u8 crn;
42 __u8 cdb[VIRTIO_SCSI_CDB_SIZE];
43} __attribute__((packed));
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010044
Nicholas Bellinger1b49dcf2014-03-16 14:51:35 -070045/* SCSI command request, followed by protection information */
46struct virtio_scsi_cmd_req_pi {
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020047 __u8 lun[8]; /* Logical Unit Number */
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020048 __virtio64 tag; /* Command identifier */
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020049 __u8 task_attr; /* Task attribute */
50 __u8 prio; /* SAM command priority field */
51 __u8 crn;
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020052 __virtio32 pi_bytesout; /* DataOUT PI Number of bytes */
53 __virtio32 pi_bytesin; /* DataIN PI Number of bytes */
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020054 __u8 cdb[VIRTIO_SCSI_CDB_SIZE];
55} __attribute__((packed));
Nicholas Bellinger1b49dcf2014-03-16 14:51:35 -070056
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010057/* Response, followed by sense data and data-in */
58struct virtio_scsi_cmd_resp {
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020059 __virtio32 sense_len; /* Sense data length */
60 __virtio32 resid; /* Residual bytes in data buffer */
61 __virtio16 status_qualifier; /* Status qualifier */
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020062 __u8 status; /* Command completion status */
63 __u8 response; /* Response values */
64 __u8 sense[VIRTIO_SCSI_SENSE_SIZE];
65} __attribute__((packed));
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010066
67/* Task Management Request */
68struct virtio_scsi_ctrl_tmf_req {
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020069 __virtio32 type;
70 __virtio32 subtype;
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020071 __u8 lun[8];
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020072 __virtio64 tag;
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020073} __attribute__((packed));
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010074
75struct virtio_scsi_ctrl_tmf_resp {
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020076 __u8 response;
77} __attribute__((packed));
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010078
79/* Asynchronous notification query/subscription */
80struct virtio_scsi_ctrl_an_req {
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020081 __virtio32 type;
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020082 __u8 lun[8];
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020083 __virtio32 event_requested;
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020084} __attribute__((packed));
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010085
86struct virtio_scsi_ctrl_an_resp {
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020087 __virtio32 event_actual;
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020088 __u8 response;
89} __attribute__((packed));
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010090
91struct virtio_scsi_event {
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020092 __virtio32 event;
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020093 __u8 lun[8];
Michael S. Tsirkind75dff32014-11-23 17:28:57 +020094 __virtio32 reason;
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020095} __attribute__((packed));
Paolo Bonzini4fe74b12012-02-05 12:16:00 +010096
97struct virtio_scsi_config {
Michael S. Tsirkinfba7f022014-11-23 17:49:12 +020098 __u32 num_queues;
99 __u32 seg_max;
100 __u32 max_sectors;
101 __u32 cmd_per_lun;
102 __u32 event_info_size;
103 __u32 sense_size;
104 __u32 cdb_size;
105 __u16 max_channel;
106 __u16 max_target;
107 __u32 max_lun;
108} __attribute__((packed));
Paolo Bonzini4fe74b12012-02-05 12:16:00 +0100109
Cong Meng365a7152012-07-05 17:06:43 +0800110/* Feature Bits */
111#define VIRTIO_SCSI_F_INOUT 0
112#define VIRTIO_SCSI_F_HOTPLUG 1
Paolo Bonzini865b58c2012-10-02 17:25:48 +0200113#define VIRTIO_SCSI_F_CHANGE 2
Nicholas Bellinger1b49dcf2014-03-16 14:51:35 -0700114#define VIRTIO_SCSI_F_T10_PI 3
Cong Meng365a7152012-07-05 17:06:43 +0800115
Paolo Bonzini4fe74b12012-02-05 12:16:00 +0100116/* Response codes */
117#define VIRTIO_SCSI_S_OK 0
118#define VIRTIO_SCSI_S_OVERRUN 1
119#define VIRTIO_SCSI_S_ABORTED 2
120#define VIRTIO_SCSI_S_BAD_TARGET 3
121#define VIRTIO_SCSI_S_RESET 4
122#define VIRTIO_SCSI_S_BUSY 5
123#define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
124#define VIRTIO_SCSI_S_TARGET_FAILURE 7
125#define VIRTIO_SCSI_S_NEXUS_FAILURE 8
126#define VIRTIO_SCSI_S_FAILURE 9
127#define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
128#define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
129#define VIRTIO_SCSI_S_INCORRECT_LUN 12
130
131/* Controlq type codes. */
132#define VIRTIO_SCSI_T_TMF 0
133#define VIRTIO_SCSI_T_AN_QUERY 1
134#define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
135
136/* Valid TMF subtypes. */
137#define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
138#define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
139#define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
140#define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
141#define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
142#define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
143#define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
144#define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
145
146/* Events. */
147#define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
148#define VIRTIO_SCSI_T_NO_EVENT 0
149#define VIRTIO_SCSI_T_TRANSPORT_RESET 1
150#define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
Paolo Bonzini865b58c2012-10-02 17:25:48 +0200151#define VIRTIO_SCSI_T_PARAM_CHANGE 3
Paolo Bonzini4fe74b12012-02-05 12:16:00 +0100152
Cong Meng365a7152012-07-05 17:06:43 +0800153/* Reasons of transport reset event */
154#define VIRTIO_SCSI_EVT_RESET_HARD 0
155#define VIRTIO_SCSI_EVT_RESET_RESCAN 1
156#define VIRTIO_SCSI_EVT_RESET_REMOVED 2
157
Paolo Bonzini4fe74b12012-02-05 12:16:00 +0100158#define VIRTIO_SCSI_S_SIMPLE 0
159#define VIRTIO_SCSI_S_ORDERED 1
160#define VIRTIO_SCSI_S_HEAD 2
161#define VIRTIO_SCSI_S_ACA 3
162
163
164#endif /* _LINUX_VIRTIO_SCSI_H */