1/*
2 * Copyright 2018-2019, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
4 *
5 * Authors:
6 *		Augustin Cavalier <waddlesplash>
7 */
8#ifndef _FBSD_COMPAT_USB_STANDARD_H_
9#define _FBSD_COMPAT_USB_STANDARD_H_
10
11#include <sys/malloc.h>
12
13MALLOC_DECLARE(M_USB);
14MALLOC_DECLARE(M_USBDEV);
15
16#include <dev/usb/usb_endian.h>
17#include <dev/usb/usb_haiku.h>
18
19#define	USB_STACK_VERSION 2000		/* 2.0 */
20
21struct usb_device_request {
22	uByte	bmRequestType;
23	uByte	bRequest;
24	uWord	wValue;
25	uWord	wIndex;
26	uWord	wLength;
27} __packed;
28typedef struct usb_device_request usb_device_request_t;
29
30/* abbreviated Haiku request types */
31#define HAIKU_USB_REQTYPE_DEVICE_IN				0x80
32#define HAIKU_USB_REQTYPE_DEVICE_OUT			0x00
33#define HAIKU_USB_REQTYPE_VENDOR				0x40
34
35/* FreeBSD request types */
36#define UT_READ_VENDOR_DEVICE	(HAIKU_USB_REQTYPE_DEVICE_IN | HAIKU_USB_REQTYPE_VENDOR)
37#define UT_WRITE_VENDOR_DEVICE	(HAIKU_USB_REQTYPE_DEVICE_OUT | HAIKU_USB_REQTYPE_VENDOR)
38
39/* make sure this matches Haiku's usb_speed! */
40enum usb_dev_speed {
41	USB_SPEED_LOW,
42	USB_SPEED_FULL,
43	USB_SPEED_HIGH,
44	USB_SPEED_SUPER,
45};
46
47enum usb_hc_mode {
48	USB_MODE_HOST,		/* initiates transfers */
49	USB_MODE_DEVICE,	/* bus transfer target */
50	USB_MODE_DUAL		/* can be host or device */
51};
52#define	USB_MODE_MAX	(USB_MODE_DUAL+1)
53
54#define usb_endpoint_descriptor freebsd_usb_endpoint_descriptor
55struct usb_endpoint_descriptor {
56	uByte	bLength;
57	uByte	bDescriptorType;
58	uByte	bEndpointAddress;
59#define	UE_GET_DIR(a)	((a) & 0x80)
60#define	UE_SET_DIR(a,d)	((a) | (((d)&1) << 7))
61#define	UE_DIR_IN	0x80		/* IN-token endpoint, fixed */
62#define	UE_DIR_OUT	0x00		/* OUT-token endpoint, fixed */
63#define	UE_ADDR		0x0f
64#define	UE_ADDR_ANY	0xff
65#define	UE_GET_ADDR(a)	((a) & UE_ADDR)
66	uByte	bmAttributes;
67#define	UE_XFERTYPE	0x03
68#define	UE_CONTROL	0x00
69#define	UE_BULK	0x02
70#define	UE_INTERRUPT	0x03
71#define	UE_GET_XFERTYPE(a)	((a) & UE_XFERTYPE)
72	uWord	wMaxPacketSize;
73	uByte	bInterval;
74} __packed;
75typedef struct usb_endpoint_descriptor usb_endpoint_descriptor_t;
76
77#endif // _FBSD_COMPAT_USB_STANDARD_H_
78