xref: /haiku/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.h (revision 97901ec593ec4dd50ac115c1c35a6d72f6e489a5)
1 /*
2  * Copyright 2008, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Michael Lotz <mmlr@mlotz.ch>
7  */
8 
9 #ifndef _USB_DISK_H_
10 #define _USB_DISK_H_
11 
12 #include <lock.h>
13 #include <USB3.h>
14 
15 #define REQUEST_MASS_STORAGE_RESET	0xff
16 #define REQUEST_GET_MAX_LUN			0xfe
17 #define MAX_LOGICAL_UNIT_NUMBER		15
18 #define ATAPI_COMMAND_LENGTH		12
19 
20 #define CBW_SIGNATURE				0x43425355
21 #define CBW_DATA_OUTPUT				0x00
22 #define CBW_DATA_INPUT				0x80
23 
24 #define CSW_SIGNATURE				0x53425355
25 #define CSW_STATUS_COMMAND_PASSED	0x00
26 #define CSW_STATUS_COMMAND_FAILED	0x01
27 #define CSW_STATUS_PHASE_ERROR		0x02
28 
29 #define SYNC_SUPPORT_RELOAD			5
30 
31 typedef struct device_lun_s device_lun;
32 
33 // holds common information about an attached device (pointed to by luns)
34 typedef struct disk_device_s {
35 	usb_device	device;
36 	uint32		device_number;
37 	bool		removed;
38 	uint32		open_count;
39 	mutex		lock;
40 	void *		link;
41 
42 	// device state
43 	usb_pipe	bulk_in;
44 	usb_pipe	bulk_out;
45 	uint8		interface;
46 	uint32		current_tag;
47 	uint8		sync_support;
48 	bool		tur_supported;
49 	bool		is_atapi;
50 
51 	// used to store callback information
52 	sem_id		notify;
53 	status_t	status;
54 	size_t		actual_length;
55 
56 	// logical units of this device
57 	uint8		lun_count;
58 	device_lun **luns;
59 } disk_device;
60 
61 
62 // represents a logical unit on the pointed to device - this gets published
63 struct device_lun_s {
64 	disk_device *device;
65 	char		name[32];
66 	uint8		logical_unit_number;
67 	bool		should_sync;
68 
69 	// device information through read capacity/inquiry
70 	bool		media_present;
71 	bool		media_changed;
72 	uint32		block_count;
73 	uint32		block_size;
74 	uint8		device_type;
75 	bool		removable;
76 	bool		write_protected;
77 };
78 
79 
80 typedef struct command_block_wrapper_s {
81 	uint32		signature;
82 	uint32		tag;
83 	uint32		data_transfer_length;
84 	uint8		flags;
85 	uint8		lun;
86 	uint8		command_block_length;
87 	uint8		command_block[16];
88 } _PACKED command_block_wrapper;
89 
90 
91 typedef struct command_status_wrapper_s {
92 	uint32		signature;
93 	uint32		tag;
94 	uint32		data_residue;
95 	uint8		status;
96 } _PACKED command_status_wrapper;
97 
98 #endif // _USB_DISK_H_
99