xref: /freebsd/sys/dev/usb/usb_bus.h (revision 7082625d976f0ad1b4207a12afe3c72e2acd9145)
102ac6454SAndrew Thompson /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
3718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4718cf2ccSPedro F. Giffuni  *
5*7082625dSHans Petter Selasky  * Copyright (c) 2008-2019 Hans Petter Selasky. All rights reserved.
602ac6454SAndrew Thompson  *
702ac6454SAndrew Thompson  * Redistribution and use in source and binary forms, with or without
802ac6454SAndrew Thompson  * modification, are permitted provided that the following conditions
902ac6454SAndrew Thompson  * are met:
1002ac6454SAndrew Thompson  * 1. Redistributions of source code must retain the above copyright
1102ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer.
1202ac6454SAndrew Thompson  * 2. Redistributions in binary form must reproduce the above copyright
1302ac6454SAndrew Thompson  *    notice, this list of conditions and the following disclaimer in the
1402ac6454SAndrew Thompson  *    documentation and/or other materials provided with the distribution.
1502ac6454SAndrew Thompson  *
1602ac6454SAndrew Thompson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1702ac6454SAndrew Thompson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1802ac6454SAndrew Thompson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1902ac6454SAndrew Thompson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2002ac6454SAndrew Thompson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2102ac6454SAndrew Thompson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2202ac6454SAndrew Thompson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2302ac6454SAndrew Thompson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2402ac6454SAndrew Thompson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2502ac6454SAndrew Thompson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2602ac6454SAndrew Thompson  * SUCH DAMAGE.
2702ac6454SAndrew Thompson  */
2802ac6454SAndrew Thompson 
2975973647SAndrew Thompson #ifndef _USB_BUS_H_
3075973647SAndrew Thompson #define	_USB_BUS_H_
3102ac6454SAndrew Thompson 
32b78e84d1SHans Petter Selasky struct usb_fs_privdata;
33b78e84d1SHans Petter Selasky 
3402ac6454SAndrew Thompson /*
35fde87526SAndrew Thompson  * The following structure defines the USB explore message sent to the USB
36fde87526SAndrew Thompson  * explore process.
3702ac6454SAndrew Thompson  */
3802ac6454SAndrew Thompson 
39760bc48eSAndrew Thompson struct usb_bus_msg {
40760bc48eSAndrew Thompson 	struct usb_proc_msg hdr;
41760bc48eSAndrew Thompson 	struct usb_bus *bus;
4202ac6454SAndrew Thompson };
4302ac6454SAndrew Thompson 
4402ac6454SAndrew Thompson /*
4502ac6454SAndrew Thompson  * The following structure defines an USB BUS. There is one USB BUS
4602ac6454SAndrew Thompson  * for every Host or Device controller.
4702ac6454SAndrew Thompson  */
48760bc48eSAndrew Thompson struct usb_bus {
49ff182db6SHans Petter Selasky #if USB_HAVE_ROOT_MOUNT_HOLD
5002ac6454SAndrew Thompson 	struct root_hold_token *bus_roothold;
51ff182db6SHans Petter Selasky #endif
529b3a48eeSHans Petter Selasky 
5343ea03d7SHans Petter Selasky /* convenience macros */
5443ea03d7SHans Petter Selasky #define	USB_BUS_TT_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus)
5543ea03d7SHans Petter Selasky #define	USB_BUS_CS_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus)
5643ea03d7SHans Petter Selasky 
579b3a48eeSHans Petter Selasky #if USB_HAVE_PER_BUS_PROCESS
589b3a48eeSHans Petter Selasky #define	USB_BUS_GIANT_PROC(bus) (&(bus)->giant_callback_proc)
5943ea03d7SHans Petter Selasky #define	USB_BUS_NON_GIANT_ISOC_PROC(bus) (&(bus)->non_giant_isoc_callback_proc)
6043ea03d7SHans Petter Selasky #define	USB_BUS_NON_GIANT_BULK_PROC(bus) (&(bus)->non_giant_bulk_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)
6302ac6454SAndrew Thompson 	/*
6443ea03d7SHans Petter Selasky 	 * There are three callback processes. One for Giant locked
6543ea03d7SHans Petter Selasky 	 * callbacks. One for non-Giant locked non-periodic callbacks
6643ea03d7SHans Petter Selasky 	 * and one for non-Giant locked periodic callbacks. This
6743ea03d7SHans Petter Selasky 	 * should avoid congestion and reduce response time in most
6843ea03d7SHans Petter Selasky 	 * cases.
6902ac6454SAndrew Thompson 	 */
70760bc48eSAndrew Thompson 	struct usb_process giant_callback_proc;
7143ea03d7SHans Petter Selasky 	struct usb_process non_giant_isoc_callback_proc;
7243ea03d7SHans Petter Selasky 	struct usb_process non_giant_bulk_callback_proc;
73672c9965SAndrew Thompson 
74672c9965SAndrew Thompson 	/* Explore process */
75760bc48eSAndrew Thompson 	struct usb_process explore_proc;
76672c9965SAndrew Thompson 
77672c9965SAndrew Thompson 	/* Control request process */
78760bc48eSAndrew Thompson 	struct usb_process control_xfer_proc;
799b3a48eeSHans Petter Selasky #endif
80672c9965SAndrew Thompson 
81760bc48eSAndrew Thompson 	struct usb_bus_msg explore_msg[2];
82760bc48eSAndrew Thompson 	struct usb_bus_msg detach_msg[2];
83760bc48eSAndrew Thompson 	struct usb_bus_msg attach_msg[2];
842e141748SHans Petter Selasky 	struct usb_bus_msg suspend_msg[2];
852e141748SHans Petter Selasky 	struct usb_bus_msg resume_msg[2];
86563ab081SHans Petter Selasky 	struct usb_bus_msg reset_msg[2];
872e141748SHans Petter Selasky 	struct usb_bus_msg shutdown_msg[2];
88b78e84d1SHans Petter Selasky #if USB_HAVE_UGEN
89b78e84d1SHans Petter Selasky 	struct usb_bus_msg cleanup_msg[2];
90b78e84d1SHans Petter Selasky 	LIST_HEAD(,usb_fs_privdata) pd_cleanup_list;
91b78e84d1SHans Petter Selasky #endif
9202ac6454SAndrew Thompson 	/*
9302ac6454SAndrew Thompson 	 * This mutex protects the USB hardware:
9402ac6454SAndrew Thompson 	 */
9502ac6454SAndrew Thompson 	struct mtx bus_mtx;
962fe7ad87SHans Petter Selasky 	struct mtx bus_spin_lock;
97760bc48eSAndrew Thompson 	struct usb_xfer_queue intr_q;
98760bc48eSAndrew Thompson 	struct usb_callout power_wdog;	/* power management */
9902ac6454SAndrew Thompson 
10002ac6454SAndrew Thompson 	device_t parent;
10102ac6454SAndrew Thompson 	device_t bdev;			/* filled by HC driver */
10202ac6454SAndrew Thompson 
1038755859aSAndrew Thompson #if USB_HAVE_BUSDMA
104760bc48eSAndrew Thompson 	struct usb_dma_parent_tag dma_parent_tag[1];
105760bc48eSAndrew Thompson 	struct usb_dma_tag dma_tags[USB_BUS_DMA_TAG_MAX];
1068755859aSAndrew Thompson #endif
107e892b3feSHans Petter Selasky 	const struct usb_bus_methods *methods;	/* filled by HC driver */
108760bc48eSAndrew Thompson 	struct usb_device **devices;
10902ac6454SAndrew Thompson 
110e376f9c3SWeongyo Jeong 	struct ifnet *ifp;	/* only for USB Packet Filter */
11118ec6525SWeongyo Jeong 
112e0a69b51SAndrew Thompson 	usb_power_mask_t hw_power_state;	/* see USB_HW_POWER_XXX */
113f9cb546cSAndrew Thompson 	usb_size_t uframe_usage[USB_HS_MICRO_FRAMES_MAX];
114578d0effSAndrew Thompson 
11502ac6454SAndrew Thompson 	uint16_t isoc_time_last;	/* in milliseconds */
11602ac6454SAndrew Thompson 
11702ac6454SAndrew Thompson 	uint8_t	alloc_failed;		/* Set if memory allocation failed. */
11802ac6454SAndrew Thompson 	uint8_t	driver_added_refcount;	/* Current driver generation count */
1198d2dd5ddSAndrew Thompson 	enum usb_revision usbrev;	/* USB revision. See "USB_REV_XXX". */
12002ac6454SAndrew Thompson 
12102ac6454SAndrew Thompson 	uint8_t	devices_max;		/* maximum number of USB devices */
1222e141748SHans Petter Selasky 	uint8_t	do_probe;		/* set if USB should be re-probed */
1232e141748SHans Petter Selasky 	uint8_t no_explore;		/* don't explore USB ports */
124b217d184SHans Petter Selasky 	uint8_t dma_bits;		/* number of DMA address lines */
1257fca0e69SHans Petter Selasky 	uint8_t control_ep_quirk;	/* need 64kByte buffer for data stage */
12602ac6454SAndrew Thompson };
12702ac6454SAndrew Thompson 
12875973647SAndrew Thompson #endif					/* _USB_BUS_H_ */
129