1184610Salfred/* $FreeBSD: stable/10/sys/dev/usb/usb_ioctl.h 353175 2019-10-07 08:13:49Z hselasky $ */
2184610Salfred/*-
3184610Salfred * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4184610Salfred * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
5184610Salfred * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
6184610Salfred *
7184610Salfred * Redistribution and use in source and binary forms, with or without
8184610Salfred * modification, are permitted provided that the following conditions
9184610Salfred * are met:
10184610Salfred * 1. Redistributions of source code must retain the above copyright
11184610Salfred *    notice, this list of conditions and the following disclaimer.
12184610Salfred * 2. Redistributions in binary form must reproduce the above copyright
13184610Salfred *    notice, this list of conditions and the following disclaimer in the
14184610Salfred *    documentation and/or other materials provided with the distribution.
15184610Salfred *
16184610Salfred * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17184610Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18184610Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19184610Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20184610Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21184610Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22184610Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23184610Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24184610Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25184610Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26184610Salfred * SUCH DAMAGE.
27184610Salfred */
28184610Salfred
29194230Sthompsa#ifndef _USB_IOCTL_H_
30194230Sthompsa#define	_USB_IOCTL_H_
31184610Salfred
32246122Shselasky#ifndef USB_GLOBAL_INCLUDE_FILE
33184610Salfred#include <sys/ioccom.h>
34254243Shselasky#include <sys/cdefs.h>
35184610Salfred
36185087Salfred/* Building "kdump" depends on these includes */
37185087Salfred
38188942Sthompsa#include <dev/usb/usb_endian.h>
39188942Sthompsa#include <dev/usb/usb.h>
40246122Shselasky#endif
41185087Salfred
42189110Sthompsa#define	USB_DEVICE_NAME "usbctl"
43189110Sthompsa#define	USB_DEVICE_DIR "usb"
44184610Salfred#define	USB_GENERIC_NAME "ugen"
45223467Shselasky#define	USB_TEMPLATE_SYSCTL "hw.usb.template"	/* integer type */
46184610Salfred
47254243Shselasky/*
48254243Shselasky * Align IOCTL structures to hide differences when running 32-bit
49254243Shselasky * programs under 64-bit kernels:
50254243Shselasky */
51254243Shselasky#ifdef COMPAT_32BIT
52254243Shselasky#define	USB_IOCTL_STRUCT_ALIGN(n) __aligned(n)
53254243Shselasky#else
54254243Shselasky#define	USB_IOCTL_STRUCT_ALIGN(n)
55254243Shselasky#endif
56254243Shselasky
57223467Shselasky/* Definition of valid template sysctl values */
58223467Shselasky
59223467Shselaskyenum {
60223467Shselasky	USB_TEMP_MSC,		/* USB Mass Storage */
61223467Shselasky	USB_TEMP_CDCE,		/* USB CDC Ethernet */
62223467Shselasky	USB_TEMP_MTP,		/* Message Transfer Protocol */
63223467Shselasky	USB_TEMP_MODEM,		/* USB CDC Modem */
64223467Shselasky	USB_TEMP_AUDIO,		/* USB Audio */
65223467Shselasky	USB_TEMP_KBD,		/* USB Keyboard */
66223467Shselasky	USB_TEMP_MOUSE,		/* USB Mouse */
67269922Shselasky	USB_TEMP_PHONE,		/* USB Phone */
68223467Shselasky	USB_TEMP_MAX,
69223467Shselasky};
70223467Shselasky
71192984Sthompsastruct usb_read_dir {
72213852Shselasky#ifdef COMPAT_32BIT
73213852Shselasky	uint64_t urd_data;
74213852Shselasky#else
75184610Salfred	void   *urd_data;
76213852Shselasky#endif
77184610Salfred	uint32_t urd_startentry;
78184610Salfred	uint32_t urd_maxlen;
79254243Shselasky} USB_IOCTL_STRUCT_ALIGN(8);
80184610Salfred
81192984Sthompsastruct usb_ctl_request {
82213852Shselasky#ifdef COMPAT_32BIT
83213852Shselasky	uint64_t ucr_data;
84213852Shselasky#else
85184610Salfred	void   *ucr_data;
86213852Shselasky#endif
87184610Salfred	uint16_t ucr_flags;
88184610Salfred	uint16_t ucr_actlen;		/* actual length transferred */
89184610Salfred	uint8_t	ucr_addr;		/* zero - currently not used */
90192984Sthompsa	struct usb_device_request ucr_request;
91254243Shselasky} USB_IOCTL_STRUCT_ALIGN(8);
92184610Salfred
93192984Sthompsastruct usb_alt_interface {
94184610Salfred	uint8_t	uai_interface_index;
95184610Salfred	uint8_t	uai_alt_index;
96254243Shselasky} USB_IOCTL_STRUCT_ALIGN(1);
97184610Salfred
98192984Sthompsastruct usb_gen_descriptor {
99213852Shselasky#ifdef COMPAT_32BIT
100213852Shselasky	uint64_t ugd_data;
101213852Shselasky#else
102184610Salfred	void   *ugd_data;
103213852Shselasky#endif
104184610Salfred	uint16_t ugd_lang_id;
105184610Salfred	uint16_t ugd_maxlen;
106184610Salfred	uint16_t ugd_actlen;
107184610Salfred	uint16_t ugd_offset;
108184610Salfred	uint8_t	ugd_config_index;
109184610Salfred	uint8_t	ugd_string_index;
110184610Salfred	uint8_t	ugd_iface_index;
111184610Salfred	uint8_t	ugd_altif_index;
112184610Salfred	uint8_t	ugd_endpt_index;
113184610Salfred	uint8_t	ugd_report_type;
114184610Salfred	uint8_t	reserved[8];
115254243Shselasky} USB_IOCTL_STRUCT_ALIGN(8);
116184610Salfred
117192984Sthompsastruct usb_device_info {
118184610Salfred	uint16_t udi_productNo;
119184610Salfred	uint16_t udi_vendorNo;
120184610Salfred	uint16_t udi_releaseNo;
121184610Salfred	uint16_t udi_power;		/* power consumption in mA, 0 if
122184610Salfred					 * selfpowered */
123184610Salfred	uint8_t	udi_bus;
124184610Salfred	uint8_t	udi_addr;		/* device address */
125184610Salfred	uint8_t	udi_index;		/* device index */
126184610Salfred	uint8_t	udi_class;
127184610Salfred	uint8_t	udi_subclass;
128184610Salfred	uint8_t	udi_protocol;
129184610Salfred	uint8_t	udi_config_no;		/* current config number */
130184610Salfred	uint8_t	udi_config_index;	/* current config index */
131184610Salfred	uint8_t	udi_speed;		/* see "USB_SPEED_XXX" */
132184610Salfred	uint8_t	udi_mode;		/* see "USB_MODE_XXX" */
133184610Salfred	uint8_t	udi_nports;
134184610Salfred	uint8_t	udi_hubaddr;		/* parent HUB address */
135184610Salfred	uint8_t	udi_hubindex;		/* parent HUB device index */
136184610Salfred	uint8_t	udi_hubport;		/* parent HUB port */
137184610Salfred	uint8_t	udi_power_mode;		/* see "USB_POWER_MODE_XXX" */
138184610Salfred	uint8_t	udi_suspended;		/* set if device is suspended */
139184610Salfred	uint8_t	udi_reserved[16];	/* leave space for the future */
140184610Salfred	char	udi_product[128];
141184610Salfred	char	udi_vendor[128];
142184610Salfred	char	udi_serial[64];
143184610Salfred	char	udi_release[8];
144254243Shselasky} USB_IOCTL_STRUCT_ALIGN(2);
145184610Salfred
146250201Shselasky#define	USB_DEVICE_PORT_PATH_MAX 32
147250201Shselasky
148250201Shselaskystruct usb_device_port_path {
149250201Shselasky	uint8_t udp_bus;		/* which bus we are on */
150250201Shselasky	uint8_t udp_index;		/* which device index */
151250201Shselasky	uint8_t udp_port_level;		/* how many levels: 0, 1, 2 ... */
152250201Shselasky	uint8_t udp_port_no[USB_DEVICE_PORT_PATH_MAX];
153254243Shselasky} USB_IOCTL_STRUCT_ALIGN(1);
154250201Shselasky
155192984Sthompsastruct usb_device_stats {
156184610Salfred	uint32_t uds_requests_ok[4];	/* Indexed by transfer type UE_XXX */
157184610Salfred	uint32_t uds_requests_fail[4];	/* Indexed by transfer type UE_XXX */
158254243Shselasky} USB_IOCTL_STRUCT_ALIGN(4);
159184610Salfred
160192984Sthompsastruct usb_fs_start {
161184610Salfred	uint8_t	ep_index;
162254243Shselasky} USB_IOCTL_STRUCT_ALIGN(1);
163184610Salfred
164192984Sthompsastruct usb_fs_stop {
165184610Salfred	uint8_t	ep_index;
166254243Shselasky} USB_IOCTL_STRUCT_ALIGN(1);
167184610Salfred
168192984Sthompsastruct usb_fs_complete {
169184610Salfred	uint8_t	ep_index;
170254243Shselasky} USB_IOCTL_STRUCT_ALIGN(1);
171184610Salfred
172184610Salfred/* This structure is used for all endpoint types */
173192984Sthompsastruct usb_fs_endpoint {
174184610Salfred	/*
175184610Salfred	 * NOTE: isochronous USB transfer only use one buffer, but can have
176184610Salfred	 * multiple frame lengths !
177184610Salfred	 */
178213852Shselasky#ifdef COMPAT_32BIT
179213852Shselasky	uint64_t ppBuffer;
180213852Shselasky	uint64_t pLength;
181213852Shselasky#else
182184610Salfred	void  **ppBuffer;		/* pointer to userland buffers */
183184610Salfred	uint32_t *pLength;		/* pointer to frame lengths, updated
184184610Salfred					 * to actual length */
185213852Shselasky#endif
186184610Salfred	uint32_t nFrames;		/* number of frames */
187184610Salfred	uint32_t aFrames;		/* actual number of frames */
188184610Salfred	uint16_t flags;
189184610Salfred	/* a single short frame will terminate */
190184610Salfred#define	USB_FS_FLAG_SINGLE_SHORT_OK 0x0001
191184610Salfred	/* multiple short frames are allowed */
192184610Salfred#define	USB_FS_FLAG_MULTI_SHORT_OK 0x0002
193184610Salfred	/* all frame(s) transmitted are short terminated */
194184610Salfred#define	USB_FS_FLAG_FORCE_SHORT 0x0004
195184610Salfred	/* will do a clear-stall before xfer */
196184610Salfred#define	USB_FS_FLAG_CLEAR_STALL 0x0008
197184610Salfred	uint16_t timeout;		/* in milliseconds */
198184610Salfred	/* isocronous completion time in milliseconds - used for echo cancel */
199184610Salfred	uint16_t isoc_time_complete;
200184610Salfred	/* timeout value for no timeout */
201184610Salfred#define	USB_FS_TIMEOUT_NONE 0
202194677Sthompsa	int	status;			/* see USB_ERR_XXX */
203254243Shselasky} USB_IOCTL_STRUCT_ALIGN(8);
204184610Salfred
205192984Sthompsastruct usb_fs_init {
206184610Salfred	/* userland pointer to endpoints structure */
207213852Shselasky#ifdef COMPAT_32BIT
208213852Shselasky	uint64_t pEndpoints;
209213852Shselasky#else
210192984Sthompsa	struct usb_fs_endpoint *pEndpoints;
211213852Shselasky#endif
212184610Salfred	/* maximum number of endpoints */
213184610Salfred	uint8_t	ep_index_max;
214254243Shselasky} USB_IOCTL_STRUCT_ALIGN(8);
215184610Salfred
216192984Sthompsastruct usb_fs_uninit {
217184610Salfred	uint8_t	dummy;			/* zero */
218254243Shselasky} USB_IOCTL_STRUCT_ALIGN(1);
219184610Salfred
220192984Sthompsastruct usb_fs_open {
221353175Shselasky#define	USB_FS_MAX_BUFSIZE (1 << 25)	/* 32 MBytes */
222184610Salfred	uint32_t max_bufsize;
223219100Shselasky#define	USB_FS_MAX_FRAMES		(1U << 12)
224219100Shselasky#define	USB_FS_MAX_FRAMES_PRE_SCALE	(1U << 31)	/* for ISOCHRONOUS transfers */
225219100Shselasky	uint32_t max_frames;		/* read and write */
226184610Salfred	uint16_t max_packet_length;	/* read only */
227184610Salfred	uint8_t	dev_index;		/* currently unused */
228184610Salfred	uint8_t	ep_index;
229184610Salfred	uint8_t	ep_no;			/* bEndpointNumber */
230254243Shselasky} USB_IOCTL_STRUCT_ALIGN(4);
231184610Salfred
232239238Shselaskystruct usb_fs_open_stream {
233239214Shselasky	struct usb_fs_open fs_open;
234254243Shselasky	uint16_t stream_id;		/* stream ID */
235254243Shselasky} USB_IOCTL_STRUCT_ALIGN(4);
236239214Shselasky
237192984Sthompsastruct usb_fs_close {
238184610Salfred	uint8_t	ep_index;
239254243Shselasky} USB_IOCTL_STRUCT_ALIGN(1);
240184610Salfred
241192984Sthompsastruct usb_fs_clear_stall_sync {
242184610Salfred	uint8_t	ep_index;
243254243Shselasky} USB_IOCTL_STRUCT_ALIGN(1);
244184610Salfred
245192984Sthompsastruct usb_gen_quirk {
246184610Salfred	uint16_t index;			/* Quirk Index */
247184610Salfred	uint16_t vid;			/* Vendor ID */
248184610Salfred	uint16_t pid;			/* Product ID */
249184610Salfred	uint16_t bcdDeviceLow;		/* Low Device Revision */
250184610Salfred	uint16_t bcdDeviceHigh;		/* High Device Revision */
251184610Salfred	uint16_t reserved[2];
252184610Salfred	/*
253254243Shselasky	 * String version of quirk including terminating zero. See
254254243Shselasky	 * UQ_XXX in "usb_quirk.h".
255184610Salfred	 */
256184610Salfred	char	quirkname[64 - 14];
257254243Shselasky} USB_IOCTL_STRUCT_ALIGN(2);
258184610Salfred
259184610Salfred/* USB controller */
260192984Sthompsa#define	USB_REQUEST		_IOWR('U', 1, struct usb_ctl_request)
261184610Salfred#define	USB_SETDEBUG		_IOW ('U', 2, int)
262184610Salfred#define	USB_DISCOVER		_IO  ('U', 3)
263192984Sthompsa#define	USB_DEVICEINFO		_IOWR('U', 4, struct usb_device_info)
264192984Sthompsa#define	USB_DEVICESTATS		_IOR ('U', 5, struct usb_device_stats)
265184610Salfred#define	USB_DEVICEENUMERATE	_IOW ('U', 6, int)
266184610Salfred
267184610Salfred/* Generic HID device */
268192984Sthompsa#define	USB_GET_REPORT_DESC	_IOWR('U', 21, struct usb_gen_descriptor)
269184610Salfred#define	USB_SET_IMMED		_IOW ('U', 22, int)
270192984Sthompsa#define	USB_GET_REPORT		_IOWR('U', 23, struct usb_gen_descriptor)
271192984Sthompsa#define	USB_SET_REPORT		_IOW ('U', 24, struct usb_gen_descriptor)
272184610Salfred#define	USB_GET_REPORT_ID	_IOR ('U', 25, int)
273184610Salfred
274184610Salfred/* Generic USB device */
275184610Salfred#define	USB_GET_CONFIG		_IOR ('U', 100, int)
276184610Salfred#define	USB_SET_CONFIG		_IOW ('U', 101, int)
277192984Sthompsa#define	USB_GET_ALTINTERFACE	_IOWR('U', 102, struct usb_alt_interface)
278192984Sthompsa#define	USB_SET_ALTINTERFACE	_IOWR('U', 103, struct usb_alt_interface)
279192984Sthompsa#define	USB_GET_DEVICE_DESC	_IOR ('U', 105, struct usb_device_descriptor)
280192984Sthompsa#define	USB_GET_CONFIG_DESC	_IOR ('U', 106, struct usb_config_descriptor)
281192984Sthompsa#define	USB_GET_RX_INTERFACE_DESC _IOR ('U', 107, struct usb_interface_descriptor)
282192984Sthompsa#define	USB_GET_RX_ENDPOINT_DESC _IOR ('U', 108, struct usb_endpoint_descriptor)
283192984Sthompsa#define	USB_GET_FULL_DESC	_IOWR('U', 109, struct usb_gen_descriptor)
284192984Sthompsa#define	USB_GET_STRING_DESC	_IOWR('U', 110, struct usb_gen_descriptor)
285192984Sthompsa#define	USB_DO_REQUEST		_IOWR('U', 111, struct usb_ctl_request)
286192984Sthompsa#define	USB_GET_DEVICEINFO	_IOR ('U', 112, struct usb_device_info)
287184610Salfred#define	USB_SET_RX_SHORT_XFER	_IOW ('U', 113, int)
288184610Salfred#define	USB_SET_RX_TIMEOUT	_IOW ('U', 114, int)
289184610Salfred#define	USB_GET_RX_FRAME_SIZE	_IOR ('U', 115, int)
290184610Salfred#define	USB_GET_RX_BUFFER_SIZE	_IOR ('U', 117, int)
291184610Salfred#define	USB_SET_RX_BUFFER_SIZE	_IOW ('U', 118, int)
292184610Salfred#define	USB_SET_RX_STALL_FLAG	_IOW ('U', 119, int)
293184610Salfred#define	USB_SET_TX_STALL_FLAG	_IOW ('U', 120, int)
294192984Sthompsa#define	USB_GET_IFACE_DRIVER	_IOWR('U', 121, struct usb_gen_descriptor)
295184610Salfred#define	USB_CLAIM_INTERFACE	_IOW ('U', 122, int)
296184610Salfred#define	USB_RELEASE_INTERFACE	_IOW ('U', 123, int)
297184610Salfred#define	USB_IFACE_DRIVER_ACTIVE	_IOW ('U', 124, int)
298184610Salfred#define	USB_IFACE_DRIVER_DETACH	_IOW ('U', 125, int)
299184610Salfred#define	USB_GET_PLUGTIME	_IOR ('U', 126, uint32_t)
300192984Sthompsa#define	USB_READ_DIR		_IOW ('U', 127, struct usb_read_dir)
301250201Shselasky/* 128 - 133 unused */
302250201Shselasky#define	USB_GET_DEV_PORT_PATH	_IOR ('U', 134, struct usb_device_port_path)
303246789Shselasky#define	USB_GET_POWER_USAGE	_IOR ('U', 135, int)
304184610Salfred#define	USB_SET_TX_FORCE_SHORT	_IOW ('U', 136, int)
305184610Salfred#define	USB_SET_TX_TIMEOUT	_IOW ('U', 137, int)
306184610Salfred#define	USB_GET_TX_FRAME_SIZE	_IOR ('U', 138, int)
307184610Salfred#define	USB_GET_TX_BUFFER_SIZE	_IOR ('U', 139, int)
308184610Salfred#define	USB_SET_TX_BUFFER_SIZE	_IOW ('U', 140, int)
309192984Sthompsa#define	USB_GET_TX_INTERFACE_DESC _IOR ('U', 141, struct usb_interface_descriptor)
310192984Sthompsa#define	USB_GET_TX_ENDPOINT_DESC _IOR ('U', 142, struct usb_endpoint_descriptor)
311184610Salfred#define	USB_SET_PORT_ENABLE	_IOW ('U', 143, int)
312184610Salfred#define	USB_SET_PORT_DISABLE	_IOW ('U', 144, int)
313184610Salfred#define	USB_SET_POWER_MODE	_IOW ('U', 145, int)
314184610Salfred#define	USB_GET_POWER_MODE	_IOR ('U', 146, int)
315188987Sthompsa#define	USB_SET_TEMPLATE	_IOW ('U', 147, int)
316188987Sthompsa#define	USB_GET_TEMPLATE	_IOR ('U', 148, int)
317184610Salfred
318184610Salfred/* Modem device */
319184610Salfred#define	USB_GET_CM_OVER_DATA	_IOR ('U', 180, int)
320184610Salfred#define	USB_SET_CM_OVER_DATA	_IOW ('U', 181, int)
321184610Salfred
322227463Shselasky/* GPIO control */
323227463Shselasky#define	USB_GET_GPIO		_IOR ('U', 182, int)
324227463Shselasky#define	USB_SET_GPIO		_IOW ('U', 183, int)
325227463Shselasky
326184610Salfred/* USB file system interface */
327192984Sthompsa#define	USB_FS_START		_IOW ('U', 192, struct usb_fs_start)
328192984Sthompsa#define	USB_FS_STOP		_IOW ('U', 193, struct usb_fs_stop)
329192984Sthompsa#define	USB_FS_COMPLETE		_IOR ('U', 194, struct usb_fs_complete)
330192984Sthompsa#define	USB_FS_INIT		_IOW ('U', 195, struct usb_fs_init)
331192984Sthompsa#define	USB_FS_UNINIT		_IOW ('U', 196, struct usb_fs_uninit)
332192984Sthompsa#define	USB_FS_OPEN		_IOWR('U', 197, struct usb_fs_open)
333192984Sthompsa#define	USB_FS_CLOSE		_IOW ('U', 198, struct usb_fs_close)
334192984Sthompsa#define	USB_FS_CLEAR_STALL_SYNC _IOW ('U', 199, struct usb_fs_clear_stall_sync)
335239238Shselasky#define	USB_FS_OPEN_STREAM	_IOWR('U', 200, struct usb_fs_open_stream)
336184610Salfred
337184610Salfred/* USB quirk system interface */
338192984Sthompsa#define	USB_DEV_QUIRK_GET	_IOWR('Q', 0, struct usb_gen_quirk)
339192984Sthompsa#define	USB_QUIRK_NAME_GET	_IOWR('Q', 1, struct usb_gen_quirk)
340192984Sthompsa#define	USB_DEV_QUIRK_ADD	_IOW ('Q', 2, struct usb_gen_quirk)
341192984Sthompsa#define	USB_DEV_QUIRK_REMOVE	_IOW ('Q', 3, struct usb_gen_quirk)
342184610Salfred
343194230Sthompsa#endif					/* _USB_IOCTL_H_ */
344