]> git.proxmox.com Git - mirror_qemu.git/blame - pc-bios/s390-ccw/scsi.h
pc-bios/s390-ccw: Get list of supported VPD pages
[mirror_qemu.git] / pc-bios / s390-ccw / scsi.h
CommitLineData
f7915614
ED
1/*
2 * SCSI definitions for s390 machine loader for qemu
3 *
4 * Copyright 2015 IBM Corp.
5 * Author: Eugene "jno" Dvurechenski <jno@linux.vnet.ibm.com>
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2 or (at
8 * your option) any later version. See the COPYING file in the top-level
9 * directory.
10 */
11
12#ifndef SCSI_H
13#define SCSI_H
14
15#include "s390-ccw.h"
16
17#define SCSI_DEFAULT_CDB_SIZE 32
18#define SCSI_DEFAULT_SENSE_SIZE 96
19
20#define CDB_STATUS_GOOD 0
21#define CDB_STATUS_CHECK_CONDITION 0x02U
22#define CDB_STATUS_VALID(status) (((status) & ~0x3eU) == 0)
23
24#define SCSI_SENSE_CODE_MASK 0x7fU
25#define SCSI_SENSE_KEY_MASK 0x0fU
26#define SCSI_SENSE_KEY_NO_SENSE 0
27#define SCSI_SENSE_KEY_UNIT_ATTENTION 6
28
9c12359c
EF
29/* SCSI Inquiry Types */
30#define SCSI_INQUIRY_STANDARD 0x00U
8edfe85b 31#define SCSI_INQUIRY_EVPD 0x01U
9c12359c
EF
32
33/* SCSI Inquiry Pages */
34#define SCSI_INQUIRY_STANDARD_NONE 0x00U
8edfe85b 35#define SCSI_INQUIRY_EVPD_SUPPORTED_PAGES 0x00U
9c12359c 36
f7915614
ED
37union ScsiLun {
38 uint64_t v64; /* numeric shortcut */
39 uint8_t v8[8]; /* generic 8 bytes representation */
40 uint16_t v16[4]; /* 4-level big-endian LUN as specified by SAM-2 */
41};
42typedef union ScsiLun ScsiLun;
43
44struct ScsiSense70 {
45 uint8_t b0; /* b0 & 7f = resp code (0x70 or 0x71) */
46 uint8_t b1, b2; /* b2 & 0f = sense key */
47 uint8_t u1[1 * 4 + 1 + 1 * 4]; /* b7 = N - 7 */
48 uint8_t additional_sense_code; /* b12 */
49 uint8_t additional_sense_code_qualifier; /* b13 */
50 uint8_t u2[1 + 3 + 0]; /* up to N (<=252) bytes */
51} __attribute__((packed));
52typedef struct ScsiSense70 ScsiSense70;
53
54/* don't confuse with virtio-scsi response/status fields! */
55
56static inline uint8_t scsi_sense_response(const void *p)
57{
58 return ((const ScsiSense70 *)p)->b0 & SCSI_SENSE_CODE_MASK;
59}
60
61static inline uint8_t scsi_sense_key(const void *p)
62{
63 return ((const ScsiSense70 *)p)->b2 & SCSI_SENSE_KEY_MASK;
64}
65
66#define SCSI_INQ_RDT_CDROM 0x05
67
68struct ScsiInquiryStd {
69 uint8_t peripheral_qdt; /* b0, use (b0 & 0x1f) to get SCSI_INQ_RDT */
70 uint8_t b1; /* Removable Media Bit = b1 & 0x80 */
71 uint8_t spc_version; /* b2 */
72 uint8_t b3; /* b3 & 0x0f == resp_data_fmt == 2, must! */
73 uint8_t u1[1 + 1 + 1 + 1 + 8]; /* b4..b15 unused, b4 = (N - 1) */
74 char prod_id[16]; /* "QEMU CD-ROM" is here */
75 uint8_t u2[4 /* b32..b35 unused, mandatory */
76 + 8 + 12 + 1 + 1 + 8 * 2 + 22 /* b36..95 unused, optional*/
77 + 0]; /* b96..bN unused, vendor specific */
78 /* byte N */
79} __attribute__((packed));
80typedef struct ScsiInquiryStd ScsiInquiryStd;
81
8edfe85b
EF
82struct ScsiInquiryEvpdPages {
83 uint8_t peripheral_qdt; /* b0, use (b0 & 0x1f) to get SCSI_INQ_RDT */
84 uint8_t page_code; /* b1 */
85 uint16_t page_length; /* b2..b3 length = N-3 */
86 uint8_t byte[28]; /* b4..bN Supported EVPD pages (N=31 here) */
87} __attribute__((packed));
88typedef struct ScsiInquiryEvpdPages ScsiInquiryEvpdPages;
89
f7915614
ED
90struct ScsiCdbInquiry {
91 uint8_t command; /* b0, == 0x12 */
92 uint8_t b1; /* b1, |= 0x01 (evpd) */
93 uint8_t b2; /* b2; if evpd==1 */
94 uint16_t alloc_len; /* b3, b4 */
95 uint8_t control; /* b5 */
96} __attribute__((packed));
97typedef struct ScsiCdbInquiry ScsiCdbInquiry;
98
99struct ScsiCdbRead10 {
100 uint8_t command; /* =0x28 */
101 uint8_t b1;
102 uint32_t lba;
103 uint8_t b6;
104 uint16_t xfer_length;
105 uint8_t control;
106} __attribute__((packed));
107typedef struct ScsiCdbRead10 ScsiCdbRead10;
108
109struct ScsiCdbTestUnitReady {
110 uint8_t command; /* =0x00 */
111 uint8_t b1_b4[4];
112 uint8_t control;
113} __attribute__((packed));
114typedef struct ScsiCdbTestUnitReady ScsiCdbTestUnitReady;
115
116struct ScsiCdbReportLuns {
117 uint8_t command; /* =0xa0 */
118 uint8_t b1;
119 uint8_t select_report; /* =0x02, "all" */
120 uint8_t b3_b5[3];
121 uint32_t alloc_len;
122 uint8_t b10;
123 uint8_t control;
124} __attribute__((packed));
125typedef struct ScsiCdbReportLuns ScsiCdbReportLuns;
126
127struct ScsiLunReport {
128 uint32_t lun_list_len;
129 uint32_t b4_b7;
130 ScsiLun lun[1]; /* space for at least 1 lun must be allocated */
131} __attribute__((packed));
132typedef struct ScsiLunReport ScsiLunReport;
133
134struct ScsiCdbReadCapacity16 {
135 uint8_t command; /* =0x9e = "service action in 16" */
136 uint8_t service_action; /* 5 bits, =0x10 = "read capacity 16" */
137 uint64_t b2_b9;
138 uint32_t alloc_len;
139 uint8_t b14;
140 uint8_t control;
141} __attribute__((packed));
142typedef struct ScsiCdbReadCapacity16 ScsiCdbReadCapacity16;
143
144struct ScsiReadCapacity16Data {
145 uint64_t ret_lba; /* get it, 0..7 */
146 uint32_t lb_len; /* bytes, 8..11 */
147 uint8_t u1[2 + 1 * 2 + 16]; /* b12..b31, unused */
148} __attribute__((packed));
149typedef struct ScsiReadCapacity16Data ScsiReadCapacity16Data;
150
151static inline ScsiLun make_lun(uint16_t channel, uint16_t target, uint32_t lun)
152{
153 ScsiLun r = { .v64 = 0 };
154
155 /* See QEMU code to choose the way to handle LUNs.
156 *
157 * So, a valid LUN must have (always channel #0):
158 * lun[0] == 1
159 * lun[1] - target, any value
160 * lun[2] == 0 or (LUN, MSB, 0x40 set, 0x80 clear)
161 * lun[3] - LUN, LSB, any value
162 */
163 r.v8[0] = 1;
164 r.v8[1] = target & 0xffU;
165 r.v8[2] = (lun >> 8) & 0x3fU;
166 if (r.v8[2]) {
167 r.v8[2] |= 0x40;
168 }
169 r.v8[3] = lun & 0xffU;
170
171 return r;
172}
173
174static inline const char *scsi_cdb_status_msg(uint8_t status)
175{
176 static char err_msg[] = "STATUS=XX";
177 uint8_t v = status & 0x3eU;
178
179 fill_hex_val(err_msg + 7, &v, 1);
180 return err_msg;
181}
182
183static inline const char *scsi_cdb_asc_msg(const void *s)
184{
185 static char err_msg[] = "RSPN=XX KEY=XX CODE=XX QLFR=XX";
186 const ScsiSense70 *p = s;
187 uint8_t sr = scsi_sense_response(s);
188 uint8_t sk = scsi_sense_key(s);
189 uint8_t ac = p->additional_sense_code;
190 uint8_t cq = p->additional_sense_code_qualifier;
191
192 fill_hex_val(err_msg + 5, &sr, 1);
193 fill_hex_val(err_msg + 12, &sk, 1);
194 fill_hex_val(err_msg + 20, &ac, 1);
195 fill_hex_val(err_msg + 28, &cq, 1);
196
197 return err_msg;
198}
199
200#endif /* SCSI_H */