usb_ioctl.h revision 246789
1184610Salfred/* $FreeBSD: head/sys/dev/usb/usb_ioctl.h 246789 2013-02-14 12:22:40Z 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>
34184610Salfred
35185087Salfred/* Building "kdump" depends on these includes */
36185087Salfred
37188942Sthompsa#include <dev/usb/usb_endian.h>
38188942Sthompsa#include <dev/usb/usb.h>
39246122Shselasky#endif
40185087Salfred
41189110Sthompsa#define	USB_DEVICE_NAME "usbctl"
42189110Sthompsa#define	USB_DEVICE_DIR "usb"
43184610Salfred#define	USB_GENERIC_NAME "ugen"
44223467Shselasky#define	USB_TEMPLATE_SYSCTL "hw.usb.template"	/* integer type */
45184610Salfred
46223467Shselasky/* Definition of valid template sysctl values */
47223467Shselasky
48223467Shselaskyenum {
49223467Shselasky	USB_TEMP_MSC,		/* USB Mass Storage */
50223467Shselasky	USB_TEMP_CDCE,		/* USB CDC Ethernet */
51223467Shselasky	USB_TEMP_MTP,		/* Message Transfer Protocol */
52223467Shselasky	USB_TEMP_MODEM,		/* USB CDC Modem */
53223467Shselasky	USB_TEMP_AUDIO,		/* USB Audio */
54223467Shselasky	USB_TEMP_KBD,		/* USB Keyboard */
55223467Shselasky	USB_TEMP_MOUSE,		/* USB Mouse */
56223467Shselasky	USB_TEMP_MAX,
57223467Shselasky};
58223467Shselasky
59192984Sthompsastruct usb_read_dir {
60213852Shselasky#ifdef COMPAT_32BIT
61213852Shselasky	uint64_t urd_data;
62213852Shselasky#else
63184610Salfred	void   *urd_data;
64213852Shselasky#endif
65184610Salfred	uint32_t urd_startentry;
66184610Salfred	uint32_t urd_maxlen;
67184610Salfred};
68184610Salfred
69192984Sthompsastruct usb_ctl_request {
70213852Shselasky#ifdef COMPAT_32BIT
71213852Shselasky	uint64_t ucr_data;
72213852Shselasky#else
73184610Salfred	void   *ucr_data;
74213852Shselasky#endif
75184610Salfred	uint16_t ucr_flags;
76184610Salfred	uint16_t ucr_actlen;		/* actual length transferred */
77184610Salfred	uint8_t	ucr_addr;		/* zero - currently not used */
78192984Sthompsa	struct usb_device_request ucr_request;
79184610Salfred};
80184610Salfred
81192984Sthompsastruct usb_alt_interface {
82184610Salfred	uint8_t	uai_interface_index;
83184610Salfred	uint8_t	uai_alt_index;
84184610Salfred};
85184610Salfred
86192984Sthompsastruct usb_gen_descriptor {
87213852Shselasky#ifdef COMPAT_32BIT
88213852Shselasky	uint64_t ugd_data;
89213852Shselasky#else
90184610Salfred	void   *ugd_data;
91213852Shselasky#endif
92184610Salfred	uint16_t ugd_lang_id;
93184610Salfred	uint16_t ugd_maxlen;
94184610Salfred	uint16_t ugd_actlen;
95184610Salfred	uint16_t ugd_offset;
96184610Salfred	uint8_t	ugd_config_index;
97184610Salfred	uint8_t	ugd_string_index;
98184610Salfred	uint8_t	ugd_iface_index;
99184610Salfred	uint8_t	ugd_altif_index;
100184610Salfred	uint8_t	ugd_endpt_index;
101184610Salfred	uint8_t	ugd_report_type;
102184610Salfred	uint8_t	reserved[8];
103184610Salfred};
104184610Salfred
105192984Sthompsastruct usb_device_info {
106184610Salfred	uint16_t udi_productNo;
107184610Salfred	uint16_t udi_vendorNo;
108184610Salfred	uint16_t udi_releaseNo;
109184610Salfred	uint16_t udi_power;		/* power consumption in mA, 0 if
110184610Salfred					 * selfpowered */
111184610Salfred	uint8_t	udi_bus;
112184610Salfred	uint8_t	udi_addr;		/* device address */
113184610Salfred	uint8_t	udi_index;		/* device index */
114184610Salfred	uint8_t	udi_class;
115184610Salfred	uint8_t	udi_subclass;
116184610Salfred	uint8_t	udi_protocol;
117184610Salfred	uint8_t	udi_config_no;		/* current config number */
118184610Salfred	uint8_t	udi_config_index;	/* current config index */
119184610Salfred	uint8_t	udi_speed;		/* see "USB_SPEED_XXX" */
120184610Salfred	uint8_t	udi_mode;		/* see "USB_MODE_XXX" */
121184610Salfred	uint8_t	udi_nports;
122184610Salfred	uint8_t	udi_hubaddr;		/* parent HUB address */
123184610Salfred	uint8_t	udi_hubindex;		/* parent HUB device index */
124184610Salfred	uint8_t	udi_hubport;		/* parent HUB port */
125184610Salfred	uint8_t	udi_power_mode;		/* see "USB_POWER_MODE_XXX" */
126184610Salfred	uint8_t	udi_suspended;		/* set if device is suspended */
127184610Salfred	uint8_t	udi_reserved[16];	/* leave space for the future */
128184610Salfred	char	udi_product[128];
129184610Salfred	char	udi_vendor[128];
130184610Salfred	char	udi_serial[64];
131184610Salfred	char	udi_release[8];
132184610Salfred};
133184610Salfred
134192984Sthompsastruct usb_device_stats {
135184610Salfred	uint32_t uds_requests_ok[4];	/* Indexed by transfer type UE_XXX */
136184610Salfred	uint32_t uds_requests_fail[4];	/* Indexed by transfer type UE_XXX */
137184610Salfred};
138184610Salfred
139192984Sthompsastruct usb_fs_start {
140184610Salfred	uint8_t	ep_index;
141184610Salfred};
142184610Salfred
143192984Sthompsastruct usb_fs_stop {
144184610Salfred	uint8_t	ep_index;
145184610Salfred};
146184610Salfred
147192984Sthompsastruct usb_fs_complete {
148184610Salfred	uint8_t	ep_index;
149184610Salfred};
150184610Salfred
151184610Salfred/* This structure is used for all endpoint types */
152192984Sthompsastruct usb_fs_endpoint {
153184610Salfred	/*
154184610Salfred	 * NOTE: isochronous USB transfer only use one buffer, but can have
155184610Salfred	 * multiple frame lengths !
156184610Salfred	 */
157213852Shselasky#ifdef COMPAT_32BIT
158213852Shselasky	uint64_t ppBuffer;
159213852Shselasky	uint64_t pLength;
160213852Shselasky#else
161184610Salfred	void  **ppBuffer;		/* pointer to userland buffers */
162184610Salfred	uint32_t *pLength;		/* pointer to frame lengths, updated
163184610Salfred					 * to actual length */
164213852Shselasky#endif
165184610Salfred	uint32_t nFrames;		/* number of frames */
166184610Salfred	uint32_t aFrames;		/* actual number of frames */
167184610Salfred	uint16_t flags;
168184610Salfred	/* a single short frame will terminate */
169184610Salfred#define	USB_FS_FLAG_SINGLE_SHORT_OK 0x0001
170184610Salfred	/* multiple short frames are allowed */
171184610Salfred#define	USB_FS_FLAG_MULTI_SHORT_OK 0x0002
172184610Salfred	/* all frame(s) transmitted are short terminated */
173184610Salfred#define	USB_FS_FLAG_FORCE_SHORT 0x0004
174184610Salfred	/* will do a clear-stall before xfer */
175184610Salfred#define	USB_FS_FLAG_CLEAR_STALL 0x0008
176184610Salfred	uint16_t timeout;		/* in milliseconds */
177184610Salfred	/* isocronous completion time in milliseconds - used for echo cancel */
178184610Salfred	uint16_t isoc_time_complete;
179184610Salfred	/* timeout value for no timeout */
180184610Salfred#define	USB_FS_TIMEOUT_NONE 0
181194677Sthompsa	int	status;			/* see USB_ERR_XXX */
182184610Salfred};
183184610Salfred
184192984Sthompsastruct usb_fs_init {
185184610Salfred	/* userland pointer to endpoints structure */
186213852Shselasky#ifdef COMPAT_32BIT
187213852Shselasky	uint64_t pEndpoints;
188213852Shselasky#else
189192984Sthompsa	struct usb_fs_endpoint *pEndpoints;
190213852Shselasky#endif
191184610Salfred	/* maximum number of endpoints */
192184610Salfred	uint8_t	ep_index_max;
193184610Salfred};
194184610Salfred
195192984Sthompsastruct usb_fs_uninit {
196184610Salfred	uint8_t	dummy;			/* zero */
197184610Salfred};
198184610Salfred
199192984Sthompsastruct usb_fs_open {
200184610Salfred#define	USB_FS_MAX_BUFSIZE (1 << 18)
201184610Salfred	uint32_t max_bufsize;
202219100Shselasky#define	USB_FS_MAX_FRAMES		(1U << 12)
203219100Shselasky#define	USB_FS_MAX_FRAMES_PRE_SCALE	(1U << 31)	/* for ISOCHRONOUS transfers */
204219100Shselasky	uint32_t max_frames;		/* read and write */
205184610Salfred	uint16_t max_packet_length;	/* read only */
206184610Salfred	uint8_t	dev_index;		/* currently unused */
207184610Salfred	uint8_t	ep_index;
208184610Salfred	uint8_t	ep_no;			/* bEndpointNumber */
209184610Salfred};
210184610Salfred
211239238Shselaskystruct usb_fs_open_stream {
212239214Shselasky	struct usb_fs_open fs_open;
213239214Shselasky	uint16_t stream_id;
214239214Shselasky};
215239214Shselasky
216192984Sthompsastruct usb_fs_close {
217184610Salfred	uint8_t	ep_index;
218184610Salfred};
219184610Salfred
220192984Sthompsastruct usb_fs_clear_stall_sync {
221184610Salfred	uint8_t	ep_index;
222184610Salfred};
223184610Salfred
224192984Sthompsastruct usb_gen_quirk {
225184610Salfred	uint16_t index;			/* Quirk Index */
226184610Salfred	uint16_t vid;			/* Vendor ID */
227184610Salfred	uint16_t pid;			/* Product ID */
228184610Salfred	uint16_t bcdDeviceLow;		/* Low Device Revision */
229184610Salfred	uint16_t bcdDeviceHigh;		/* High Device Revision */
230184610Salfred	uint16_t reserved[2];
231184610Salfred	/*
232184610Salfred	 * String version of quirk including terminating zero. See UQ_XXX in
233188942Sthompsa	 * "usb_quirk.h".
234184610Salfred	 */
235184610Salfred	char	quirkname[64 - 14];
236184610Salfred};
237184610Salfred
238184610Salfred/* USB controller */
239192984Sthompsa#define	USB_REQUEST		_IOWR('U', 1, struct usb_ctl_request)
240184610Salfred#define	USB_SETDEBUG		_IOW ('U', 2, int)
241184610Salfred#define	USB_DISCOVER		_IO  ('U', 3)
242192984Sthompsa#define	USB_DEVICEINFO		_IOWR('U', 4, struct usb_device_info)
243192984Sthompsa#define	USB_DEVICESTATS		_IOR ('U', 5, struct usb_device_stats)
244184610Salfred#define	USB_DEVICEENUMERATE	_IOW ('U', 6, int)
245184610Salfred
246184610Salfred/* Generic HID device */
247192984Sthompsa#define	USB_GET_REPORT_DESC	_IOWR('U', 21, struct usb_gen_descriptor)
248184610Salfred#define	USB_SET_IMMED		_IOW ('U', 22, int)
249192984Sthompsa#define	USB_GET_REPORT		_IOWR('U', 23, struct usb_gen_descriptor)
250192984Sthompsa#define	USB_SET_REPORT		_IOW ('U', 24, struct usb_gen_descriptor)
251184610Salfred#define	USB_GET_REPORT_ID	_IOR ('U', 25, int)
252184610Salfred
253184610Salfred/* Generic USB device */
254184610Salfred#define	USB_GET_CONFIG		_IOR ('U', 100, int)
255184610Salfred#define	USB_SET_CONFIG		_IOW ('U', 101, int)
256192984Sthompsa#define	USB_GET_ALTINTERFACE	_IOWR('U', 102, struct usb_alt_interface)
257192984Sthompsa#define	USB_SET_ALTINTERFACE	_IOWR('U', 103, struct usb_alt_interface)
258192984Sthompsa#define	USB_GET_DEVICE_DESC	_IOR ('U', 105, struct usb_device_descriptor)
259192984Sthompsa#define	USB_GET_CONFIG_DESC	_IOR ('U', 106, struct usb_config_descriptor)
260192984Sthompsa#define	USB_GET_RX_INTERFACE_DESC _IOR ('U', 107, struct usb_interface_descriptor)
261192984Sthompsa#define	USB_GET_RX_ENDPOINT_DESC _IOR ('U', 108, struct usb_endpoint_descriptor)
262192984Sthompsa#define	USB_GET_FULL_DESC	_IOWR('U', 109, struct usb_gen_descriptor)
263192984Sthompsa#define	USB_GET_STRING_DESC	_IOWR('U', 110, struct usb_gen_descriptor)
264192984Sthompsa#define	USB_DO_REQUEST		_IOWR('U', 111, struct usb_ctl_request)
265192984Sthompsa#define	USB_GET_DEVICEINFO	_IOR ('U', 112, struct usb_device_info)
266184610Salfred#define	USB_SET_RX_SHORT_XFER	_IOW ('U', 113, int)
267184610Salfred#define	USB_SET_RX_TIMEOUT	_IOW ('U', 114, int)
268184610Salfred#define	USB_GET_RX_FRAME_SIZE	_IOR ('U', 115, int)
269184610Salfred#define	USB_GET_RX_BUFFER_SIZE	_IOR ('U', 117, int)
270184610Salfred#define	USB_SET_RX_BUFFER_SIZE	_IOW ('U', 118, int)
271184610Salfred#define	USB_SET_RX_STALL_FLAG	_IOW ('U', 119, int)
272184610Salfred#define	USB_SET_TX_STALL_FLAG	_IOW ('U', 120, int)
273192984Sthompsa#define	USB_GET_IFACE_DRIVER	_IOWR('U', 121, struct usb_gen_descriptor)
274184610Salfred#define	USB_CLAIM_INTERFACE	_IOW ('U', 122, int)
275184610Salfred#define	USB_RELEASE_INTERFACE	_IOW ('U', 123, int)
276184610Salfred#define	USB_IFACE_DRIVER_ACTIVE	_IOW ('U', 124, int)
277184610Salfred#define	USB_IFACE_DRIVER_DETACH	_IOW ('U', 125, int)
278184610Salfred#define	USB_GET_PLUGTIME	_IOR ('U', 126, uint32_t)
279192984Sthompsa#define	USB_READ_DIR		_IOW ('U', 127, struct usb_read_dir)
280246789Shselasky/* 128 - 134 unused */
281246789Shselasky#define	USB_GET_POWER_USAGE	_IOR ('U', 135, int)
282184610Salfred#define	USB_SET_TX_FORCE_SHORT	_IOW ('U', 136, int)
283184610Salfred#define	USB_SET_TX_TIMEOUT	_IOW ('U', 137, int)
284184610Salfred#define	USB_GET_TX_FRAME_SIZE	_IOR ('U', 138, int)
285184610Salfred#define	USB_GET_TX_BUFFER_SIZE	_IOR ('U', 139, int)
286184610Salfred#define	USB_SET_TX_BUFFER_SIZE	_IOW ('U', 140, int)
287192984Sthompsa#define	USB_GET_TX_INTERFACE_DESC _IOR ('U', 141, struct usb_interface_descriptor)
288192984Sthompsa#define	USB_GET_TX_ENDPOINT_DESC _IOR ('U', 142, struct usb_endpoint_descriptor)
289184610Salfred#define	USB_SET_PORT_ENABLE	_IOW ('U', 143, int)
290184610Salfred#define	USB_SET_PORT_DISABLE	_IOW ('U', 144, int)
291184610Salfred#define	USB_SET_POWER_MODE	_IOW ('U', 145, int)
292184610Salfred#define	USB_GET_POWER_MODE	_IOR ('U', 146, int)
293188987Sthompsa#define	USB_SET_TEMPLATE	_IOW ('U', 147, int)
294188987Sthompsa#define	USB_GET_TEMPLATE	_IOR ('U', 148, int)
295184610Salfred
296184610Salfred/* Modem device */
297184610Salfred#define	USB_GET_CM_OVER_DATA	_IOR ('U', 180, int)
298184610Salfred#define	USB_SET_CM_OVER_DATA	_IOW ('U', 181, int)
299184610Salfred
300227463Shselasky/* GPIO control */
301227463Shselasky#define	USB_GET_GPIO		_IOR ('U', 182, int)
302227463Shselasky#define	USB_SET_GPIO		_IOW ('U', 183, int)
303227463Shselasky
304184610Salfred/* USB file system interface */
305192984Sthompsa#define	USB_FS_START		_IOW ('U', 192, struct usb_fs_start)
306192984Sthompsa#define	USB_FS_STOP		_IOW ('U', 193, struct usb_fs_stop)
307192984Sthompsa#define	USB_FS_COMPLETE		_IOR ('U', 194, struct usb_fs_complete)
308192984Sthompsa#define	USB_FS_INIT		_IOW ('U', 195, struct usb_fs_init)
309192984Sthompsa#define	USB_FS_UNINIT		_IOW ('U', 196, struct usb_fs_uninit)
310192984Sthompsa#define	USB_FS_OPEN		_IOWR('U', 197, struct usb_fs_open)
311192984Sthompsa#define	USB_FS_CLOSE		_IOW ('U', 198, struct usb_fs_close)
312192984Sthompsa#define	USB_FS_CLEAR_STALL_SYNC _IOW ('U', 199, struct usb_fs_clear_stall_sync)
313239238Shselasky#define	USB_FS_OPEN_STREAM	_IOWR('U', 200, struct usb_fs_open_stream)
314184610Salfred
315184610Salfred/* USB quirk system interface */
316192984Sthompsa#define	USB_DEV_QUIRK_GET	_IOWR('Q', 0, struct usb_gen_quirk)
317192984Sthompsa#define	USB_QUIRK_NAME_GET	_IOWR('Q', 1, struct usb_gen_quirk)
318192984Sthompsa#define	USB_DEV_QUIRK_ADD	_IOW ('Q', 2, struct usb_gen_quirk)
319192984Sthompsa#define	USB_DEV_QUIRK_REMOVE	_IOW ('Q', 3, struct usb_gen_quirk)
320184610Salfred
321194230Sthompsa#endif					/* _USB_IOCTL_H_ */
322