RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
scsi.h
浏览该文件的文档.
1/*
2 * Copyright (c) 2006-2023, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2023-02-25 GuEe-GUI the first version
9 */
10
11#ifndef __SCSI_H__
12#define __SCSI_H__
13
14#include <rthw.h>
15#include <rtthread.h>
16#include <drivers/byteorder.h>
17
18#define RT_SCSI_LUN_SHIFT 5
19
20rt_packed(struct rt_scsi_unknow
21{
22 rt_uint8_t opcode;
23});
24
26{
27 rt_uint8_t opcode;
28 rt_uint8_t reserved[4];
29 rt_uint8_t control;
30 rt_uint8_t pad[6]; /* To be ATAPI compatible */
31});
32
34{
35 rt_uint8_t opcode;
36 rt_uint8_t config; /* 7-2 Reserved, 1 Obsolete Formerly CMDDT, 0 EVPD */
37 rt_uint8_t page; /* Page code if EVPD=1 */
38 rt_uint8_t reserved;
39 rt_uint8_t alloc_length;
40 rt_uint8_t control;
41 rt_uint8_t pad[6]; /* To be ATAPI compatible */
42});
43
44rt_packed(struct rt_scsi_inquiry_data
45{
46#define RT_SCSI_DEVTYPE_MASK 31
47 rt_uint8_t devtype;
48#define RT_SCSI_REMOVABLE_BIT 7
49 rt_uint8_t rmb;
50 rt_uint8_t reserved[2];
51 rt_uint8_t length;
52 rt_uint8_t reserved1[3];
53 char vendor[8];
54 char prodid[16];
55 char prodrev[4];
56});
57
59{
60 rt_uint8_t opcode;
61 rt_uint8_t config; /* 7-2 Reserved, 1 Obsolete, 0 SP */
62 rt_uint8_t reserved[2];
63 rt_uint8_t alloc_length;
64 rt_uint8_t control;
65 rt_uint8_t pad[6]; /* To be ATAPI compatible */
66});
67
68rt_packed(struct rt_scsi_request_sense_data
69{
70 rt_uint8_t error_code; /* 7 Valid, 6-0 Err. code */
71 rt_uint8_t segment_number;
72 rt_uint8_t sense_key; /* 7 FileMark, 6 EndOfMedia, 5 ILI, 4-0 sense key */
73 rt_be32_t information;
74 rt_uint8_t additional_sense_length;
75 rt_be32_t cmd_specific_info;
76 rt_uint8_t additional_sense_code;
77 rt_uint8_t additional_sense_code_qualifier;
78 rt_uint8_t field_replaceable_unit_code;
79 rt_uint8_t sense_key_specific[3];
80});
81
83{
84 rt_uint8_t opcode;
85 rt_uint8_t config; /* 7-1 Reserved, 0 Obsolete */
86 rt_be32_t logical_block_addr; /* only if PMI=1 */
87 rt_uint8_t reserved[2];
88 rt_uint8_t pmi;
89 rt_uint8_t control;
90 rt_be16_t pad; /* To be ATAPI compatible */
91});
92
93rt_packed(struct rt_scsi_read_capacity10_data
94{
95 rt_be32_t last_block;
96 rt_be32_t block_size;
97});
98
100{
101 rt_uint8_t opcode;
102 rt_uint8_t config; /* 7-5 Reserved, 4-0 SERVICE ACTION 0x10 */
103 rt_be64_t logical_block_addr; /* only if PMI=1 */
104 rt_be32_t alloc_len;
105 rt_uint8_t pmi;
106 rt_uint8_t control;
107});
108
109rt_packed(struct rt_scsi_read_capacity16_data
110{
111 rt_be64_t last_block;
112 rt_be32_t block_size;
113 rt_uint8_t pad[20];
114});
115
117{
118 rt_uint8_t opcode;
119 rt_uint8_t config; /* 7-5 RDPROTECT, 4 DPO, 3 FUA, 2 RARC, 1 Obsolete, 0 Obsolete */
120 rt_be32_t lba;
121 rt_uint8_t reserved;
122 rt_be16_t size;
123 rt_uint8_t reserved2;
124 rt_be16_t pad;
125});
126
128{
129 rt_uint8_t opcode;
130 rt_uint8_t config; /* 7-5 RDPROTECT, 4 DPO, 3 FUA, 2 RARC, 1 Obsolete, 0 Obsolete */
131 rt_be32_t lba;
132 rt_be32_t size;
133 rt_uint8_t reserved;
134 rt_uint8_t control;
135});
136
138{
139 rt_uint8_t opcode;
140 rt_uint8_t config; /* 7-5 RDPROTECT, 4 DPO, 3 FUA, 2 RARC, 1 Obsolete, 0 DLD2 */
141 rt_be64_t lba;
142 rt_be32_t size;
143 rt_uint8_t reserved;
144 rt_uint8_t control;
145});
146
148{
149 rt_uint8_t opcode;
150 rt_uint8_t config; /* 7-5 WRPROTECT, 4 DPO, 3 FUA, 2 Reserved, 1 Obsolete, 0 Obsolete */
151 rt_be32_t lba;
152 rt_uint8_t reserved;
153 rt_be16_t size;
154 rt_uint8_t reserved2;
155 rt_be16_t pad;
156});
157
159{
160 rt_uint8_t opcode;
161 rt_uint8_t config; /* 7-5 WRPROTECT, 4 DPO, 3 FUA, 2 Reserved, 1 Obsolete, 0 Obsolete */
162 rt_be32_t lba;
163 rt_be32_t size;
164 rt_uint8_t reserved;
165 rt_uint8_t control;
166});
167
169{
170 rt_uint8_t opcode;
171 rt_uint8_t config; /* 7-5 WRPROTECT, 4 DPO, 3 FUA, 2 Reserved, 1 Obsolete, 0 DLD2 */
172 rt_be64_t lba;
173 rt_be32_t size;
174 rt_uint8_t reserved;
175 rt_uint8_t control;
176});
177
179{
180 rt_uint8_t opcode;
181 rt_uint8_t config; /* 7-3 Reserved, 2 Obsolete, 1 IMMED, 0 Obsolete */
182 rt_be32_t lba;
183 rt_uint8_t reserved;
184 rt_be16_t size;
185 rt_uint8_t control;
186});
187
189{
190 rt_uint8_t opcode;
191 rt_uint8_t config; /* 7-3 Reserved, 2 Obsolete, 1 IMMED, 0 Obsolete */
192 rt_be64_t lba;
193 rt_be32_t size;
194 rt_uint8_t reserved;
195 rt_uint8_t control;
196});
197
198#define RT_SCSI_UNMAP_SHIFT 3
199
201{
202 rt_uint8_t opcode;
203 rt_uint8_t config; /* 7-5 WRPROTECT, 4 ANCHOR, 3 UNMAP, 2 Obsolete, 1 Obsolete, 0 Obsolete */
204 rt_be32_t lba;
205 rt_uint8_t reserved;
206 rt_be16_t size;
207 rt_uint8_t control;
208});
209
211{
212 rt_uint8_t opcode;
213 rt_uint8_t config; /* 7-5 WRPROTECT, 4 ANCHOR, 3 UNMAP, 2 Obsolete, 1 Obsolete, 0 NDOB */
214 rt_be64_t lba;
215 rt_be32_t size;
216 rt_uint8_t reserved;
217 rt_uint8_t control;
218});
219
220#define RT_SCSI_PF_SHIFT 4
221#define RT_SCSI_RTD_SHIFT 1
222#define RT_SCSI_SP_SHIFT 0
223
225{
226 rt_uint8_t opcode;
227 rt_uint8_t config; /* 7-5 Reserved, 4 PF, 3-2 Reserved, 1 RTD, 0 SP */
228 rt_uint8_t reserved[2];
229 rt_uint8_t param_list_len;
230 rt_uint8_t control;
231});
232
234{
235 rt_uint8_t opcode;
236 rt_uint8_t config; /* 7-5 Reserved, 4 PF, 3-1 Reserved, 0 SP */
237 rt_uint8_t reserved[5];
238 rt_be16_t param_list_len;
239 rt_uint8_t control;
240});
241
251
252#define RT_SCSI_DBD_SHIFT 3
253#define RT_SCSI_LLBAA_SHIFT 4
254#define RT_SCSI_PC_SHIFT 6
255#define RT_SCSI_PAGE_CODE_SHIFT 0
256
258{
259 rt_uint8_t opcode;
260 rt_uint8_t config; /* 7-4 Reserved, 3 DBD, 2-0 Reserved */
261 rt_uint8_t page_control_code;
262 rt_uint8_t subpage_code;
263 rt_uint8_t allocation_len;
264 rt_uint8_t control;
265});
266
268{
269 rt_uint8_t opcode;
270 rt_uint8_t config; /* 7-5 Reserved, 4 LLBAA, 3 DBD, 2-0 Reserved */
271 rt_uint8_t page_control_code;
272 rt_uint8_t subpage_code;
273 rt_uint8_t reserved[3];
274 rt_be16_t allocation_len;
275 rt_uint8_t control;
276});
277
278#define RT_SCSI_CMD_TEST_UNIT_READY 0x00
279#define RT_SCSI_CMD_REQUEST_SENSE 0x03
280#define RT_SCSI_CMD_INQUIRY 0x12
281#define RT_SCSI_CMD_MODE_SELECT 0x15
282#define RT_SCSI_CMD_MODE_SENSE 0x1a
283#define RT_SCSI_CMD_READ_CAPACITY10 0x25
284#define RT_SCSI_CMD_READ10 0x28
285#define RT_SCSI_CMD_WRITE10 0x2a
286#define RT_SCSI_CMD_SYNCHRONIZE_CACHE10 0x35
287#define RT_SCSI_CMD_WRITE_SAME10 0x41
288#define RT_SCSI_CMD_MODE_SELECT10 0x55
289#define RT_SCSI_CMD_MODE_SENSE10 0x5a
290#define RT_SCSI_CMD_READ16 0x88
291#define RT_SCSI_CMD_WRITE16 0x8a
292#define RT_SCSI_CMD_SYNCHRONIZE_CACHE16 0x91
293#define RT_SCSI_CMD_WRITE_SAME16 0x93
294#define RT_SCSI_CMD_READ_CAPACITY16 0x9e
295#define RT_SCSI_CMD_READ12 0xa8
296#define RT_SCSI_CMD_WRITE12 0xaa
297
341
342enum
343{
344 SCSI_DEVICE_TYPE_DIRECT = 0x00, /* DiskPeripheral (GenDisk) */
345 SCSI_DEVICE_TYPE_SEQUENTIAL = 0x01, /* TapePeripheral */
346 SCSI_DEVICE_TYPE_PRINTER = 0x02, /* PrinterPeripheral (GenPrinter) */
347 SCSI_DEVICE_TYPE_PROCESSOR = 0x03, /* OtherPeripheral */
348 SCSI_DEVICE_TYPE_WRITE_ONCE_READ_MULTIPLE = 0x04, /* WormPeripheral (GenWorm) */
349 SCSI_DEVICE_TYPE_CDROM = 0x05, /* CdRomPeripheral (GenCdRom) */
350 SCSI_DEVICE_TYPE_SCANNER = 0x06, /* ScannerPeripheral (GenScanner) */
351 SCSI_DEVICE_TYPE_OPTICAL = 0x07, /* OpticalDiskPeripheral (GenOptical) */
352 SCSI_DEVICE_TYPE_MEDIUM_CHANGER = 0x08, /* MediumChangerPeripheral (ScsiChanger) */
353 SCSI_DEVICE_TYPE_COMMUNICATION = 0x09, /* CommunicationsPeripheral (ScsiNet) */
354 SCSI_DEVICE_TYPE_ASC_PREPRESS_GRAPHICS10 = 0x0a, /* ASCPrePressGraphicsPeripheral (ScsiASCIT8) */
355 SCSI_DEVICE_TYPE_ASC_PREPRESS_GRAPHICS11 = 0x0b, /* ASCPrePressGraphicsPeripheral (ScsiASCIT8) */
356 SCSI_DEVICE_TYPE_ARRAY = 0x0c, /* ArrayPeripheral (ScsiArray) */
357 SCSI_DEVICE_TYPE_ENCLOSURE = 0x0d, /* EnclosurePeripheral (ScsiEnclosure) */
358 SCSI_DEVICE_TYPE_RBC = 0x0e, /* RBCPeripheral (ScsiRBC) */
359 SCSI_DEVICE_TYPE_CARDREADER = 0x0f, /* CardReaderPeripheral (ScsiCardReader) */
360 SCSI_DEVICE_TYPE_BRIDGE = 0x10, /* BridgePeripheral (ScsiBridge) */
361 SCSI_DEVICE_TYPE_OTHER = 0x11, /* OtherPeripheral (ScsiOther) */
363};
364
365struct rt_scsi_ops;
366
378
394
396{
397 rt_err_t (*reset)(struct rt_scsi_device *sdev);
398 rt_err_t (*transfer)(struct rt_scsi_device *sdev, struct rt_scsi_cmd *cmd);
399};
400
403
405{
406 return cmd->op.write10.opcode == RT_SCSI_CMD_WRITE10 ||
407 cmd->op.write12.opcode == RT_SCSI_CMD_WRITE16 ||
408 cmd->op.write16.opcode == RT_SCSI_CMD_WRITE12;
409}
410
412 struct rt_scsi_request_sense_data *out_data);
413
416 struct rt_scsi_inquiry_data *out_data);
417
419 struct rt_scsi_read_capacity10_data *out_data);
421 struct rt_scsi_read_capacity16_data *out_data);
422
424 rt_off_t lba, void *buffer, rt_size_t size);
426 rt_off_t lba, void *buffer, rt_size_t size);
428 rt_off_t lba, void *buffer, rt_size_t size);
429
431 rt_off_t lba, const void *buffer, rt_size_t size);
433 rt_off_t lba, const void *buffer, rt_size_t size);
435 rt_off_t lba, const void *buffer, rt_size_t size);
436
438 rt_off_t lba, rt_size_t size);
440 rt_off_t lba, rt_size_t size);
441
443 rt_off_t lba, rt_size_t size);
445 rt_off_t lba, rt_size_t size);
446
448 rt_uint8_t pf, rt_uint8_t sp, void *buffer, rt_size_t size,
451 rt_uint8_t pf, rt_uint8_t sp, void *buffer, rt_size_t size,
453
455 rt_uint8_t dbd, rt_uint8_t modepage, rt_uint8_t subpage, void *buffer, rt_size_t size,
458 rt_uint8_t dbd, rt_uint8_t modepage, rt_uint8_t subpage, void *buffer, rt_size_t size,
460
461#endif /* __SCSI_H__ */
rt_uint64_t __bitwise rt_be64_t
rt_uint16_t __bitwise rt_be16_t
rt_uint32_t __bitwise rt_be32_t
rt_base_t rt_off_t
int rt_bool_t
rt_base_t rt_err_t
unsigned char rt_uint8_t
unsigned short rt_uint16_t
rt_ubase_t rt_size_t
struct rt_list_node rt_list_t
unsigned int rt_uint32_t
rt_err_t rt_scsi_write16(struct rt_scsi_device *sdev, rt_off_t lba, const void *buffer, rt_size_t size)
#define RT_SCSI_CMD_WRITE10
定义 scsi.h:285
rt_inline rt_bool_t rt_scsi_cmd_is_write(struct rt_scsi_cmd *cmd)
定义 scsi.h:404
rt_err_t rt_scsi_host_register(struct rt_scsi_host *scsi)
rt_err_t rt_scsi_synchronize_cache10(struct rt_scsi_device *sdev, rt_off_t lba, rt_size_t size)
@ SCSI_DEVICE_TYPE_OTHER
定义 scsi.h:361
@ SCSI_DEVICE_TYPE_MAX
定义 scsi.h:362
@ SCSI_DEVICE_TYPE_RBC
定义 scsi.h:358
@ SCSI_DEVICE_TYPE_PRINTER
定义 scsi.h:346
@ SCSI_DEVICE_TYPE_ARRAY
定义 scsi.h:356
@ SCSI_DEVICE_TYPE_COMMUNICATION
定义 scsi.h:353
@ SCSI_DEVICE_TYPE_SCANNER
定义 scsi.h:350
@ SCSI_DEVICE_TYPE_BRIDGE
定义 scsi.h:360
@ SCSI_DEVICE_TYPE_ASC_PREPRESS_GRAPHICS11
定义 scsi.h:355
@ SCSI_DEVICE_TYPE_PROCESSOR
定义 scsi.h:347
@ SCSI_DEVICE_TYPE_ENCLOSURE
定义 scsi.h:357
@ SCSI_DEVICE_TYPE_CARDREADER
定义 scsi.h:359
@ SCSI_DEVICE_TYPE_OPTICAL
定义 scsi.h:351
@ SCSI_DEVICE_TYPE_SEQUENTIAL
定义 scsi.h:345
@ SCSI_DEVICE_TYPE_MEDIUM_CHANGER
定义 scsi.h:352
@ SCSI_DEVICE_TYPE_CDROM
定义 scsi.h:349
@ SCSI_DEVICE_TYPE_WRITE_ONCE_READ_MULTIPLE
定义 scsi.h:348
@ SCSI_DEVICE_TYPE_DIRECT
定义 scsi.h:344
@ SCSI_DEVICE_TYPE_ASC_PREPRESS_GRAPHICS10
定义 scsi.h:354
rt_err_t rt_scsi_read_capacity16(struct rt_scsi_device *sdev, struct rt_scsi_read_capacity16_data *out_data)
#define RT_SCSI_CMD_WRITE16
定义 scsi.h:291
rt_err_t rt_scsi_synchronize_cache16(struct rt_scsi_device *sdev, rt_off_t lba, rt_size_t size)
rt_err_t rt_scsi_read10(struct rt_scsi_device *sdev, rt_off_t lba, void *buffer, rt_size_t size)
rt_err_t rt_scsi_test_unit_ready(struct rt_scsi_device *sdev)
rt_err_t rt_scsi_inquiry(struct rt_scsi_device *sdev, struct rt_scsi_inquiry_data *out_data)
rt_err_t rt_scsi_mode_select6(struct rt_scsi_device *sdev, rt_uint8_t pf, rt_uint8_t sp, void *buffer, rt_size_t size, struct rt_scsi_mode_select_data *data)
rt_err_t rt_scsi_request_sense(struct rt_scsi_device *sdev, struct rt_scsi_request_sense_data *out_data)
rt_err_t rt_scsi_write_same16(struct rt_scsi_device *sdev, rt_off_t lba, rt_size_t size)
rt_err_t rt_scsi_write_same10(struct rt_scsi_device *sdev, rt_off_t lba, rt_size_t size)
rt_packed(struct rt_scsi_unknow { rt_uint8_t opcode;})
rt_err_t rt_scsi_read12(struct rt_scsi_device *sdev, rt_off_t lba, void *buffer, rt_size_t size)
#define RT_SCSI_CMD_WRITE12
定义 scsi.h:296
rt_err_t rt_scsi_read16(struct rt_scsi_device *sdev, rt_off_t lba, void *buffer, rt_size_t size)
rt_err_t rt_scsi_read_capacity10(struct rt_scsi_device *sdev, struct rt_scsi_read_capacity10_data *out_data)
rt_err_t rt_scsi_write12(struct rt_scsi_device *sdev, rt_off_t lba, const void *buffer, rt_size_t size)
rt_err_t rt_scsi_write10(struct rt_scsi_device *sdev, rt_off_t lba, const void *buffer, rt_size_t size)
rt_err_t rt_scsi_mode_sense10(struct rt_scsi_device *sdev, rt_uint8_t dbd, rt_uint8_t modepage, rt_uint8_t subpage, void *buffer, rt_size_t size, struct rt_scsi_mode_select_data *data)
rt_err_t rt_scsi_host_unregister(struct rt_scsi_host *scsi)
rt_err_t rt_scsi_mode_sense6(struct rt_scsi_device *sdev, rt_uint8_t dbd, rt_uint8_t modepage, rt_uint8_t subpage, void *buffer, rt_size_t size, struct rt_scsi_mode_select_data *data)
rt_err_t rt_scsi_mode_select10(struct rt_scsi_device *sdev, rt_uint8_t pf, rt_uint8_t sp, void *buffer, rt_size_t size, struct rt_scsi_mode_select_data *data)
struct rt_scsi_synchronize_cache16 synchronize_cache16
定义 scsi.h:315
rt_size_t size
定义 scsi.h:337
struct rt_scsi_write_same10 write_same10
定义 scsi.h:316
struct rt_scsi_mode_select6 mode_select6
定义 scsi.h:318
struct rt_scsi_request_sense request_sense
定义 scsi.h:305
struct rt_scsi_mode_sense6 mode_sense6
定义 scsi.h:320
struct rt_scsi_read16 read16
定义 scsi.h:310
struct rt_scsi_synchronize_cache10 synchronize_cache10
定义 scsi.h:314
struct rt_scsi_inquiry inquiry
定义 scsi.h:304
rt_size_t op_size
定义 scsi.h:323
struct rt_scsi_read_capacity10 read_capacity10
定义 scsi.h:306
struct rt_scsi_read_capacity16 read_capacity16
定义 scsi.h:307
struct rt_scsi_unknow unknow
定义 scsi.h:302
struct rt_scsi_write10 write10
定义 scsi.h:311
struct rt_scsi_mode_sense10 mode_sense10
定义 scsi.h:321
union rt_scsi_cmd::@127112164346047252131150363270265367232301355316 data
struct rt_scsi_write12 write12
定义 scsi.h:312
struct rt_scsi_write_same16 write_same16
定义 scsi.h:317
union rt_scsi_cmd::@110335064260203175325264173125227050061241262006 op
struct rt_scsi_read12 read12
定义 scsi.h:309
struct rt_scsi_test_unit_ready test_unit_ready
定义 scsi.h:303
struct rt_scsi_mode_select10 mode_select10
定义 scsi.h:319
struct rt_scsi_read10 read10
定义 scsi.h:308
struct rt_scsi_write16 write16
定义 scsi.h:313
struct rt_scsi_host * host
定义 scsi.h:381
rt_list_t list
定义 scsi.h:383
rt_size_t id
定义 scsi.h:385
rt_uint32_t removable
定义 scsi.h:388
rt_size_t lun
定义 scsi.h:386
rt_size_t block_size
定义 scsi.h:390
rt_uint32_t devtype
定义 scsi.h:387
rt_size_t last_block
定义 scsi.h:389
struct rt_device * dev
定义 scsi.h:369
rt_size_t max_id
定义 scsi.h:373
rt_list_t lun_nodes
定义 scsi.h:376
rt_size_t max_lun
定义 scsi.h:374
const struct rt_scsi_ops * ops
定义 scsi.h:371
rt_uint16_t block_descriptor_length
定义 scsi.h:245
rt_err_t(* transfer)(struct rt_scsi_device *sdev, struct rt_scsi_cmd *cmd)
定义 scsi.h:398
rt_err_t(* reset)(struct rt_scsi_device *sdev)
定义 scsi.h:397