xref: /haiku/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.h (revision a127b88ecbfab58f64944c98aa47722a18e363b2)
1 /*
2  * Copyright 2008-2023, 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 #ifndef _USB_DISK_H_
9 #define _USB_DISK_H_
10 
11 
12 #include <util/Vector.h>
13 #include <util/DoublyLinkedList.h>
14 
15 #include <lock.h>
16 #include <USB3.h>
17 #include <device_manager.h>
18 #include <usb/USB_massbulk.h>
19 
20 
21 #define REQUEST_MASS_STORAGE_RESET	0xff
22 #define REQUEST_GET_MAX_LUN			0xfe
23 #define MAX_LOGICAL_UNIT_NUMBER		15
24 #define ATAPI_COMMAND_LENGTH		12
25 
26 #define SYNC_SUPPORT_RELOAD			5
27 
28 struct IOScheduler;
29 struct DMAResource;
30 typedef struct device_lun_s device_lun;
31 
32 // holds common information about an attached device (pointed to by luns)
33 typedef struct disk_device_s {
34 	disk_device_s();
35 	~disk_device_s();
36 
37 	int32		number;
38 	device_node	*node;
39 
40 	usb_device	device;
41 	bool		removed;
42 	uint32		open_count;
43 	recursive_lock io_lock;
44 	mutex		lock;
45 
46 	// IO operations
47 	Vector<DMAResource*>	dma_resources;
48 
49 	// device state
50 	usb_pipe	bulk_in;
51 	usb_pipe	bulk_out;
52 	usb_pipe	interrupt;
53 	uint8		interface;
54 	uint32		current_tag;
55 	uint8		sync_support;
56 	bool		tur_supported;
57 	bool		is_atapi;
58 	bool		is_ufi;
59 
60 	// used to store callback information
61 	sem_id		notify;
62 	status_t	status;
63 	size_t		actual_length;
64 
65 	// used to store interrupt result
66 	unsigned char interruptBuffer[2];
67 	sem_id interruptLock;
68 
69 	// logical units of this device
70 	uint8		lun_count;
71 	device_lun **luns;
72 } disk_device;
73 
74 
75 // represents a logical unit on the pointed to device - this gets published
76 struct device_lun_s {
77 	disk_device *device;
78 	char		name[32];
79 	uint8		logical_unit_number;
80 	bool		should_sync;
81 
82 	// device information through read capacity/inquiry
83 	bool		media_present;
84 	bool		media_changed;
85 	uint64		block_count;
86 	uint32		block_size;
87 	uint32		physical_block_size;
88 	uint8		device_type;
89 	bool		removable;
90 	bool		write_protected;
91 
92 	char		vendor_name[8];
93 	char		product_name[16];
94 	char		product_revision[4];
95 };
96 
97 
98 typedef struct interrupt_status_wrapper_s {
99 	uint8		status;
100 	uint8		misc;
101 } _PACKED interrupt_status_wrapper;
102 
103 
104 #endif // _USB_DISK_H_
105