xref: /freebsd-src/sys/dev/usb/usb_hub.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
102ac6454SAndrew Thompson /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
402ac6454SAndrew Thompson  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
502ac6454SAndrew Thompson  *
602ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
702ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
802ac6454SAndrew Thompson  * are met:
902ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1002ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1102ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1202ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1302ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1402ac6454SAndrew Thompson  *
1502ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1602ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1702ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1802ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1902ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2002ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2102ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2202ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2302ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2402ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2502ac6454SAndrew Thompson  * SUCH DAMAGE.
2602ac6454SAndrew Thompson  */
2702ac6454SAndrew Thompson 
2875973647SAndrew Thompson #ifndef _USB_HUB_H_
2975973647SAndrew Thompson #define	_USB_HUB_H_
3002ac6454SAndrew Thompson 
3102ac6454SAndrew Thompson /*
3202ac6454SAndrew Thompson  * The following structure defines an USB port.
3302ac6454SAndrew Thompson  */
34760bc48eSAndrew Thompson struct usb_port {
3502ac6454SAndrew Thompson 	uint8_t	restartcnt;
3602ac6454SAndrew Thompson #define	USB_RESTART_MAX 5
3702ac6454SAndrew Thompson 	uint8_t	device_index;		/* zero means not valid */
38f29a0724SAndrew Thompson 	enum usb_hc_mode usb_mode;	/* host or device mode */
39a0d53e0bSHans Petter Selasky #if USB_HAVE_TT_SUPPORT
40a0d53e0bSHans Petter Selasky 	struct usb_device_request req_reset_tt __aligned(4);
41a0d53e0bSHans Petter Selasky #endif
4202ac6454SAndrew Thompson };
4302ac6454SAndrew Thompson 
4402ac6454SAndrew Thompson /*
4502ac6454SAndrew Thompson  * The following structure defines an USB HUB.
4602ac6454SAndrew Thompson  */
47760bc48eSAndrew Thompson struct usb_hub {
48760bc48eSAndrew Thompson 	struct usb_device *hubudev;	/* the HUB device */
49e0a69b51SAndrew Thompson 	usb_error_t (*explore) (struct usb_device *hub);
5002ac6454SAndrew Thompson 	void   *hubsoftc;
51a0d53e0bSHans Petter Selasky #if USB_HAVE_TT_SUPPORT
52a0d53e0bSHans Petter Selasky 	struct usb_udev_msg tt_msg[2];
53a0d53e0bSHans Petter Selasky #endif
54f9cb546cSAndrew Thompson 	usb_size_t uframe_usage[USB_HS_MICRO_FRAMES_MAX];
5502ac6454SAndrew Thompson 	uint16_t portpower;		/* mA per USB port */
5602ac6454SAndrew Thompson 	uint8_t	isoc_last_time;
5702ac6454SAndrew Thompson 	uint8_t	nports;
582c79a775SHans Petter Selasky #if (USB_HAVE_FIXED_PORT == 0)
59760bc48eSAndrew Thompson 	struct usb_port ports[0];
602c79a775SHans Petter Selasky #else
612c79a775SHans Petter Selasky 	struct usb_port ports[USB_MAX_PORTS];
622c79a775SHans Petter Selasky #endif
6302ac6454SAndrew Thompson };
6402ac6454SAndrew Thompson 
6502ac6454SAndrew Thompson /* function prototypes */
6602ac6454SAndrew Thompson 
67f12c6c29SAndrew Thompson void	usb_hs_bandwidth_alloc(struct usb_xfer *xfer);
68f12c6c29SAndrew Thompson void	usb_hs_bandwidth_free(struct usb_xfer *xfer);
69a593f6b8SAndrew Thompson void	usb_bus_port_set_device(struct usb_bus *bus, struct usb_port *up,
70760bc48eSAndrew Thompson 	    struct usb_device *udev, uint8_t device_index);
71a593f6b8SAndrew Thompson struct usb_device *usb_bus_port_get_device(struct usb_bus *bus,
72760bc48eSAndrew Thompson 	    struct usb_port *up);
73a593f6b8SAndrew Thompson void	usb_needs_explore(struct usb_bus *bus, uint8_t do_probe);
74a593f6b8SAndrew Thompson void	usb_needs_explore_all(void);
75a593f6b8SAndrew Thompson void	usb_bus_power_update(struct usb_bus *bus);
76a593f6b8SAndrew Thompson void	usb_bus_powerd(struct usb_bus *bus);
77760bc48eSAndrew Thompson void	uhub_root_intr(struct usb_bus *, const uint8_t *, uint8_t);
78963169b4SHans Petter Selasky usb_error_t uhub_query_info(struct usb_device *, uint8_t *, uint8_t *);
79d64e9217SHans Petter Selasky void	uhub_explore_handle_re_enumerate(struct usb_device *);
8002ac6454SAndrew Thompson 
8175973647SAndrew Thompson #endif					/* _USB_HUB_H_ */
82