xref: /freebsd/sys/dev/usb/usb_bus.h (revision 7fca0e69f608b36b0e5e2c9b5037ca2ec06a96de)
102ac6454SAndrew Thompson /* $FreeBSD$ */
202ac6454SAndrew Thompson /*-
3718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4718cf2ccSPedro F. Giffuni  *
502ac6454SAndrew Thompson  * Copyright (c) 2008 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 the USB statistics structure.
4602ac6454SAndrew Thompson  */
47760bc48eSAndrew Thompson struct usb_bus_stat {
4802ac6454SAndrew Thompson 	uint32_t uds_requests[4];
4902ac6454SAndrew Thompson };
5002ac6454SAndrew Thompson 
5102ac6454SAndrew Thompson /*
5202ac6454SAndrew Thompson  * The following structure defines an USB BUS. There is one USB BUS
5302ac6454SAndrew Thompson  * for every Host or Device controller.
5402ac6454SAndrew Thompson  */
55760bc48eSAndrew Thompson struct usb_bus {
56760bc48eSAndrew Thompson 	struct usb_bus_stat stats_err;
57760bc48eSAndrew Thompson 	struct usb_bus_stat stats_ok;
58ff182db6SHans Petter Selasky #if USB_HAVE_ROOT_MOUNT_HOLD
5902ac6454SAndrew Thompson 	struct root_hold_token *bus_roothold;
60ff182db6SHans Petter Selasky #endif
619b3a48eeSHans Petter Selasky 
6243ea03d7SHans Petter Selasky /* convenience macros */
6343ea03d7SHans Petter Selasky #define	USB_BUS_TT_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus)
6443ea03d7SHans Petter Selasky #define	USB_BUS_CS_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus)
6543ea03d7SHans Petter Selasky 
669b3a48eeSHans Petter Selasky #if USB_HAVE_PER_BUS_PROCESS
679b3a48eeSHans Petter Selasky #define	USB_BUS_GIANT_PROC(bus) (&(bus)->giant_callback_proc)
6843ea03d7SHans Petter Selasky #define	USB_BUS_NON_GIANT_ISOC_PROC(bus) (&(bus)->non_giant_isoc_callback_proc)
6943ea03d7SHans Petter Selasky #define	USB_BUS_NON_GIANT_BULK_PROC(bus) (&(bus)->non_giant_bulk_callback_proc)
709b3a48eeSHans Petter Selasky #define	USB_BUS_EXPLORE_PROC(bus) (&(bus)->explore_proc)
719b3a48eeSHans Petter Selasky #define	USB_BUS_CONTROL_XFER_PROC(bus) (&(bus)->control_xfer_proc)
7202ac6454SAndrew Thompson 	/*
7343ea03d7SHans Petter Selasky 	 * There are three callback processes. One for Giant locked
7443ea03d7SHans Petter Selasky 	 * callbacks. One for non-Giant locked non-periodic callbacks
7543ea03d7SHans Petter Selasky 	 * and one for non-Giant locked periodic callbacks. This
7643ea03d7SHans Petter Selasky 	 * should avoid congestion and reduce response time in most
7743ea03d7SHans Petter Selasky 	 * cases.
7802ac6454SAndrew Thompson 	 */
79760bc48eSAndrew Thompson 	struct usb_process giant_callback_proc;
8043ea03d7SHans Petter Selasky 	struct usb_process non_giant_isoc_callback_proc;
8143ea03d7SHans Petter Selasky 	struct usb_process non_giant_bulk_callback_proc;
82672c9965SAndrew Thompson 
83672c9965SAndrew Thompson 	/* Explore process */
84760bc48eSAndrew Thompson 	struct usb_process explore_proc;
85672c9965SAndrew Thompson 
86672c9965SAndrew Thompson 	/* Control request process */
87760bc48eSAndrew Thompson 	struct usb_process control_xfer_proc;
889b3a48eeSHans Petter Selasky #endif
89672c9965SAndrew Thompson 
90760bc48eSAndrew Thompson 	struct usb_bus_msg explore_msg[2];
91760bc48eSAndrew Thompson 	struct usb_bus_msg detach_msg[2];
92760bc48eSAndrew Thompson 	struct usb_bus_msg attach_msg[2];
932e141748SHans Petter Selasky 	struct usb_bus_msg suspend_msg[2];
942e141748SHans Petter Selasky 	struct usb_bus_msg resume_msg[2];
95563ab081SHans Petter Selasky 	struct usb_bus_msg reset_msg[2];
962e141748SHans Petter Selasky 	struct usb_bus_msg shutdown_msg[2];
97b78e84d1SHans Petter Selasky #if USB_HAVE_UGEN
98b78e84d1SHans Petter Selasky 	struct usb_bus_msg cleanup_msg[2];
99b78e84d1SHans Petter Selasky 	LIST_HEAD(,usb_fs_privdata) pd_cleanup_list;
100b78e84d1SHans Petter Selasky #endif
10102ac6454SAndrew Thompson 	/*
10202ac6454SAndrew Thompson 	 * This mutex protects the USB hardware:
10302ac6454SAndrew Thompson 	 */
10402ac6454SAndrew Thompson 	struct mtx bus_mtx;
1052fe7ad87SHans Petter Selasky 	struct mtx bus_spin_lock;
106760bc48eSAndrew Thompson 	struct usb_xfer_queue intr_q;
107760bc48eSAndrew Thompson 	struct usb_callout power_wdog;	/* power management */
10802ac6454SAndrew Thompson 
10902ac6454SAndrew Thompson 	device_t parent;
11002ac6454SAndrew Thompson 	device_t bdev;			/* filled by HC driver */
11102ac6454SAndrew Thompson 
1128755859aSAndrew Thompson #if USB_HAVE_BUSDMA
113760bc48eSAndrew Thompson 	struct usb_dma_parent_tag dma_parent_tag[1];
114760bc48eSAndrew Thompson 	struct usb_dma_tag dma_tags[USB_BUS_DMA_TAG_MAX];
1158755859aSAndrew Thompson #endif
116e892b3feSHans Petter Selasky 	const struct usb_bus_methods *methods;	/* filled by HC driver */
117760bc48eSAndrew Thompson 	struct usb_device **devices;
11802ac6454SAndrew Thompson 
119e376f9c3SWeongyo Jeong 	struct ifnet *ifp;	/* only for USB Packet Filter */
12018ec6525SWeongyo Jeong 
121e0a69b51SAndrew Thompson 	usb_power_mask_t hw_power_state;	/* see USB_HW_POWER_XXX */
122f9cb546cSAndrew Thompson 	usb_size_t uframe_usage[USB_HS_MICRO_FRAMES_MAX];
123578d0effSAndrew Thompson 
12402ac6454SAndrew Thompson 	uint16_t isoc_time_last;	/* in milliseconds */
12502ac6454SAndrew Thompson 
12602ac6454SAndrew Thompson 	uint8_t	alloc_failed;		/* Set if memory allocation failed. */
12702ac6454SAndrew Thompson 	uint8_t	driver_added_refcount;	/* Current driver generation count */
1288d2dd5ddSAndrew Thompson 	enum usb_revision usbrev;	/* USB revision. See "USB_REV_XXX". */
12902ac6454SAndrew Thompson 
13002ac6454SAndrew Thompson 	uint8_t	devices_max;		/* maximum number of USB devices */
1312e141748SHans Petter Selasky 	uint8_t	do_probe;		/* set if USB should be re-probed */
1322e141748SHans Petter Selasky 	uint8_t no_explore;		/* don't explore USB ports */
133b217d184SHans Petter Selasky 	uint8_t dma_bits;		/* number of DMA address lines */
134*7fca0e69SHans Petter Selasky 	uint8_t control_ep_quirk;	/* need 64kByte buffer for data stage */
13502ac6454SAndrew Thompson };
13602ac6454SAndrew Thompson 
13775973647SAndrew Thompson #endif					/* _USB_BUS_H_ */
138