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
31typedef struct device_lun_s device_lun;
32
33// holds common information about an attached device (pointed to by luns)
34typedef 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
63struct 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	char		vendor_name[8];
79	char		product_name[16];
80	char		product_revision[4];
81};
82
83
84typedef struct command_block_wrapper_s {
85	uint32		signature;
86	uint32		tag;
87	uint32		data_transfer_length;
88	uint8		flags;
89	uint8		lun;
90	uint8		command_block_length;
91	uint8		command_block[16];
92} _PACKED command_block_wrapper;
93
94
95typedef struct command_status_wrapper_s {
96	uint32		signature;
97	uint32		tag;
98	uint32		data_residue;
99	uint8		status;
100} _PACKED command_status_wrapper;
101
102#endif // _USB_DISK_H_
103