xref: /openbsd/usr.sbin/vmd/vioscsi.h (revision a1f20724)
1 /*	$OpenBSD: vioscsi.h,v 1.3 2020/09/03 13:11:49 krw Exp $  */
2 
3 /*
4  * Copyright (c) 2017 Carlos Cardenas <ccardenas@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /* Constants */
20 #define VIOSCSI_SEG_MAX			17
21 #define VIOSCSI_CDB_LEN			32
22 #define VIOSCSI_SENSE_LEN		96
23 
24 #define VIOSCSI_NUM_QUEUES		1
25 #define VIOSCSI_CMD_PER_LUN		1
26 #define VIOSCSI_MAX_TARGET		1
27 #define VIOSCSI_MAX_LUN			1
28 
29 #define VIOSCSI_BLOCK_SIZE_CDROM	2048
30 
31 #define READ_TOC_START_TRACK		0x01
32 #define READ_TOC_LAST_TRACK		0x01
33 #define READ_TOC_LEAD_OUT_TRACK		0xaa
34 #define READ_TOC_ADR_CTL		0x14
35 
36 #define SENSE_DEFAULT_ASCQ		0x00
37 #define SENSE_LBA_OUT_OF_RANGE		0x21
38 #define SENSE_ILLEGAL_CDB_FIELD		0x24
39 #define SENSE_MEDIUM_NOT_PRESENT	0x3a
40 
41 #define INQUIRY_VENDOR			"OpenBSD "
42 #define INQUIRY_VENDOR_LEN		8
43 #define INQUIRY_PRODUCT			"VMM CD-ROM      "
44 #define INQUIRY_PRODUCT_LEN		16
45 #define INQUIRY_REVISION		"001 "
46 #define INQUIRY_REVISION_LEN		4
47 
48 #define MODE_MEDIUM_TYPE_CODE		0x70
49 #define MODE_ERR_RECOVERY_PAGE_CODE	0x01
50 #define MODE_ERR_RECOVERY_PAGE_LEN	0x0a
51 #define MODE_READ_RETRY_COUNT		0x05
52 #define MODE_CDVD_CAP_PAGE_CODE		0x2a
53 #define MODE_CDVD_CAP_READ_CODE		0x08
54 #define MODE_CDVD_CAP_NUM_LEVELS	0x02
55 
56 #define GESN_HEADER_LEN			0x06
57 
58 #define G_CONFIG_REPLY_SIZE		56
59 #define G_CONFIG_REPLY_SIZE_HEX		0x0034
60 
61 #define RPL_MIN_SIZE			16
62 
63 /* Opcodes not defined in scsi */
64 #define GET_EVENT_STATUS_NOTIFICATION	0x4a
65 #define GET_CONFIGURATION		0x46
66 #define READ_DISC_INFORMATION		0x51
67 #define MECHANISM_STATUS		0xbd
68 
69 /* Sizes for reply structures */
70 #define TOC_DATA_SIZE			20
71 #define GESN_SIZE			8
72 #define RESP_SENSE_LEN			14
73 
74 /* Structures for Opcodes defined locally */
75 struct scsi_mechanism_status {
76 	u_int8_t opcode;
77 	u_int8_t unused[7];
78 	u_int8_t length[2];
79 	u_int8_t unused1;
80 	u_int8_t control;
81 };
82 
83 struct scsi_mechanism_status_header {
84 	u_int8_t byte1;
85 	u_int8_t byte2;
86 	u_int8_t addr[3];
87 	u_int8_t num_slots;
88 	u_int8_t slot_len[2];
89 };
90 
91 struct scsi_read_disc_information {
92 	u_int8_t opcode;
93 	u_int8_t byte2;
94 	u_int8_t unused[5];
95 	u_int8_t length[2];
96 	u_int8_t control;
97 };
98 
99 struct scsi_gesn {
100 	u_int8_t opcode;
101 	u_int8_t byte2;
102 	u_int8_t unused[2];
103 	u_int8_t notify_class;
104 	u_int8_t unused1[2];
105 	u_int8_t length[2];
106 	u_int8_t control;
107 };
108 
109 struct scsi_gesn_event_header {
110 	u_int8_t length[2];
111 	u_int8_t notification;
112 #define GESN_NOTIFY_NONE		0x0
113 #define GESN_NOTIFY_OP_CHANGE		0x1
114 #define GESN_NOTIFY_POWER_MGMT		0x2
115 #define GESN_NOTIFY_EXT_REQUEST		0x3
116 #define GESN_NOTIFY_MEDIA		0x4
117 #define GESN_NOTIFY_MULTIPLE_HOSTS	0x5
118 #define GESN_NOTIFY_DEVICE_BUSY		0x6
119 #define GESN_NOTIFY_RESERVED		0x7
120 	u_int8_t supported_event;
121 #define GESN_EVENT_NONE			0x1
122 #define GESN_EVENT_OP_CHANGE		0x2
123 #define GESN_EVENT_POWER_MGMT		0x4
124 #define GESN_EVENT_EXT_REQUEST		0x8
125 #define GESN_EVENT_MEDIA		0x10
126 #define GESN_EVENT_MULTIPLE_HOSTS	0x20
127 #define GESN_EVENT_DEVICE_BUSY		0x40
128 #define GESN_EVENT_RESERVED		0x80
129 };
130 
131 struct scsi_gesn_power_event {
132 	u_int8_t event_code;
133 #define GESN_CODE_NOCHG			0x0
134 #define GESN_CODE_PWRCHG_SUCCESS	0x1
135 #define GESN_CODE_PWRCHG_FAIL		0x2
136 #define GESN_CODE_RESERVED		0x3
137 	u_int8_t status;
138 #define GESN_STATUS_RESERVED		0x0
139 #define GESN_STATUS_ACTIVE		0x1
140 #define GESN_STATUS_IDLE		0x2
141 #define GESN_STATUS_STANDBY		0x3
142 #define GESN_STATUS_SLEEP		0x4
143 	u_int8_t unused[2];
144 };
145 
146 struct scsi_get_configuration {
147 	u_int8_t opcode;
148 	u_int8_t byte2;
149 	u_int8_t feature[2];
150 	u_int8_t unused[3];
151 	u_int8_t length[2];
152 	u_int8_t control;
153 };
154 
155 struct scsi_config_feature_header {
156 	u_int8_t length[4];
157 	u_int8_t unused[2];
158 	u_int8_t current_profile[2];
159 	/* Complete Profile List in MMC-5, 5.3.1, Table 89 */
160 #define CONFIG_PROFILE_RESERVED		0x0000
161 #define CONFIG_PROFILE_CD_ROM		0x0008
162 #define CONFIG_PROFILE_NON_CONFORM	0xffff
163 };
164 
165 struct scsi_config_generic_descriptor {
166 	u_int8_t feature_code[2];
167 	/* Complete Feature Code List in MMC-5, 5.2.3, Table 86 */
168 #define CONFIG_FEATURE_CODE_PROFILE		0x0000
169 #define CONFIG_FEATURE_CODE_CORE		0x0001
170 #define CONFIG_FEATURE_CODE_MORPHING		0x0002
171 #define CONFIG_FEATURE_CODE_REMOVE_MEDIA	0x0004
172 #define CONFIG_FEATURE_CODE_RANDOM_READ		0x0010
173 	u_int8_t byte3;
174 #define CONFIG_PROFILELIST_BYTE3		0x03
175 	u_int8_t length;
176 #define CONFIG_PROFILELIST_LENGTH		0x04
177 };
178 
179 struct scsi_config_profile_descriptor {
180 	u_int8_t profile_number[2];
181 	u_int8_t byte3;
182 #define CONFIG_PROFILE_BYTE3			0x01
183 	u_int8_t unused;
184 };
185 
186 struct scsi_config_core_descriptor {
187 	u_int8_t feature_code[2];
188 	u_int8_t byte3;
189 #define CONFIG_CORE_BYTE3		0x11
190 	u_int8_t length;
191 #define CONFIG_CORE_LENGTH		0x08
192 	u_int8_t phy_std[4];
193 	/* Complete PHYs List in MMC-5, 5.3.2, Table 91 */
194 #define CONFIG_CORE_PHY_SCSI		0x00000001
195 	u_int8_t unused[4];
196 };
197 
198 struct scsi_config_morphing_descriptor {
199 	u_int8_t feature_code[2];
200 	u_int8_t byte3;
201 #define CONFIG_MORPHING_BYTE3		0x07
202 	u_int8_t length;
203 #define CONFIG_MORPHING_LENGTH		0x04
204 	/* OCE (bit 1), always set and ASYNC (bit 0) Bit */
205 	u_int8_t byte5;
206 #define CONFIG_MORPHING_BYTE5		0x2
207 	u_int8_t unused[3];
208 };
209 
210 struct scsi_config_remove_media_descriptor {
211 	u_int8_t feature_code[2];
212 	u_int8_t byte3;
213 #define CONFIG_REMOVE_MEDIA_BYTE3	0x03
214 	u_int8_t length;
215 #define CONFIG_REMOVE_MEDIA_LENGTH	0x04
216 	/* Ejection Type */
217 	u_int8_t byte5;
218 #define CONFIG_REMOVE_MEDIA_BYTE5	0x09
219 	u_int8_t unused[3];
220 };
221 
222 struct scsi_config_random_read_descriptor {
223 	u_int8_t feature_code[2];
224 	u_int8_t byte3;
225 #define CONFIG_RANDOM_READ_BYTE3	0x03
226 	u_int8_t length;
227 #define CONFIG_RANDOM_READ_LENGTH	0x08
228 	u_int8_t block_size[4];
229 	u_int8_t blocking_type[2];
230 #define CONFIG_RANDOM_READ_BLOCKING_TYPE	0x0010
231 	u_int8_t unused[2];
232 };
233 
234 /*
235  * Variant of scsi_report_luns_data in scsi_all.h
236  * but with only one lun in the lun list
237  */
238 struct vioscsi_report_luns_data {
239 	u_int8_t length[4];
240 	u_int8_t reserved[4];
241 #define RPL_SINGLE_LUN			8
242 	u_int8_t lun[RPL_SINGLE_LUN];
243 };
244