Loading...
Searching...
No Matches
scsi.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019-2021 Mesotic SAS
3 * SPDX-License-Identifier: LGPL-2.1-only
4 */
5
6#pragma once
7
18
19#include "byteorder.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#ifndef USBUS_MSC_VENDOR_ID
26#define USBUS_MSC_VENDOR_ID "RIOT-OS"
27#endif /* USBUS_MSC_VENDOR_ID */
28
29#ifndef USBUS_MSC_PRODUCT_ID
30#define USBUS_MSC_PRODUCT_ID "RIOT_MSC_DISK "
31#endif /* USBUS_MSC_PRODUCT_ID */
32
33#ifndef USBUS_MSC_PRODUCT_REV
34#define USBUS_MSC_PRODUCT_REV " 1.0"
35#endif /* USBUS_MSC_PRODUCT_REV */
36
44#define SCSI_TEST_UNIT_READY 0x00
45#define SCSI_REQUEST_SENSE 0x03
46#define SCSI_FORMAT_UNIT 0x04
47#define SCSI_INQUIRY 0x12
48#define SCSI_MODE_SELECT6 0x15
49#define SCSI_MODE_SENSE6 0x1A
50#define SCSI_START_STOP_UNIT 0x1B
51#define SCSI_MEDIA_REMOVAL 0x1E
52#define SCSI_READ_FORMAT_CAPACITIES 0x23
53#define SCSI_READ_CAPACITY 0x25
54#define SCSI_READ10 0x28
55#define SCCI_READ12 0xA8
56#define SCSI_WRITE10 0x2A
57#define SCSI_WRITE12 0xAA
58#define SCSI_SEEK 0x2B
59#define SCSI_WRITE_AND_VERIFY 0x2E
60#define SCSI_VERIFY10 0x2F
61#define SCSI_MODE_SELECT10 0x55
62#define SCSI_MODE_SENSE10 0x5A
64
68#define SCSI_CBW_SIGNATURE 0x43425355
69
73#define SCSI_CSW_SIGNATURE 0x53425355
74
79#define SCSI_VERSION_NONE 0x0000
80#define SCSI_VERSION_SCSI1 0x0001
81#define SCSI_VERSION_SCSI2 0x0002
83
90#define SCSI_READ_FMT_CAPA_TYPE_RESERVED 0x00
91#define SCSI_READ_FMT_CAPA_TYPE_UNFORMATTED 0x01
92#define SCSI_READ_FMT_CAPA_TYPE_FORMATTED 0x02
93#define SCSI_READ_FMT_CAPA_TYPE_NO_MEDIA 0x03
95
99#define SCSI_REQUEST_SENSE_ERROR 0x70
100
106#define SCSI_SENSE_KEY_NO_SENSE 0x00
107#define SCSI_SENSE_KEY_RECOVERED_ERROR 0x01
108#define SCSI_SENSE_KEY_NOT_READY 0x02
109#define SCSI_SENSE_KEY_MEDIUM_ERROR 0x03
110#define SCSI_SENSE_KEY_HARDWARE_ERROR 0x04
111#define SCSI_SENSE_KEY_ILLEGAL_REQUEST 0x05
112#define SCSI_SENSE_KEY_UNIT_ATTENTION 0x06
113#define SCSI_SENSE_KEY_DATA_PROTECT 0x07
114#define SCSI_SENSE_KEY_BLANK_CHECK 0x08
115#define SCSI_SENSE_KEY_VENDOR_SPECIFIC 0x09
116#define SCSI_SENSE_KEY_ABORTED_COMMAND 0x0B
117#define SCSI_SENSE_KEY_VOLUME_OVERFLOW 0x0D
118#define SCSI_SENSE_KEY_MISCOMPARE 0x0E
120
126typedef struct __attribute__((packed)) {
127 uint8_t type;
128 uint8_t logical_unit;
129 uint8_t reserved[10];
131
138typedef struct __attribute__((packed)) {
140 uint8_t medium_type;
141 uint8_t flags;
144
153typedef struct __attribute__((packed)) {
154 uint8_t opcode;
155 uint8_t flags;
157 uint8_t group_number;
160
169typedef struct __attribute__((packed)) {
170 uint8_t type;
171 uint8_t reserved1 : 7;
172 uint8_t removable : 1;
173 uint8_t version;
174 uint8_t response_format : 4;
175 uint8_t reserved3 : 4;
176 uint8_t length;
177 uint8_t flags[3];
178 uint8_t vendor_id[8];
179 uint8_t product_id[16];
180 uint8_t product_rev[4];
182
189typedef struct __attribute__((packed)) {
190 uint8_t reserved1[3];
191 uint8_t list_length;
193 uint8_t type;
194 uint8_t blk_len[3];
196
201typedef struct __attribute__((packed)) {
202 uint8_t error_code;
203 uint8_t reserved1;
204 uint8_t sense_key;
205 uint8_t reserved2[4];
206 uint8_t add_len;
207 uint8_t reserved3[4];
208 uint8_t asc;
209 uint8_t ascq;
210 uint8_t fruc;
211 uint16_t sk_spec;
213
222typedef struct __attribute__((packed)) {
226
233typedef struct __attribute__((packed)) {
234 uint32_t signature;
235 uint32_t tag;
236 uint32_t data_len;
237 uint8_t flags;
238 uint8_t lun;
239 uint8_t cb_len;
240 uint8_t cb[16];
242
249typedef struct __attribute__((packed)) {
250 uint32_t signature;
251 uint32_t tag;
252 uint32_t data_left;
253 uint8_t status;
255
260typedef struct {
261 uint32_t tag;
262 size_t len;
263 uint8_t status;
264 uint8_t lun;
265} cbw_info_t;
266
276 size_t len);
277
285
286#ifdef __cplusplus
287}
288#endif
289
Functions to work with different byte orders.
struct usbdev_ep usbdev_ep_t
usbdev_ep_t forward declaration
Definition usbdev.h:96
struct usbus_handler usbus_handler_t
USBUS event handler forward declaration.
Definition usbus.h:220
struct usbus usbus_t
USBUS context forward declaration.
Definition usbus.h:215
void usbus_msc_scsi_process_cmd(usbus_t *usbus, usbus_handler_t *handler, usbdev_ep_t *ep, size_t len)
Process incoming Command Block Wrapper buffer.
void scsi_gen_csw(usbus_handler_t *handler, cbw_info_t *cmd)
Generate Command Status Wrapper and send it to the host.
USBUS Command Block Wrapper information.
Definition scsi.h:260
uint8_t status
Status of the current operation.
Definition scsi.h:263
size_t len
Remaining bytes to handle.
Definition scsi.h:262
uint8_t lun
Store LUN from CBW.
Definition scsi.h:264
uint32_t tag
Store tag information from CBW.
Definition scsi.h:261
Command Block Wrapper packet structure.
Definition scsi.h:233
uint32_t tag
ID for the current command.
Definition scsi.h:235
uint32_t signature
CBW signature (SCSI_CBW_SIGNATURE)
Definition scsi.h:234
uint8_t lun
Target Logical Unit Number.
Definition scsi.h:238
uint32_t data_len
Number of bytes host expects to transfer from/to.
Definition scsi.h:236
uint8_t cb[16]
Command block buffer.
Definition scsi.h:240
uint8_t flags
Command block flags.
Definition scsi.h:237
uint8_t cb_len
Length of the block in bytes (max: 16 bytes)
Definition scsi.h:239
CBW Packet structure for (SCSI_READ10) and (SCSI_WRITE10) requests.
Definition scsi.h:153
uint8_t group_number
Group number.
Definition scsi.h:157
uint8_t flags
Miscellaneous flags.
Definition scsi.h:155
be_uint32_t blk_addr
Block address.
Definition scsi.h:156
be_uint16_t xfer_len
Transfer length in bytes.
Definition scsi.h:158
uint8_t opcode
Operation code.
Definition scsi.h:154
Command Status Wrapper packet structure.
Definition scsi.h:249
uint32_t signature
CSW signature (SCSI_CSW_SIGNATURE)
Definition scsi.h:250
uint8_t status
Status of the command.
Definition scsi.h:253
uint32_t tag
ID for the answered CBW.
Definition scsi.h:251
uint32_t data_left
Indicate how many bytes from the CBW were not processed.
Definition scsi.h:252
Packet structure to answer (SCSI_INQUIRY) request.
Definition scsi.h:169
uint8_t product_rev[4]
Byte 35..32 Product Revision.
Definition scsi.h:180
uint8_t vendor_id[8]
Byte 15..8 Vendor Identification.
Definition scsi.h:178
uint8_t length
Byte 4 Additional Length (n-4)
Definition scsi.h:176
uint8_t removable
Byte 1 [B7] Removable device flag.
Definition scsi.h:172
uint8_t product_id[16]
Byte 31..16 Product Identification.
Definition scsi.h:179
uint8_t type
Byte 0 Peripheral type.
Definition scsi.h:170
uint8_t reserved1
Byte 1 [B6..B0] Reserved.
Definition scsi.h:171
uint8_t flags[3]
Byte 7..5 Miscellaneous flags UNUSED BY USBUS ONLY.
Definition scsi.h:177
uint8_t reserved3
Byte 3 [B7..B4] Reserved.
Definition scsi.h:175
uint8_t response_format
Byte 3 [B3..B0] Response Data Format.
Definition scsi.h:174
uint8_t version
Byte 2 SCSI Version.
Definition scsi.h:173
Packet structure to answer (SCSI_MODE_SELECT6) and (SCSI_MODE_SENSE6) requests.
Definition scsi.h:138
uint8_t medium_type
Type of medium.
Definition scsi.h:140
uint8_t mode_data_len
Size of the whole packet.
Definition scsi.h:139
uint8_t flags
Miscellaneous flags.
Definition scsi.h:141
uint8_t block_desc_len
Length of block descriptor.
Definition scsi.h:142
Packet structure to answer (SCSI_READ_CAPACITY) request.
Definition scsi.h:222
be_uint32_t last_blk
Indicate last block number.
Definition scsi.h:223
be_uint32_t blk_len
Total size of a block in bytes.
Definition scsi.h:224
Packet structure to answer (SCSI_READ_FORMAT_CAPACITIES) request.
Definition scsi.h:189
uint8_t type
Byte 8 Descriptor type.
Definition scsi.h:193
uint8_t blk_len[3]
Byte 11..9 Block length.
Definition scsi.h:194
uint8_t reserved1[3]
Byte 2..0 reserved.
Definition scsi.h:190
be_uint32_t blk_nb
Byte 7..4 Number of blocks.
Definition scsi.h:192
uint8_t list_length
Byte 3 Capacity list length.
Definition scsi.h:191
Packet structure to answer (SCSI_REQUEST_SENSE) request.
Definition scsi.h:201
uint8_t reserved2[4]
Byte 6..3 Information.
Definition scsi.h:205
uint16_t sk_spec
Byte 16..15 Sense Key Specific.
Definition scsi.h:211
uint8_t fruc
Byte 14 Field Replaceable Unit Code.
Definition scsi.h:210
uint8_t asc
Byte 12 Additional Sense Code.
Definition scsi.h:208
uint8_t ascq
Byte 13 Additional Sense Code Qualifier.
Definition scsi.h:209
uint8_t sense_key
Byte 2 Sense key.
Definition scsi.h:204
uint8_t reserved1
Reserved.
Definition scsi.h:203
uint8_t reserved3[4]
Byte 11..8 Vendor specific.
Definition scsi.h:207
uint8_t error_code
Byte 0 Error code.
Definition scsi.h:202
uint8_t add_len
Byte 7 Additional sense length.
Definition scsi.h:206
Packet structure to answer (SCSI_TEST_UNIT_READY) request.
Definition scsi.h:126
uint8_t reserved[10]
Reserved.
Definition scsi.h:129
uint8_t type
type of device
Definition scsi.h:127
uint8_t logical_unit
Selected LUN.
Definition scsi.h:128
USBUS context struct.
Definition usbus.h:444
A 16 bit integer in big endian aka network byte order.
Definition byteorder.h:70
A 32 bit integer in big endian aka network byte order.
Definition byteorder.h:80