xref: /freebsd/sys/dev/usb/usb_hub.h (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
1 /* $FreeBSD$ */
2 /*-
3  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4  *
5  * Copyright (c) 2008 Hans Petter Selasky. 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_HUB_H_
30 #define	_USB_HUB_H_
31 
32 /*
33  * The following structure defines an USB port.
34  */
35 struct usb_port {
36 	uint8_t	restartcnt;
37 #define	USB_RESTART_MAX 5
38 	uint8_t	device_index;		/* zero means not valid */
39 	enum usb_hc_mode usb_mode;	/* host or device mode */
40 #if USB_HAVE_TT_SUPPORT
41 	struct usb_device_request req_reset_tt __aligned(4);
42 #endif
43 };
44 
45 /*
46  * The following structure defines an USB HUB.
47  */
48 struct usb_hub {
49 	struct usb_device *hubudev;	/* the HUB device */
50 	usb_error_t (*explore) (struct usb_device *hub);
51 	void   *hubsoftc;
52 #if USB_HAVE_TT_SUPPORT
53 	struct usb_udev_msg tt_msg[2];
54 #endif
55 	usb_size_t uframe_usage[USB_HS_MICRO_FRAMES_MAX];
56 	uint16_t portpower;		/* mA per USB port */
57 	uint8_t	isoc_last_time;
58 	uint8_t	nports;
59 #if (USB_HAVE_FIXED_PORT == 0)
60 	struct usb_port ports[0];
61 #else
62 	struct usb_port ports[USB_MAX_PORTS];
63 #endif
64 };
65 
66 /* function prototypes */
67 
68 void	usb_hs_bandwidth_alloc(struct usb_xfer *xfer);
69 void	usb_hs_bandwidth_free(struct usb_xfer *xfer);
70 void	usb_bus_port_set_device(struct usb_bus *bus, struct usb_port *up,
71 	    struct usb_device *udev, uint8_t device_index);
72 struct usb_device *usb_bus_port_get_device(struct usb_bus *bus,
73 	    struct usb_port *up);
74 void	usb_needs_explore(struct usb_bus *bus, uint8_t do_probe);
75 void	usb_needs_explore_all(void);
76 void	usb_bus_power_update(struct usb_bus *bus);
77 void	usb_bus_powerd(struct usb_bus *bus);
78 void	uhub_root_intr(struct usb_bus *, const uint8_t *, uint8_t);
79 usb_error_t uhub_query_info(struct usb_device *, uint8_t *, uint8_t *);
80 void	uhub_explore_handle_re_enumerate(struct usb_device *);
81 
82 #endif					/* _USB_HUB_H_ */
83