1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * This header is BSD licensed so anyone can use the definitions to implement
5 * compatible drivers/servers.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 *
28 * $FreeBSD$
29 */
30
31 #ifndef _VIRTIO_SCSI_H
32 #define _VIRTIO_SCSI_H
33
34 /* Default values of the CDB and sense data size configuration fields */
35 #define VIRTIO_SCSI_CDB_SIZE 32
36 #define VIRTIO_SCSI_SENSE_SIZE 96
37
38 /* SCSI command request, followed by data-out */
39 struct virtio_scsi_cmd_req {
40 uint8_t lun[8]; /* Logical Unit Number */
41 uint64_t tag; /* Command identifier */
42 uint8_t task_attr; /* Task attribute */
43 uint8_t prio; /* SAM command priority field */
44 uint8_t crn;
45 uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
46 } __packed;
47
48 /* SCSI command request, followed by protection information */
49 struct virtio_scsi_cmd_req_pi {
50 uint8_t lun[8]; /* Logical Unit Number */
51 uint64_t tag; /* Command identifier */
52 uint8_t task_attr; /* Task attribute */
53 uint8_t prio; /* SAM command priority field */
54 uint8_t crn;
55 uint32_t pi_bytesout; /* DataOUT PI Number of bytes */
56 uint32_t pi_bytesin; /* DataIN PI Number of bytes */
57 uint8_t cdb[VIRTIO_SCSI_CDB_SIZE];
58 } __packed;
59
60 /* Response, followed by sense data and data-in */
61 struct virtio_scsi_cmd_resp {
62 uint32_t sense_len; /* Sense data length */
63 uint32_t resid; /* Residual bytes in data buffer */
64 uint16_t status_qualifier; /* Status qualifier */
65 uint8_t status; /* Command completion status */
66 uint8_t response; /* Response values */
67 uint8_t sense[VIRTIO_SCSI_SENSE_SIZE];
68 } __packed;
69
70 /* Task Management Request */
71 struct virtio_scsi_ctrl_tmf_req {
72 uint32_t type;
73 uint32_t subtype;
74 uint8_t lun[8];
75 uint64_t tag;
76 } __packed;
77
78 struct virtio_scsi_ctrl_tmf_resp {
79 uint8_t response;
80 } __packed;
81
82 /* Asynchronous notification query/subscription */
83 struct virtio_scsi_ctrl_an_req {
84 uint32_t type;
85 uint8_t lun[8];
86 uint32_t event_requested;
87 } __packed;
88
89 struct virtio_scsi_ctrl_an_resp {
90 uint32_t event_actual;
91 uint8_t response;
92 } __packed;
93
94 struct virtio_scsi_event {
95 uint32_t event;
96 uint8_t lun[8];
97 uint32_t reason;
98 } __packed;
99
100 struct virtio_scsi_config {
101 uint32_t num_queues;
102 uint32_t seg_max;
103 uint32_t max_sectors;
104 uint32_t cmd_per_lun;
105 uint32_t event_info_size;
106 uint32_t sense_size;
107 uint32_t cdb_size;
108 uint16_t max_channel;
109 uint16_t max_target;
110 uint32_t max_lun;
111 } __packed;
112
113 /* Feature bits */
114 #define VIRTIO_SCSI_F_INOUT 0x0001 /* Single request can contain both
115 * read and write buffers.
116 */
117 #define VIRTIO_SCSI_F_HOTPLUG 0x0002 /* Host should enable hot plug/unplug
118 * of new LUNs and targets.
119 */
120 #define VIRTIO_SCSI_F_CHANGE 0x0004 /* Host will report changes to LUN
121 * parameters via a
122 * VIRTIO_SCSI_T_PARAM_CHANGE event.
123 */
124 #define VIRTIO_SCSI_F_T10_PI 0x0008 /* Extended fields for T10 protection
125 * information (DIF/DIX) are included
126 * in the SCSI request header.
127 */
128
129 /* Response codes */
130 #define VIRTIO_SCSI_S_OK 0
131 #define VIRTIO_SCSI_S_FUNCTION_COMPLETE 0
132 #define VIRTIO_SCSI_S_OVERRUN 1
133 #define VIRTIO_SCSI_S_ABORTED 2
134 #define VIRTIO_SCSI_S_BAD_TARGET 3
135 #define VIRTIO_SCSI_S_RESET 4
136 #define VIRTIO_SCSI_S_BUSY 5
137 #define VIRTIO_SCSI_S_TRANSPORT_FAILURE 6
138 #define VIRTIO_SCSI_S_TARGET_FAILURE 7
139 #define VIRTIO_SCSI_S_NEXUS_FAILURE 8
140 #define VIRTIO_SCSI_S_FAILURE 9
141 #define VIRTIO_SCSI_S_FUNCTION_SUCCEEDED 10
142 #define VIRTIO_SCSI_S_FUNCTION_REJECTED 11
143 #define VIRTIO_SCSI_S_INCORRECT_LUN 12
144
145 /* Controlq type codes. */
146 #define VIRTIO_SCSI_T_TMF 0
147 #define VIRTIO_SCSI_T_AN_QUERY 1
148 #define VIRTIO_SCSI_T_AN_SUBSCRIBE 2
149
150 /* Valid TMF subtypes. */
151 #define VIRTIO_SCSI_T_TMF_ABORT_TASK 0
152 #define VIRTIO_SCSI_T_TMF_ABORT_TASK_SET 1
153 #define VIRTIO_SCSI_T_TMF_CLEAR_ACA 2
154 #define VIRTIO_SCSI_T_TMF_CLEAR_TASK_SET 3
155 #define VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET 4
156 #define VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET 5
157 #define VIRTIO_SCSI_T_TMF_QUERY_TASK 6
158 #define VIRTIO_SCSI_T_TMF_QUERY_TASK_SET 7
159
160 /* Events. */
161 #define VIRTIO_SCSI_T_EVENTS_MISSED 0x80000000
162 #define VIRTIO_SCSI_T_NO_EVENT 0
163 #define VIRTIO_SCSI_T_TRANSPORT_RESET 1
164 #define VIRTIO_SCSI_T_ASYNC_NOTIFY 2
165 #define VIRTIO_SCSI_T_PARAM_CHANGE 3
166
167 /* Reasons of transport reset event */
168 #define VIRTIO_SCSI_EVT_RESET_HARD 0
169 #define VIRTIO_SCSI_EVT_RESET_RESCAN 1
170 #define VIRTIO_SCSI_EVT_RESET_REMOVED 2
171
172 #define VIRTIO_SCSI_S_SIMPLE 0
173 #define VIRTIO_SCSI_S_ORDERED 1
174 #define VIRTIO_SCSI_S_HEAD 2
175 #define VIRTIO_SCSI_S_ACA 3
176
177 #endif /* _VIRTIO_SCSI_H */
Cache object: 54c31c02b4e4ab8e11d48410f7742a91
|