xref: /freebsd/sys/dev/usb/usb_bus.h (revision e892b3fe36cbf5aff5352b4e1f6dbde630cead67)
102ac6454SAndrew Thompson /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
302ac6454SAndrew Thompson  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
402ac6454SAndrew Thompson  *
502ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
602ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
702ac6454SAndrew Thompson  * are met:
802ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
902ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1002ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1102ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1202ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1302ac6454SAndrew Thompson  *
1402ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1502ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1602ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1702ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1802ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1902ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2002ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2102ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2202ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2302ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2402ac6454SAndrew Thompson  * SUCH DAMAGE.
2502ac6454SAndrew Thompson  */
2602ac6454SAndrew Thompson 
2775973647SAndrew Thompson #ifndef _USB_BUS_H_
2875973647SAndrew Thompson #define	_USB_BUS_H_
2902ac6454SAndrew Thompson 
3002ac6454SAndrew Thompson /*
31fde87526SAndrew Thompson  * The following structure defines the USB explore message sent to the USB
32fde87526SAndrew Thompson  * explore process.
3302ac6454SAndrew Thompson  */
3402ac6454SAndrew Thompson 
35760bc48eSAndrew Thompson struct usb_bus_msg {
36760bc48eSAndrew Thompson 	struct usb_proc_msg hdr;
37760bc48eSAndrew Thompson 	struct usb_bus *bus;
3802ac6454SAndrew Thompson };
3902ac6454SAndrew Thompson 
4002ac6454SAndrew Thompson /*
4102ac6454SAndrew Thompson  * The following structure defines the USB statistics structure.
4202ac6454SAndrew Thompson  */
43760bc48eSAndrew Thompson struct usb_bus_stat {
4402ac6454SAndrew Thompson 	uint32_t uds_requests[4];
4502ac6454SAndrew Thompson };
4602ac6454SAndrew Thompson 
4702ac6454SAndrew Thompson /*
4802ac6454SAndrew Thompson  * The following structure defines an USB BUS. There is one USB BUS
4902ac6454SAndrew Thompson  * for every Host or Device controller.
5002ac6454SAndrew Thompson  */
51760bc48eSAndrew Thompson struct usb_bus {
52760bc48eSAndrew Thompson 	struct usb_bus_stat stats_err;
53760bc48eSAndrew Thompson 	struct usb_bus_stat stats_ok;
54ff182db6SHans Petter Selasky #if USB_HAVE_ROOT_MOUNT_HOLD
5502ac6454SAndrew Thompson 	struct root_hold_token *bus_roothold;
56ff182db6SHans Petter Selasky #endif
579b3a48eeSHans Petter Selasky 
589b3a48eeSHans Petter Selasky #if USB_HAVE_PER_BUS_PROCESS
599b3a48eeSHans Petter Selasky #define	USB_BUS_GIANT_PROC(bus) (&(bus)->giant_callback_proc)
609b3a48eeSHans Petter Selasky #define	USB_BUS_NON_GIANT_PROC(bus) (&(bus)->non_giant_callback_proc)
619b3a48eeSHans Petter Selasky #define	USB_BUS_EXPLORE_PROC(bus) (&(bus)->explore_proc)
629b3a48eeSHans Petter Selasky #define	USB_BUS_CONTROL_XFER_PROC(bus) (&(bus)->control_xfer_proc)
639b3a48eeSHans Petter Selasky 
6402ac6454SAndrew Thompson 	/*
6502ac6454SAndrew Thompson 	 * There are two callback processes. One for Giant locked
6602ac6454SAndrew Thompson 	 * callbacks. One for non-Giant locked callbacks. This should
6702ac6454SAndrew Thompson 	 * avoid congestion and reduce response time in most cases.
6802ac6454SAndrew Thompson 	 */
69760bc48eSAndrew Thompson 	struct usb_process giant_callback_proc;
70760bc48eSAndrew Thompson 	struct usb_process non_giant_callback_proc;
71672c9965SAndrew Thompson 
72672c9965SAndrew Thompson 	/* Explore process */
73760bc48eSAndrew Thompson 	struct usb_process explore_proc;
74672c9965SAndrew Thompson 
75672c9965SAndrew Thompson 	/* Control request process */
76760bc48eSAndrew Thompson 	struct usb_process control_xfer_proc;
779b3a48eeSHans Petter Selasky #endif
78672c9965SAndrew Thompson 
79760bc48eSAndrew Thompson 	struct usb_bus_msg explore_msg[2];
80760bc48eSAndrew Thompson 	struct usb_bus_msg detach_msg[2];
81760bc48eSAndrew Thompson 	struct usb_bus_msg attach_msg[2];
822e141748SHans Petter Selasky 	struct usb_bus_msg suspend_msg[2];
832e141748SHans Petter Selasky 	struct usb_bus_msg resume_msg[2];
84563ab081SHans Petter Selasky 	struct usb_bus_msg reset_msg[2];
852e141748SHans Petter Selasky 	struct usb_bus_msg shutdown_msg[2];
8602ac6454SAndrew Thompson 	/*
8702ac6454SAndrew Thompson 	 * This mutex protects the USB hardware:
8802ac6454SAndrew Thompson 	 */
8902ac6454SAndrew Thompson 	struct mtx bus_mtx;
90760bc48eSAndrew Thompson 	struct usb_xfer_queue intr_q;
91760bc48eSAndrew Thompson 	struct usb_callout power_wdog;	/* power management */
9202ac6454SAndrew Thompson 
9302ac6454SAndrew Thompson 	device_t parent;
9402ac6454SAndrew Thompson 	device_t bdev;			/* filled by HC driver */
9502ac6454SAndrew Thompson 
968755859aSAndrew Thompson #if USB_HAVE_BUSDMA
97760bc48eSAndrew Thompson 	struct usb_dma_parent_tag dma_parent_tag[1];
98760bc48eSAndrew Thompson 	struct usb_dma_tag dma_tags[USB_BUS_DMA_TAG_MAX];
998755859aSAndrew Thompson #endif
100*e892b3feSHans Petter Selasky 	const struct usb_bus_methods *methods;	/* filled by HC driver */
101760bc48eSAndrew Thompson 	struct usb_device **devices;
10202ac6454SAndrew Thompson 
103e376f9c3SWeongyo Jeong 	struct ifnet *ifp;	/* only for USB Packet Filter */
10418ec6525SWeongyo Jeong 
105e0a69b51SAndrew Thompson 	usb_power_mask_t hw_power_state;	/* see USB_HW_POWER_XXX */
106f9cb546cSAndrew Thompson 	usb_size_t uframe_usage[USB_HS_MICRO_FRAMES_MAX];
107578d0effSAndrew Thompson 
10802ac6454SAndrew Thompson 	uint16_t isoc_time_last;	/* in milliseconds */
10902ac6454SAndrew Thompson 
11002ac6454SAndrew Thompson 	uint8_t	alloc_failed;		/* Set if memory allocation failed. */
11102ac6454SAndrew Thompson 	uint8_t	driver_added_refcount;	/* Current driver generation count */
1128d2dd5ddSAndrew Thompson 	enum usb_revision usbrev;	/* USB revision. See "USB_REV_XXX". */
11302ac6454SAndrew Thompson 
11402ac6454SAndrew Thompson 	uint8_t	devices_max;		/* maximum number of USB devices */
1152e141748SHans Petter Selasky 	uint8_t	do_probe;		/* set if USB should be re-probed */
1162e141748SHans Petter Selasky 	uint8_t no_explore;		/* don't explore USB ports */
11702ac6454SAndrew Thompson };
11802ac6454SAndrew Thompson 
11975973647SAndrew Thompson #endif					/* _USB_BUS_H_ */
120