vioscsi.h revision 1.2
1/*	$OpenBSD: vioscsi.h,v 1.2 2018/01/16 06:10:45 ccardenas 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_RESPONSE_FORMAT		0x02
42#define INQUIRY_VENDOR			"OpenBSD "
43#define INQUIRY_VENDOR_LEN		8
44#define INQUIRY_PRODUCT			"VMM CD-ROM      "
45#define INQUIRY_PRODUCT_LEN		16
46#define INQUIRY_REVISION		"001 "
47#define INQUIRY_REVISION_LEN		4
48
49#define MODE_MEDIUM_TYPE_CODE		0x70
50#define MODE_ERR_RECOVERY_PAGE_CODE	0x01
51#define MODE_ERR_RECOVERY_PAGE_LEN	0x0a
52#define MODE_READ_RETRY_COUNT		0x05
53#define MODE_CDVD_CAP_PAGE_CODE		0x2a
54#define MODE_CDVD_CAP_READ_CODE		0x08
55#define MODE_CDVD_CAP_NUM_LEVELS	0x02
56
57#define GESN_HEADER_LEN			0x06
58
59#define G_CONFIG_REPLY_SIZE		56
60#define G_CONFIG_REPLY_SIZE_HEX		0x0034
61
62#define RPL_MIN_SIZE			16
63
64/* Opcodes not defined in scsi */
65#define GET_EVENT_STATUS_NOTIFICATION	0x4a
66#define GET_CONFIGURATION		0x46
67#define READ_DISC_INFORMATION		0x51
68#define MECHANISM_STATUS		0xbd
69
70/* Sizes for reply structures */
71#define TOC_DATA_SIZE			20
72#define GESN_SIZE			8
73#define RESP_SENSE_LEN			14
74
75/* Structures for Opcodes defined locally */
76struct scsi_mechanism_status {
77	u_int8_t opcode;
78	u_int8_t unused[7];
79	u_int8_t length[2];
80	u_int8_t unused1;
81	u_int8_t control;
82};
83
84struct scsi_mechanism_status_header {
85	u_int8_t byte1;
86	u_int8_t byte2;
87	u_int8_t addr[3];
88	u_int8_t num_slots;
89	u_int8_t slot_len[2];
90};
91
92struct scsi_read_disc_information {
93	u_int8_t opcode;
94	u_int8_t byte2;
95	u_int8_t unused[5];
96	u_int8_t length[2];
97	u_int8_t control;
98};
99
100struct scsi_gesn {
101	u_int8_t opcode;
102	u_int8_t byte2;
103	u_int8_t unused[2];
104	u_int8_t notify_class;
105	u_int8_t unused1[2];
106	u_int8_t length[2];
107	u_int8_t control;
108};
109
110struct scsi_gesn_event_header {
111	u_int8_t length[2];
112	u_int8_t notification;
113#define GESN_NOTIFY_NONE		0x0
114#define GESN_NOTIFY_OP_CHANGE		0x1
115#define GESN_NOTIFY_POWER_MGMT		0x2
116#define GESN_NOTIFY_EXT_REQUEST		0x3
117#define GESN_NOTIFY_MEDIA		0x4
118#define GESN_NOTIFY_MULTIPLE_HOSTS	0x5
119#define GESN_NOTIFY_DEVICE_BUSY		0x6
120#define GESN_NOTIFY_RESERVED		0x7
121	u_int8_t supported_event;
122#define GESN_EVENT_NONE			0x1
123#define GESN_EVENT_OP_CHANGE		0x2
124#define GESN_EVENT_POWER_MGMT		0x4
125#define GESN_EVENT_EXT_REQUEST		0x8
126#define GESN_EVENT_MEDIA		0x10
127#define GESN_EVENT_MULTIPLE_HOSTS	0x20
128#define GESN_EVENT_DEVICE_BUSY		0x40
129#define GESN_EVENT_RESERVED		0x80
130};
131
132struct scsi_gesn_power_event {
133	u_int8_t event_code;
134#define GESN_CODE_NOCHG			0x0
135#define GESN_CODE_PWRCHG_SUCCESS	0x1
136#define GESN_CODE_PWRCHG_FAIL		0x2
137#define GESN_CODE_RESERVED		0x3
138	u_int8_t status;
139#define GESN_STATUS_RESERVED		0x0
140#define GESN_STATUS_ACTIVE		0x1
141#define GESN_STATUS_IDLE		0x2
142#define GESN_STATUS_STANDBY		0x3
143#define GESN_STATUS_SLEEP		0x4
144	u_int8_t unused[2];
145};
146
147struct scsi_get_configuration {
148	u_int8_t opcode;
149	u_int8_t byte2;
150	u_int8_t feature[2];
151	u_int8_t unused[3];
152	u_int8_t length[2];
153	u_int8_t control;
154};
155
156struct scsi_config_feature_header {
157	u_int8_t length[4];
158	u_int8_t unused[2];
159	u_int8_t current_profile[2];
160	/* Complete Profile List in MMC-5, 5.3.1, Table 89 */
161#define CONFIG_PROFILE_RESERVED		0x0000
162#define CONFIG_PROFILE_CD_ROM		0x0008
163#define CONFIG_PROFILE_NON_CONFORM	0xffff
164};
165
166struct scsi_config_generic_descriptor {
167	u_int8_t feature_code[2];
168	/* Complete Feature Code List in MMC-5, 5.2.3, Table 86 */
169#define CONFIG_FEATURE_CODE_PROFILE		0x0000
170#define CONFIG_FEATURE_CODE_CORE		0x0001
171#define CONFIG_FEATURE_CODE_MORPHING		0x0002
172#define CONFIG_FEATURE_CODE_REMOVE_MEDIA	0x0004
173#define CONFIG_FEATURE_CODE_RANDOM_READ		0x0010
174	u_int8_t byte3;
175#define CONFIG_PROFILELIST_BYTE3		0x03
176	u_int8_t length;
177#define CONFIG_PROFILELIST_LENGTH		0x04
178};
179
180struct scsi_config_profile_descriptor {
181	u_int8_t profile_number[2];
182	u_int8_t byte3;
183#define CONFIG_PROFILE_BYTE3			0x01
184	u_int8_t unused;
185};
186
187struct scsi_config_core_descriptor {
188	u_int8_t feature_code[2];
189	u_int8_t byte3;
190#define CONFIG_CORE_BYTE3		0x11
191	u_int8_t length;
192#define CONFIG_CORE_LENGTH		0x08
193	u_int8_t phy_std[4];
194	/* Complete PHYs List in MMC-5, 5.3.2, Table 91 */
195#define CONFIG_CORE_PHY_SCSI		0x00000001
196	u_int8_t unused[4];
197};
198
199struct scsi_config_morphing_descriptor {
200	u_int8_t feature_code[2];
201	u_int8_t byte3;
202#define CONFIG_MORPHING_BYTE3		0x07
203	u_int8_t length;
204#define CONFIG_MORPHING_LENGTH		0x04
205	/* OCE (bit 1), always set and ASYNC (bit 0) Bit */
206	u_int8_t byte5;
207#define CONFIG_MORPHING_BYTE5		0x2
208	u_int8_t unused[3];
209};
210
211struct scsi_config_remove_media_descriptor {
212	u_int8_t feature_code[2];
213	u_int8_t byte3;
214#define CONFIG_REMOVE_MEDIA_BYTE3	0x03
215	u_int8_t length;
216#define CONFIG_REMOVE_MEDIA_LENGTH	0x04
217	/* Ejection Type */
218	u_int8_t byte5;
219#define CONFIG_REMOVE_MEDIA_BYTE5	0x09
220	u_int8_t unused[3];
221};
222
223struct scsi_config_random_read_descriptor {
224	u_int8_t feature_code[2];
225	u_int8_t byte3;
226#define CONFIG_RANDOM_READ_BYTE3	0x03
227	u_int8_t length;
228#define CONFIG_RANDOM_READ_LENGTH	0x08
229	u_int8_t block_size[4];
230	u_int8_t blocking_type[2];
231#define CONFIG_RANDOM_READ_BLOCKING_TYPE	0x0010
232	u_int8_t unused[2];
233};
234
235/*
236 * Variant of scsi_report_luns_data in scsi_all.h
237 * but with only one lun in the lun list
238 */
239struct vioscsi_report_luns_data {
240	u_int8_t length[4];
241	u_int8_t reserved[4];
242#define RPL_SINGLE_LUN			8
243	u_int8_t lun[RPL_SINGLE_LUN];
244};
245