• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2009 Andrew Thompson
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 #ifndef _USB_USBDI_H_
29 #define _USB_USBDI_H_
30 
31 struct usb_fifo;
32 struct usb_xfer;
33 struct usb_device;
34 struct usb_attach_arg;
35 struct usb_interface;
36 struct usb_endpoint;
37 struct usb_page_cache;
38 struct usb_page_search;
39 struct usb_process;
40 struct usb_proc_msg;
41 struct usb_mbuf;
42 struct usb_fs_privdata;
43 struct mbuf;
44 
45 typedef enum {	/* keep in sync with usb_errstr_table */
46 	USB_ERR_NORMAL_COMPLETION = 0,
47 	USB_ERR_PENDING_REQUESTS,	/* 1 */
48 	USB_ERR_NOT_STARTED,		/* 2 */
49 	USB_ERR_INVAL,			/* 3 */
50 	USB_ERR_NOMEM,			/* 4 */
51 	USB_ERR_CANCELLED,		/* 5 */
52 	USB_ERR_BAD_ADDRESS,		/* 6 */
53 	USB_ERR_BAD_BUFSIZE,		/* 7 */
54 	USB_ERR_BAD_FLAG,		/* 8 */
55 	USB_ERR_NO_CALLBACK,		/* 9 */
56 	USB_ERR_IN_USE,			/* 10 */
57 	USB_ERR_NO_ADDR,		/* 11 */
58 	USB_ERR_NO_PIPE,		/* 12 */
59 	USB_ERR_ZERO_NFRAMES,		/* 13 */
60 	USB_ERR_ZERO_MAXP,		/* 14 */
61 	USB_ERR_SET_ADDR_FAILED,	/* 15 */
62 	USB_ERR_NO_POWER,		/* 16 */
63 	USB_ERR_TOO_DEEP,		/* 17 */
64 	USB_ERR_IOERROR,		/* 18 */
65 	USB_ERR_NOT_CONFIGURED,		/* 19 */
66 	USB_ERR_TIMEOUT,		/* 20 */
67 	USB_ERR_SHORT_XFER,		/* 21 */
68 	USB_ERR_STALLED,		/* 22 */
69 	USB_ERR_INTERRUPTED,		/* 23 */
70 	USB_ERR_DMA_LOAD_FAILED,	/* 24 */
71 	USB_ERR_BAD_CONTEXT,		/* 25 */
72 	USB_ERR_NO_ROOT_HUB,		/* 26 */
73 	USB_ERR_NO_INTR_THREAD,		/* 27 */
74 	USB_ERR_NOT_LOCKED,		/* 28 */
75 	USB_ERR_MAX
76 } usb_error_t;
77 
78 /*
79  * Flags for transfers
80  */
81 #define	USB_FORCE_SHORT_XFER	0x0001	/* force a short transmit last */
82 #define	USB_SHORT_XFER_OK	0x0004	/* allow short reads */
83 #define	USB_DELAY_STATUS_STAGE	0x0010	/* insert delay before STATUS stage */
84 #define	USB_USER_DATA_PTR	0x0020	/* internal flag */
85 #define	USB_MULTI_SHORT_OK	0x0040	/* allow multiple short frames */
86 #define	USB_MANUAL_STATUS	0x0080	/* manual ctrl status */
87 
88 #define	USB_NO_TIMEOUT 0
89 #define	USB_DEFAULT_TIMEOUT 5000	/* 5000 ms = 5 seconds */
90 
91 #if defined(_KERNEL)
92 /* typedefs */
93 
94 typedef void (usb_callback_t)(struct usb_xfer *, usb_error_t);
95 typedef void (usb_proc_callback_t)(struct usb_proc_msg *);
96 typedef usb_error_t (usb_handle_req_t)(struct usb_device *,
97     struct usb_device_request *, const void **, uint16_t *);
98 
99 typedef int (usb_fifo_open_t)(struct usb_fifo *fifo, int fflags);
100 typedef void (usb_fifo_close_t)(struct usb_fifo *fifo, int fflags);
101 typedef int (usb_fifo_ioctl_t)(struct usb_fifo *fifo, u_long cmd, void *addr, int fflags);
102 typedef void (usb_fifo_cmd_t)(struct usb_fifo *fifo);
103 typedef void (usb_fifo_filter_t)(struct usb_fifo *fifo, struct usb_mbuf *m);
104 
105 /* USB events */
106 typedef void (*usb_dev_configured_t)(void *, struct usb_device *,
107     struct usb_attach_arg *);
108 
109 /*
110  * The following macros are used used to convert milliseconds into
111  * HZ. We use 1024 instead of 1000 milliseconds per second to save a
112  * full division.
113  */
114 #define	USB_MS_HZ 1024
115 
116 #define	USB_MS_TO_TICKS(ms) \
117   (((uint32_t)((((uint32_t)(ms)) * ((uint32_t)(hz))) + USB_MS_HZ - 1)) / USB_MS_HZ)
118 
119 /*
120  * Common queue structure for USB transfers.
121  */
122 struct usb_xfer_queue {
123 	TAILQ_HEAD(, usb_xfer) head;
124 	struct usb_xfer *curr;		/* current USB transfer processed */
125 	void	(*command) (struct usb_xfer_queue *pq);
126 	uint8_t	recurse_1:1;
127 	uint8_t	recurse_2:1;
128 };
129 
130 /*
131  * The following structure defines an USB endpoint
132  * USB endpoint.
133  */
134 struct usb_endpoint {
135 	/* queue of USB transfers */
136 	struct usb_xfer_queue endpoint_q[USB_MAX_EP_STREAMS];
137 
138 	struct usb_endpoint_descriptor *edesc;
139 	struct usb_endpoint_ss_comp_descriptor *ecomp;
140 	const struct usb_pipe_methods *methods;	/* set by HC driver */
141 
142 	uint16_t isoc_next;
143 
144 	uint8_t	toggle_next:1;		/* next data toggle value */
145 	uint8_t	is_stalled:1;		/* set if endpoint is stalled */
146 	uint8_t	is_synced:1;		/* set if we a synchronised */
147 	uint8_t	unused:5;
148 	uint8_t	iface_index;		/* not used by "default endpoint" */
149 
150 	uint8_t refcount_alloc;		/* allocation refcount */
151 	uint8_t refcount_bw;		/* bandwidth refcount */
152 #define	USB_EP_REF_MAX 0x3f
153 
154 	/* High-Speed resource allocation (valid if "refcount_bw" > 0) */
155 
156 	uint8_t	usb_smask;		/* USB start mask */
157 	uint8_t	usb_cmask;		/* USB complete mask */
158 	uint8_t	usb_uframe;		/* USB microframe */
159 
160 	/* USB endpoint mode, see USB_EP_MODE_XXX */
161 
162 	uint8_t ep_mode;
163 };
164 
165 /*
166  * The following structure defines an USB interface.
167  */
168 struct usb_interface {
169 	struct usb_interface_descriptor *idesc;
170 	device_t subdev;
171 	/* Current alternate interface index, from 0 to 255 */
172 	uint8_t	alt_index;
173 	uint8_t	parent_iface_index;
174 
175 	/* Linux compat */
176 	struct usb_host_interface *altsetting;
177 	struct usb_host_interface *cur_altsetting;
178 	struct usb_device *linux_udev;
179 	void   *bsd_priv_sc;		/* device specific information */
180 	char   *pnpinfo;		/* additional PnP-info for this interface */
181 	uint8_t	num_altsetting;		/* number of alternate settings */
182 	uint8_t	bsd_iface_index;
183 };
184 
185 /*
186  * The following structure defines a set of USB transfer flags.
187  */
188 struct usb_xfer_flags {
189 	uint8_t	force_short_xfer:1;	/* force a short transmit transfer
190 					 * last */
191 	uint8_t	short_xfer_ok:1;	/* allow short receive transfers */
192 	uint8_t	short_frames_ok:1;	/* allow short frames */
193 	uint8_t	pipe_bof:1;		/* block pipe on failure */
194 	uint8_t	proxy_buffer:1;		/* makes buffer size a factor of
195 					 * "max_frame_size" */
196 	uint8_t	ext_buffer:1;		/* uses external DMA buffer */
197 	uint8_t	manual_status:1;	/* non automatic status stage on
198 					 * control transfers */
199 	uint8_t	no_pipe_ok:1;		/* set if "USB_ERR_NO_PIPE" error can
200 					 * be ignored */
201 	uint8_t	stall_pipe:1;		/* set if the endpoint belonging to
202 					 * this USB transfer should be stalled
203 					 * before starting this transfer! */
204 	uint8_t pre_scale_frames:1;	/* "usb_config->frames" is
205 					 * assumed to give the
206 					 * buffering time in
207 					 * milliseconds and is
208 					 * converted into the nearest
209 					 * number of frames when the
210 					 * USB transfer is setup. This
211 					 * option only has effect for
212 					 * ISOCHRONOUS transfers.
213 					 */
214 };
215 
216 /*
217  * The following structure define an USB configuration, that basically
218  * is used when setting up an USB transfer.
219  */
220 struct usb_config {
221 	usb_callback_t *callback;	/* USB transfer callback */
222 	usb_frlength_t bufsize;	/* total pipe buffer size in bytes */
223 	usb_frcount_t frames;		/* maximum number of USB frames */
224 	usb_timeout_t interval;	/* interval in milliseconds */
225 #define	USB_DEFAULT_INTERVAL	0
226 	usb_timeout_t timeout;		/* transfer timeout in milliseconds */
227 	struct usb_xfer_flags flags;	/* transfer flags */
228 	usb_stream_t stream_id;		/* USB3.0 specific */
229 	enum usb_hc_mode usb_mode;	/* host or device mode */
230 	uint8_t	type;			/* pipe type */
231 	uint8_t	endpoint;		/* pipe number */
232 	uint8_t	direction;		/* pipe direction */
233 	uint8_t	ep_index;		/* pipe index match to use */
234 	uint8_t	if_index;		/* "ifaces" index to use */
235 };
236 
237 /*
238  * Use these macro when defining USB device ID arrays if you want to
239  * have your driver module automatically loaded in host, device or
240  * both modes respectively:
241  */
242 #if USB_HAVE_ID_SECTION
243 #define	STRUCT_USB_HOST_ID \
244     struct usb_device_id __section("usb_host_id")
245 #define	STRUCT_USB_DEVICE_ID \
246     struct usb_device_id __section("usb_device_id")
247 #define	STRUCT_USB_DUAL_ID \
248     struct usb_device_id __section("usb_dual_id")
249 #else
250 #define	STRUCT_USB_HOST_ID \
251     struct usb_device_id
252 #define	STRUCT_USB_DEVICE_ID \
253     struct usb_device_id
254 #define	STRUCT_USB_DUAL_ID \
255     struct usb_device_id
256 #endif			/* USB_HAVE_ID_SECTION */
257 
258 /*
259  * The following structure is used when looking up an USB driver for
260  * an USB device. It is inspired by the Linux structure called
261  * "usb_device_id".
262  */
263 struct usb_device_id {
264 	/* Hook for driver specific information */
265 	unsigned long driver_info;
266 
267 	/* Used for product specific matches; the BCD range is inclusive */
268 	uint16_t idVendor;
269 	uint16_t idProduct;
270 	uint16_t bcdDevice_lo;
271 	uint16_t bcdDevice_hi;
272 
273 	/* Used for device class matches */
274 	uint8_t	bDeviceClass;
275 	uint8_t	bDeviceSubClass;
276 	uint8_t	bDeviceProtocol;
277 
278 	/* Used for interface class matches */
279 	uint8_t	bInterfaceClass;
280 	uint8_t	bInterfaceSubClass;
281 	uint8_t	bInterfaceProtocol;
282 
283 	/* Select which fields to match against */
284 	uint8_t	match_flag_vendor:1;
285 	uint8_t	match_flag_product:1;
286 	uint8_t	match_flag_dev_lo:1;
287 	uint8_t	match_flag_dev_hi:1;
288 
289 	uint8_t	match_flag_dev_class:1;
290 	uint8_t	match_flag_dev_subclass:1;
291 	uint8_t	match_flag_dev_protocol:1;
292 	uint8_t	match_flag_int_class:1;
293 
294 	uint8_t	match_flag_int_subclass:1;
295 	uint8_t	match_flag_int_protocol:1;
296 	uint8_t	match_flag_unused:6;
297 
298 #if USB_HAVE_COMPAT_LINUX
299 	/* which fields to match against */
300 	uint16_t match_flags;
301 #define	USB_DEVICE_ID_MATCH_VENDOR		0x0001
302 #define	USB_DEVICE_ID_MATCH_PRODUCT		0x0002
303 #define	USB_DEVICE_ID_MATCH_DEV_LO		0x0004
304 #define	USB_DEVICE_ID_MATCH_DEV_HI		0x0008
305 #define	USB_DEVICE_ID_MATCH_DEV_CLASS		0x0010
306 #define	USB_DEVICE_ID_MATCH_DEV_SUBCLASS	0x0020
307 #define	USB_DEVICE_ID_MATCH_DEV_PROTOCOL	0x0040
308 #define	USB_DEVICE_ID_MATCH_INT_CLASS		0x0080
309 #define	USB_DEVICE_ID_MATCH_INT_SUBCLASS	0x0100
310 #define	USB_DEVICE_ID_MATCH_INT_PROTOCOL	0x0200
311 #endif
312 } __aligned(32);
313 
314 /* check that the size of the structure above is correct */
315 extern char usb_device_id_assert[(sizeof(struct usb_device_id) == 32) ? 1 : -1];
316 
317 #define	USB_VENDOR(vend)			\
318   .match_flag_vendor = 1, .idVendor = (vend)
319 
320 #define	USB_PRODUCT(prod)			\
321   .match_flag_product = 1, .idProduct = (prod)
322 
323 #define	USB_VP(vend,prod)			\
324   USB_VENDOR(vend), USB_PRODUCT(prod)
325 
326 #define	USB_VPI(vend,prod,info)			\
327   USB_VENDOR(vend), USB_PRODUCT(prod), USB_DRIVER_INFO(info)
328 
329 #define	USB_DEV_BCD_GTEQ(lo)	/* greater than or equal */ \
330   .match_flag_dev_lo = 1, .bcdDevice_lo = (lo)
331 
332 #define	USB_DEV_BCD_LTEQ(hi)	/* less than or equal */ \
333   .match_flag_dev_hi = 1, .bcdDevice_hi = (hi)
334 
335 #define	USB_DEV_CLASS(dc)			\
336   .match_flag_dev_class = 1, .bDeviceClass = (dc)
337 
338 #define	USB_DEV_SUBCLASS(dsc)			\
339   .match_flag_dev_subclass = 1, .bDeviceSubClass = (dsc)
340 
341 #define	USB_DEV_PROTOCOL(dp)			\
342   .match_flag_dev_protocol = 1, .bDeviceProtocol = (dp)
343 
344 #define	USB_IFACE_CLASS(ic)			\
345   .match_flag_int_class = 1, .bInterfaceClass = (ic)
346 
347 #define	USB_IFACE_SUBCLASS(isc)			\
348   .match_flag_int_subclass = 1, .bInterfaceSubClass = (isc)
349 
350 #define	USB_IFACE_PROTOCOL(ip)			\
351   .match_flag_int_protocol = 1, .bInterfaceProtocol = (ip)
352 
353 #define	USB_IF_CSI(class,subclass,info)			\
354   USB_IFACE_CLASS(class), USB_IFACE_SUBCLASS(subclass), USB_DRIVER_INFO(info)
355 
356 #define	USB_DRIVER_INFO(n)			\
357   .driver_info = (n)
358 
359 #define	USB_GET_DRIVER_INFO(did)		\
360   (did)->driver_info
361 
362 /*
363  * The following structure keeps information that is used to match
364  * against an array of "usb_device_id" elements.
365  */
366 struct usbd_lookup_info {
367 	uint16_t idVendor;
368 	uint16_t idProduct;
369 	uint16_t bcdDevice;
370 	uint8_t	bDeviceClass;
371 	uint8_t	bDeviceSubClass;
372 	uint8_t	bDeviceProtocol;
373 	uint8_t	bInterfaceClass;
374 	uint8_t	bInterfaceSubClass;
375 	uint8_t	bInterfaceProtocol;
376 	uint8_t	bIfaceIndex;
377 	uint8_t	bIfaceNum;
378 	uint8_t	bConfigIndex;
379 	uint8_t	bConfigNum;
380 };
381 
382 /* Structure used by probe and attach */
383 
384 struct usb_attach_arg {
385 	struct usbd_lookup_info info;
386 	device_t temp_dev;		/* for internal use */
387 	unsigned long driver_info;	/* for internal use */
388 	void *driver_ivar;
389 	struct usb_device *device;	/* current device */
390 	struct usb_interface *iface;	/* current interface */
391 	enum usb_hc_mode usb_mode;	/* host or device mode */
392 	uint8_t	port;
393 	uint8_t dev_state;
394 #define UAA_DEV_READY		0
395 #define UAA_DEV_DISABLED	1
396 #define UAA_DEV_EJECTING	2
397 };
398 
399 /*
400  * General purpose locking wrappers to ease supporting
401  * USB polled mode:
402  */
403 #ifdef INVARIANTS
404 #define	USB_MTX_ASSERT(_m, _t) do {		\
405 	if (!USB_IN_POLLING_MODE_FUNC())	\
406 		mtx_assert(_m, _t);		\
407 } while (0)
408 #else
409 #define	USB_MTX_ASSERT(_m, _t) do { } while (0)
410 #endif
411 
412 #define	USB_MTX_LOCK(_m) do {			\
413 	if (!USB_IN_POLLING_MODE_FUNC())	\
414 		mtx_lock(_m);			\
415 } while (0)
416 
417 #define	USB_MTX_UNLOCK(_m) do {			\
418 	if (!USB_IN_POLLING_MODE_FUNC())	\
419 		mtx_unlock(_m);			\
420 } while (0)
421 
422 #define	USB_MTX_LOCK_SPIN(_m) do {		\
423 	if (!USB_IN_POLLING_MODE_FUNC())	\
424 		mtx_lock_spin(_m);		\
425 } while (0)
426 
427 #define	USB_MTX_UNLOCK_SPIN(_m) do {		\
428 	if (!USB_IN_POLLING_MODE_FUNC())	\
429 		mtx_unlock_spin(_m);		\
430 } while (0)
431 
432 /*
433  * The following is a wrapper for the callout structure to ease
434  * porting the code to other platforms.
435  */
436 
437 
438 /* USB transfer states */
439 
440 #define	USB_ST_SETUP		0
441 #define	USB_ST_TRANSFERRED	1
442 #define	USB_ST_ERROR		2
443 
444 /* USB handle request states */
445 #define	USB_HR_NOT_COMPLETE	0
446 #define	USB_HR_COMPLETE_OK	1
447 #define	USB_HR_COMPLETE_ERR	2
448 
449 /*
450  * The following macro will return the current state of an USB
451  * transfer like defined by the "USB_ST_XXX" enums.
452  */
453 #define	USB_GET_STATE(xfer) (usbd_xfer_state(xfer))
454 
455 /*
456  * The following structure defines the USB process message header.
457  */
458 struct usb_proc_msg {
459 	TAILQ_ENTRY(usb_proc_msg) pm_qentry;
460 	usb_proc_callback_t *pm_callback;
461 	usb_size_t pm_num;
462 };
463 
464 #define	USB_FIFO_TX 0
465 #define	USB_FIFO_RX 1
466 
467 /*
468  * Locking note for the following functions.  All the
469  * "usb_fifo_cmd_t" and "usb_fifo_filter_t" functions are called
470  * locked. The others are called unlocked.
471  */
472 struct usb_fifo_methods {
473 	usb_fifo_open_t *f_open;
474 	usb_fifo_close_t *f_close;
475 	usb_fifo_ioctl_t *f_ioctl;
476 	/*
477 	 * NOTE: The post-ioctl callback is called after the USB reference
478 	 * gets locked in the IOCTL handler:
479 	 */
480 	usb_fifo_ioctl_t *f_ioctl_post;
481 	usb_fifo_cmd_t *f_start_read;
482 	usb_fifo_cmd_t *f_stop_read;
483 	usb_fifo_cmd_t *f_start_write;
484 	usb_fifo_cmd_t *f_stop_write;
485 	usb_fifo_filter_t *f_filter_read;
486 	usb_fifo_filter_t *f_filter_write;
487 	const char *basename[4];
488 	const char *postfix[4];
489 };
490 
491 struct usb_fifo_sc {
492 	struct usb_fifo *fp[2];
493 	struct usb_fs_privdata *dev;
494 };
495 
496 const char *usbd_errstr(usb_error_t error);
497 void	*usbd_find_descriptor(struct usb_device *udev, void *id,
498 	    uint8_t iface_index, uint8_t type, uint8_t type_mask,
499 	    uint8_t subtype, uint8_t subtype_mask);
500 struct usb_config_descriptor *usbd_get_config_descriptor(
501 	    struct usb_device *udev);
502 struct usb_device_descriptor *usbd_get_device_descriptor(
503 	    struct usb_device *udev);
504 struct usb_interface *usbd_get_iface(struct usb_device *udev,
505 	    uint8_t iface_index);
506 struct usb_interface_descriptor *usbd_get_interface_descriptor(
507 	    struct usb_interface *iface);
508 struct usb_endpoint *usbd_get_endpoint(struct usb_device *udev, uint8_t iface_index,
509 		    const struct usb_config *setup);
510 struct usb_endpoint *usbd_get_ep_by_addr(struct usb_device *udev, uint8_t ea_val);
511 usb_error_t	usbd_interface_count(struct usb_device *udev, uint8_t *count);
512 enum usb_hc_mode usbd_get_mode(struct usb_device *udev);
513 enum usb_dev_speed usbd_get_speed(struct usb_device *udev);
514 void	device_set_usb_desc(device_t dev);
515 void	usb_pause_mtx(struct mtx *mtx, int _ticks);
516 usb_error_t	usbd_set_pnpinfo(struct usb_device *udev,
517 			uint8_t iface_index, const char *pnpinfo);
518 usb_error_t	usbd_add_dynamic_quirk(struct usb_device *udev,
519 			uint16_t quirk);
520 usb_error_t	usbd_set_endpoint_mode(struct usb_device *udev,
521 			struct usb_endpoint *ep, uint8_t ep_mode);
522 uint8_t		usbd_get_endpoint_mode(struct usb_device *udev,
523 			struct usb_endpoint *ep);
524 
525 const struct usb_device_id *usbd_lookup_id_by_info(
526 	    const struct usb_device_id *id, usb_size_t sizeof_id,
527 	    const struct usbd_lookup_info *info);
528 int	usbd_lookup_id_by_uaa(const struct usb_device_id *id,
529 	    usb_size_t sizeof_id, struct usb_attach_arg *uaa);
530 
531 usb_error_t usbd_do_request_flags(struct usb_device *udev, struct mtx *mtx,
532 		    struct usb_device_request *req, void *data, uint16_t flags,
533 		    uint16_t *actlen, usb_timeout_t timeout);
534 #define	usbd_do_request(u,m,r,d) \
535   usbd_do_request_flags(u, m, r, d, 0, NULL, USB_DEFAULT_TIMEOUT)
536 
537 uint8_t	usbd_clear_stall_callback(struct usb_xfer *xfer1,
538 	    struct usb_xfer *xfer2);
539 uint8_t	usbd_get_interface_altindex(struct usb_interface *iface);
540 usb_error_t usbd_set_alt_interface_index(struct usb_device *udev,
541 	    uint8_t iface_index, uint8_t alt_index);
542 uint32_t usbd_get_isoc_fps(struct usb_device *udev);
543 usb_error_t usbd_transfer_setup(struct usb_device *udev,
544 	    const uint8_t *ifaces, struct usb_xfer **pxfer,
545 	    const struct usb_config *setup_start, uint16_t n_setup,
546 	    void *priv_sc, struct mtx *priv_mtx);
547 void	usbd_transfer_submit(struct usb_xfer *xfer);
548 void	usbd_transfer_clear_stall(struct usb_xfer *xfer);
549 void	usbd_transfer_drain(struct usb_xfer *xfer);
550 uint8_t	usbd_transfer_pending(struct usb_xfer *xfer);
551 void	usbd_transfer_start(struct usb_xfer *xfer);
552 void	usbd_transfer_stop(struct usb_xfer *xfer);
553 void	usbd_transfer_unsetup(struct usb_xfer **pxfer, uint16_t n_setup);
554 void	usbd_transfer_poll(struct usb_xfer **ppxfer, uint16_t max);
555 void	usbd_set_parent_iface(struct usb_device *udev, uint8_t iface_index,
556 	    uint8_t parent_index);
557 uint8_t	usbd_get_bus_index(struct usb_device *udev);
558 uint8_t	usbd_get_device_index(struct usb_device *udev);
559 void	usbd_set_power_mode(struct usb_device *udev, uint8_t power_mode);
560 uint8_t	usbd_filter_power_mode(struct usb_device *udev, uint8_t power_mode);
561 uint8_t	usbd_device_attached(struct usb_device *udev);
562 
563 usb_frlength_t
564 	usbd_xfer_old_frame_length(struct usb_xfer *xfer, usb_frcount_t frindex);
565 void	usbd_xfer_status(struct usb_xfer *xfer, int *actlen, int *sumlen,
566 	    int *aframes, int *nframes);
567 struct usb_page_cache *usbd_xfer_get_frame(struct usb_xfer *, usb_frcount_t);
568 void	*usbd_xfer_get_frame_buffer(struct usb_xfer *, usb_frcount_t);
569 void	*usbd_xfer_softc(struct usb_xfer *xfer);
570 void	*usbd_xfer_get_priv(struct usb_xfer *xfer);
571 void	usbd_xfer_set_priv(struct usb_xfer *xfer, void *);
572 void	usbd_xfer_set_interval(struct usb_xfer *xfer, int);
573 uint8_t	usbd_xfer_state(struct usb_xfer *xfer);
574 void	usbd_xfer_set_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
575 	    void *ptr, usb_frlength_t len);
576 void	usbd_xfer_frame_data(struct usb_xfer *xfer, usb_frcount_t frindex,
577 	    void **ptr, int *len);
578 void	usbd_xfer_set_frame_offset(struct usb_xfer *xfer, usb_frlength_t offset,
579 	    usb_frcount_t frindex);
580 usb_frlength_t usbd_xfer_max_len(struct usb_xfer *xfer);
581 usb_frlength_t usbd_xfer_max_framelen(struct usb_xfer *xfer);
582 usb_frcount_t usbd_xfer_max_frames(struct usb_xfer *xfer);
583 uint8_t	usbd_xfer_get_fps_shift(struct usb_xfer *xfer);
584 usb_frlength_t usbd_xfer_frame_len(struct usb_xfer *xfer,
585 	    usb_frcount_t frindex);
586 void	usbd_xfer_set_frame_len(struct usb_xfer *xfer, usb_frcount_t frindex,
587 	    usb_frlength_t len);
588 void	usbd_xfer_set_timeout(struct usb_xfer *xfer, int timeout);
589 void	usbd_xfer_set_frames(struct usb_xfer *xfer, usb_frcount_t n);
590 void	usbd_xfer_set_stall(struct usb_xfer *xfer);
591 int	usbd_xfer_is_stalled(struct usb_xfer *xfer);
592 void	usbd_xfer_set_flag(struct usb_xfer *xfer, int flag);
593 void	usbd_xfer_clr_flag(struct usb_xfer *xfer, int flag);
594 uint16_t usbd_xfer_get_timestamp(struct usb_xfer *xfer);
595 uint8_t usbd_xfer_maxp_was_clamped(struct usb_xfer *xfer);
596 
597 int	copyin(const void *uaddr, void *kaddr, size_t len);
598 int	copyout(const void *kaddr, void *uaddr, size_t len);
599 int	usbd_copy_from_user(void *dest, uint32_t dest_len, const void *src, uint32_t src_len);
600 int	usbd_copy_to_user(void *dest, uint32_t dest_len, const void *src, uint32_t src_len);
601 void	usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset,
602 	    const void *ptr, usb_frlength_t len);
603 int	usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset,
604 	    const void *ptr, usb_frlength_t len);
605 void	usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset,
606 	    void *ptr, usb_frlength_t len);
607 int	usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset,
608 	    void *ptr, usb_frlength_t len);
609 void	usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset,
610 	    struct usb_page_search *res);
611 void	usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset,
612 	    struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len);
613 void	usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset,
614 	    usb_frlength_t len);
615 void	usbd_start_re_enumerate(struct usb_device *udev);
616 usb_error_t
617 	usbd_start_set_config(struct usb_device *, uint8_t);
618 
619 int	usb_fifo_attach(struct usb_device *udev, void *priv_sc,
620 	    struct mtx *priv_mtx, struct usb_fifo_methods *pm,
621 	    struct usb_fifo_sc *f_sc, uint16_t unit, int16_t subunit,
622 	    uint8_t iface_index, uid_t uid, gid_t gid, int mode);
623 void	usb_fifo_detach(struct usb_fifo_sc *f_sc);
624 int	usb_fifo_alloc_buffer(struct usb_fifo *f, uint32_t bufsize,
625 	    uint16_t nbuf);
626 void	usb_fifo_free_buffer(struct usb_fifo *f);
627 uint32_t usb_fifo_put_bytes_max(struct usb_fifo *fifo);
628 void	usb_fifo_put_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
629 	    usb_frlength_t offset, usb_frlength_t len, uint8_t what);
630 void	usb_fifo_put_data_linear(struct usb_fifo *fifo, void *ptr,
631 	    usb_size_t len, uint8_t what);
632 uint8_t	usb_fifo_put_data_buffer(struct usb_fifo *f, void *ptr, usb_size_t len);
633 void	usb_fifo_put_data_error(struct usb_fifo *fifo);
634 uint8_t	usb_fifo_get_data(struct usb_fifo *fifo, struct usb_page_cache *pc,
635 	    usb_frlength_t offset, usb_frlength_t len, usb_frlength_t *actlen,
636 	    uint8_t what);
637 uint8_t	usb_fifo_get_data_linear(struct usb_fifo *fifo, void *ptr,
638 	    usb_size_t len, usb_size_t *actlen, uint8_t what);
639 uint8_t	usb_fifo_get_data_buffer(struct usb_fifo *f, void **pptr,
640 	    usb_size_t *plen);
641 void	usb_fifo_reset(struct usb_fifo *f);
642 void	usb_fifo_wakeup(struct usb_fifo *f);
643 void	usb_fifo_get_data_error(struct usb_fifo *fifo);
644 void	*usb_fifo_softc(struct usb_fifo *fifo);
645 void	usb_fifo_set_close_zlp(struct usb_fifo *, uint8_t);
646 void	usb_fifo_set_write_defrag(struct usb_fifo *, uint8_t);
647 void	usb_fifo_free(struct usb_fifo *f);
648 #endif /* _KERNEL */
649 #endif /* _USB_USBDI_H_ */
650