xref: /freebsd/sys/dev/usb/usb_ioctl.h (revision 6e660824a82f590542932de52f128db584029893)
1 /* $FreeBSD$ */
2 /*-
3  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
5  * Copyright (c) 1998 Lennart Augustsson. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _USB_IOCTL_H_
30 #define	_USB_IOCTL_H_
31 
32 #ifndef USB_GLOBAL_INCLUDE_FILE
33 #include <sys/ioccom.h>
34 
35 /* Building "kdump" depends on these includes */
36 
37 #include <dev/usb/usb_endian.h>
38 #include <dev/usb/usb.h>
39 #endif
40 
41 #define	USB_DEVICE_NAME "usbctl"
42 #define	USB_DEVICE_DIR "usb"
43 #define	USB_GENERIC_NAME "ugen"
44 #define	USB_TEMPLATE_SYSCTL "hw.usb.template"	/* integer type */
45 
46 /* Definition of valid template sysctl values */
47 
48 enum {
49 	USB_TEMP_MSC,		/* USB Mass Storage */
50 	USB_TEMP_CDCE,		/* USB CDC Ethernet */
51 	USB_TEMP_MTP,		/* Message Transfer Protocol */
52 	USB_TEMP_MODEM,		/* USB CDC Modem */
53 	USB_TEMP_AUDIO,		/* USB Audio */
54 	USB_TEMP_KBD,		/* USB Keyboard */
55 	USB_TEMP_MOUSE,		/* USB Mouse */
56 	USB_TEMP_MAX,
57 };
58 
59 struct usb_read_dir {
60 #ifdef COMPAT_32BIT
61 	uint64_t urd_data;
62 #else
63 	void   *urd_data;
64 #endif
65 	uint32_t urd_startentry;
66 	uint32_t urd_maxlen;
67 };
68 
69 struct usb_ctl_request {
70 #ifdef COMPAT_32BIT
71 	uint64_t ucr_data;
72 #else
73 	void   *ucr_data;
74 #endif
75 	uint16_t ucr_flags;
76 	uint16_t ucr_actlen;		/* actual length transferred */
77 	uint8_t	ucr_addr;		/* zero - currently not used */
78 	struct usb_device_request ucr_request;
79 };
80 
81 struct usb_alt_interface {
82 	uint8_t	uai_interface_index;
83 	uint8_t	uai_alt_index;
84 };
85 
86 struct usb_gen_descriptor {
87 #ifdef COMPAT_32BIT
88 	uint64_t ugd_data;
89 #else
90 	void   *ugd_data;
91 #endif
92 	uint16_t ugd_lang_id;
93 	uint16_t ugd_maxlen;
94 	uint16_t ugd_actlen;
95 	uint16_t ugd_offset;
96 	uint8_t	ugd_config_index;
97 	uint8_t	ugd_string_index;
98 	uint8_t	ugd_iface_index;
99 	uint8_t	ugd_altif_index;
100 	uint8_t	ugd_endpt_index;
101 	uint8_t	ugd_report_type;
102 	uint8_t	reserved[8];
103 };
104 
105 struct usb_device_info {
106 	uint16_t udi_productNo;
107 	uint16_t udi_vendorNo;
108 	uint16_t udi_releaseNo;
109 	uint16_t udi_power;		/* power consumption in mA, 0 if
110 					 * selfpowered */
111 	uint8_t	udi_bus;
112 	uint8_t	udi_addr;		/* device address */
113 	uint8_t	udi_index;		/* device index */
114 	uint8_t	udi_class;
115 	uint8_t	udi_subclass;
116 	uint8_t	udi_protocol;
117 	uint8_t	udi_config_no;		/* current config number */
118 	uint8_t	udi_config_index;	/* current config index */
119 	uint8_t	udi_speed;		/* see "USB_SPEED_XXX" */
120 	uint8_t	udi_mode;		/* see "USB_MODE_XXX" */
121 	uint8_t	udi_nports;
122 	uint8_t	udi_hubaddr;		/* parent HUB address */
123 	uint8_t	udi_hubindex;		/* parent HUB device index */
124 	uint8_t	udi_hubport;		/* parent HUB port */
125 	uint8_t	udi_power_mode;		/* see "USB_POWER_MODE_XXX" */
126 	uint8_t	udi_suspended;		/* set if device is suspended */
127 	uint8_t	udi_reserved[16];	/* leave space for the future */
128 	char	udi_product[128];
129 	char	udi_vendor[128];
130 	char	udi_serial[64];
131 	char	udi_release[8];
132 };
133 
134 #define	USB_DEVICE_PORT_PATH_MAX 32
135 
136 struct usb_device_port_path {
137 	uint8_t udp_bus;		/* which bus we are on */
138 	uint8_t udp_index;		/* which device index */
139 	uint8_t udp_port_level;		/* how many levels: 0, 1, 2 ... */
140 	uint8_t udp_port_no[USB_DEVICE_PORT_PATH_MAX];
141 };
142 
143 struct usb_device_stats {
144 	uint32_t uds_requests_ok[4];	/* Indexed by transfer type UE_XXX */
145 	uint32_t uds_requests_fail[4];	/* Indexed by transfer type UE_XXX */
146 };
147 
148 struct usb_fs_start {
149 	uint8_t	ep_index;
150 };
151 
152 struct usb_fs_stop {
153 	uint8_t	ep_index;
154 };
155 
156 struct usb_fs_complete {
157 	uint8_t	ep_index;
158 };
159 
160 /* This structure is used for all endpoint types */
161 struct usb_fs_endpoint {
162 	/*
163 	 * NOTE: isochronous USB transfer only use one buffer, but can have
164 	 * multiple frame lengths !
165 	 */
166 #ifdef COMPAT_32BIT
167 	uint64_t ppBuffer;
168 	uint64_t pLength;
169 #else
170 	void  **ppBuffer;		/* pointer to userland buffers */
171 	uint32_t *pLength;		/* pointer to frame lengths, updated
172 					 * to actual length */
173 #endif
174 	uint32_t nFrames;		/* number of frames */
175 	uint32_t aFrames;		/* actual number of frames */
176 	uint16_t flags;
177 	/* a single short frame will terminate */
178 #define	USB_FS_FLAG_SINGLE_SHORT_OK 0x0001
179 	/* multiple short frames are allowed */
180 #define	USB_FS_FLAG_MULTI_SHORT_OK 0x0002
181 	/* all frame(s) transmitted are short terminated */
182 #define	USB_FS_FLAG_FORCE_SHORT 0x0004
183 	/* will do a clear-stall before xfer */
184 #define	USB_FS_FLAG_CLEAR_STALL 0x0008
185 	uint16_t timeout;		/* in milliseconds */
186 	/* isocronous completion time in milliseconds - used for echo cancel */
187 	uint16_t isoc_time_complete;
188 	/* timeout value for no timeout */
189 #define	USB_FS_TIMEOUT_NONE 0
190 	int	status;			/* see USB_ERR_XXX */
191 };
192 
193 struct usb_fs_init {
194 	/* userland pointer to endpoints structure */
195 #ifdef COMPAT_32BIT
196 	uint64_t pEndpoints;
197 #else
198 	struct usb_fs_endpoint *pEndpoints;
199 #endif
200 	/* maximum number of endpoints */
201 	uint8_t	ep_index_max;
202 };
203 
204 struct usb_fs_uninit {
205 	uint8_t	dummy;			/* zero */
206 };
207 
208 struct usb_fs_open {
209 #define	USB_FS_MAX_BUFSIZE (1 << 18)
210 	uint32_t max_bufsize;
211 #define	USB_FS_MAX_FRAMES		(1U << 12)
212 #define	USB_FS_MAX_FRAMES_PRE_SCALE	(1U << 31)	/* for ISOCHRONOUS transfers */
213 	uint32_t max_frames;		/* read and write */
214 	uint16_t max_packet_length;	/* read only */
215 	uint8_t	dev_index;		/* currently unused */
216 	uint8_t	ep_index;
217 	uint8_t	ep_no;			/* bEndpointNumber */
218 };
219 
220 struct usb_fs_open_stream {
221 	struct usb_fs_open fs_open;
222 	uint16_t stream_id;
223 };
224 
225 struct usb_fs_close {
226 	uint8_t	ep_index;
227 };
228 
229 struct usb_fs_clear_stall_sync {
230 	uint8_t	ep_index;
231 };
232 
233 struct usb_gen_quirk {
234 	uint16_t index;			/* Quirk Index */
235 	uint16_t vid;			/* Vendor ID */
236 	uint16_t pid;			/* Product ID */
237 	uint16_t bcdDeviceLow;		/* Low Device Revision */
238 	uint16_t bcdDeviceHigh;		/* High Device Revision */
239 	uint16_t reserved[2];
240 	/*
241 	 * String version of quirk including terminating zero. See UQ_XXX in
242 	 * "usb_quirk.h".
243 	 */
244 	char	quirkname[64 - 14];
245 };
246 
247 /* USB controller */
248 #define	USB_REQUEST		_IOWR('U', 1, struct usb_ctl_request)
249 #define	USB_SETDEBUG		_IOW ('U', 2, int)
250 #define	USB_DISCOVER		_IO  ('U', 3)
251 #define	USB_DEVICEINFO		_IOWR('U', 4, struct usb_device_info)
252 #define	USB_DEVICESTATS		_IOR ('U', 5, struct usb_device_stats)
253 #define	USB_DEVICEENUMERATE	_IOW ('U', 6, int)
254 
255 /* Generic HID device */
256 #define	USB_GET_REPORT_DESC	_IOWR('U', 21, struct usb_gen_descriptor)
257 #define	USB_SET_IMMED		_IOW ('U', 22, int)
258 #define	USB_GET_REPORT		_IOWR('U', 23, struct usb_gen_descriptor)
259 #define	USB_SET_REPORT		_IOW ('U', 24, struct usb_gen_descriptor)
260 #define	USB_GET_REPORT_ID	_IOR ('U', 25, int)
261 
262 /* Generic USB device */
263 #define	USB_GET_CONFIG		_IOR ('U', 100, int)
264 #define	USB_SET_CONFIG		_IOW ('U', 101, int)
265 #define	USB_GET_ALTINTERFACE	_IOWR('U', 102, struct usb_alt_interface)
266 #define	USB_SET_ALTINTERFACE	_IOWR('U', 103, struct usb_alt_interface)
267 #define	USB_GET_DEVICE_DESC	_IOR ('U', 105, struct usb_device_descriptor)
268 #define	USB_GET_CONFIG_DESC	_IOR ('U', 106, struct usb_config_descriptor)
269 #define	USB_GET_RX_INTERFACE_DESC _IOR ('U', 107, struct usb_interface_descriptor)
270 #define	USB_GET_RX_ENDPOINT_DESC _IOR ('U', 108, struct usb_endpoint_descriptor)
271 #define	USB_GET_FULL_DESC	_IOWR('U', 109, struct usb_gen_descriptor)
272 #define	USB_GET_STRING_DESC	_IOWR('U', 110, struct usb_gen_descriptor)
273 #define	USB_DO_REQUEST		_IOWR('U', 111, struct usb_ctl_request)
274 #define	USB_GET_DEVICEINFO	_IOR ('U', 112, struct usb_device_info)
275 #define	USB_SET_RX_SHORT_XFER	_IOW ('U', 113, int)
276 #define	USB_SET_RX_TIMEOUT	_IOW ('U', 114, int)
277 #define	USB_GET_RX_FRAME_SIZE	_IOR ('U', 115, int)
278 #define	USB_GET_RX_BUFFER_SIZE	_IOR ('U', 117, int)
279 #define	USB_SET_RX_BUFFER_SIZE	_IOW ('U', 118, int)
280 #define	USB_SET_RX_STALL_FLAG	_IOW ('U', 119, int)
281 #define	USB_SET_TX_STALL_FLAG	_IOW ('U', 120, int)
282 #define	USB_GET_IFACE_DRIVER	_IOWR('U', 121, struct usb_gen_descriptor)
283 #define	USB_CLAIM_INTERFACE	_IOW ('U', 122, int)
284 #define	USB_RELEASE_INTERFACE	_IOW ('U', 123, int)
285 #define	USB_IFACE_DRIVER_ACTIVE	_IOW ('U', 124, int)
286 #define	USB_IFACE_DRIVER_DETACH	_IOW ('U', 125, int)
287 #define	USB_GET_PLUGTIME	_IOR ('U', 126, uint32_t)
288 #define	USB_READ_DIR		_IOW ('U', 127, struct usb_read_dir)
289 /* 128 - 133 unused */
290 #define	USB_GET_DEV_PORT_PATH	_IOR ('U', 134, struct usb_device_port_path)
291 #define	USB_GET_POWER_USAGE	_IOR ('U', 135, int)
292 #define	USB_SET_TX_FORCE_SHORT	_IOW ('U', 136, int)
293 #define	USB_SET_TX_TIMEOUT	_IOW ('U', 137, int)
294 #define	USB_GET_TX_FRAME_SIZE	_IOR ('U', 138, int)
295 #define	USB_GET_TX_BUFFER_SIZE	_IOR ('U', 139, int)
296 #define	USB_SET_TX_BUFFER_SIZE	_IOW ('U', 140, int)
297 #define	USB_GET_TX_INTERFACE_DESC _IOR ('U', 141, struct usb_interface_descriptor)
298 #define	USB_GET_TX_ENDPOINT_DESC _IOR ('U', 142, struct usb_endpoint_descriptor)
299 #define	USB_SET_PORT_ENABLE	_IOW ('U', 143, int)
300 #define	USB_SET_PORT_DISABLE	_IOW ('U', 144, int)
301 #define	USB_SET_POWER_MODE	_IOW ('U', 145, int)
302 #define	USB_GET_POWER_MODE	_IOR ('U', 146, int)
303 #define	USB_SET_TEMPLATE	_IOW ('U', 147, int)
304 #define	USB_GET_TEMPLATE	_IOR ('U', 148, int)
305 
306 /* Modem device */
307 #define	USB_GET_CM_OVER_DATA	_IOR ('U', 180, int)
308 #define	USB_SET_CM_OVER_DATA	_IOW ('U', 181, int)
309 
310 /* GPIO control */
311 #define	USB_GET_GPIO		_IOR ('U', 182, int)
312 #define	USB_SET_GPIO		_IOW ('U', 183, int)
313 
314 /* USB file system interface */
315 #define	USB_FS_START		_IOW ('U', 192, struct usb_fs_start)
316 #define	USB_FS_STOP		_IOW ('U', 193, struct usb_fs_stop)
317 #define	USB_FS_COMPLETE		_IOR ('U', 194, struct usb_fs_complete)
318 #define	USB_FS_INIT		_IOW ('U', 195, struct usb_fs_init)
319 #define	USB_FS_UNINIT		_IOW ('U', 196, struct usb_fs_uninit)
320 #define	USB_FS_OPEN		_IOWR('U', 197, struct usb_fs_open)
321 #define	USB_FS_CLOSE		_IOW ('U', 198, struct usb_fs_close)
322 #define	USB_FS_CLEAR_STALL_SYNC _IOW ('U', 199, struct usb_fs_clear_stall_sync)
323 #define	USB_FS_OPEN_STREAM	_IOWR('U', 200, struct usb_fs_open_stream)
324 
325 /* USB quirk system interface */
326 #define	USB_DEV_QUIRK_GET	_IOWR('Q', 0, struct usb_gen_quirk)
327 #define	USB_QUIRK_NAME_GET	_IOWR('Q', 1, struct usb_gen_quirk)
328 #define	USB_DEV_QUIRK_ADD	_IOW ('Q', 2, struct usb_gen_quirk)
329 #define	USB_DEV_QUIRK_REMOVE	_IOW ('Q', 3, struct usb_gen_quirk)
330 
331 #endif					/* _USB_IOCTL_H_ */
332