xref: /freebsd/sys/dev/usb/usb_bus.h (revision 672c9965ef482f0b8b716c71d06d8e3d92db0a79)
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 
2702ac6454SAndrew Thompson #ifndef _USB2_BUS_H_
2802ac6454SAndrew Thompson #define	_USB2_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 
3502ac6454SAndrew Thompson struct usb2_bus_msg {
3602ac6454SAndrew Thompson 	struct usb2_proc_msg hdr;
3702ac6454SAndrew Thompson 	struct usb2_bus *bus;
3802ac6454SAndrew Thompson };
3902ac6454SAndrew Thompson 
4002ac6454SAndrew Thompson /*
4102ac6454SAndrew Thompson  * The following structure defines the USB statistics structure.
4202ac6454SAndrew Thompson  */
4302ac6454SAndrew Thompson struct usb2_bus_stat {
4402ac6454SAndrew Thompson 	uint32_t uds_requests[4];
4502ac6454SAndrew Thompson };
4602ac6454SAndrew Thompson 
4702ac6454SAndrew Thompson /*
4839307315SAndrew Thompson  * The following structure is used to keep the state of a standard
4939307315SAndrew Thompson  * root transfer.
5039307315SAndrew Thompson  */
5139307315SAndrew Thompson struct usb2_sw_transfer {
5239307315SAndrew Thompson 	struct usb2_device_request req;
5339307315SAndrew Thompson 	uint8_t *ptr;
5439307315SAndrew Thompson 	uint16_t len;
5539307315SAndrew Thompson 	usb2_error_t err;
5639307315SAndrew Thompson };
5739307315SAndrew Thompson 
5839307315SAndrew Thompson /*
5902ac6454SAndrew Thompson  * The following structure defines an USB BUS. There is one USB BUS
6002ac6454SAndrew Thompson  * for every Host or Device controller.
6102ac6454SAndrew Thompson  */
6202ac6454SAndrew Thompson struct usb2_bus {
6302ac6454SAndrew Thompson 	struct usb2_bus_stat stats_err;
6402ac6454SAndrew Thompson 	struct usb2_bus_stat stats_ok;
6539307315SAndrew Thompson 	struct usb2_sw_transfer roothub_req;
6602ac6454SAndrew Thompson 	struct root_hold_token *bus_roothold;
6702ac6454SAndrew Thompson 	/*
6802ac6454SAndrew Thompson 	 * There are two callback processes. One for Giant locked
6902ac6454SAndrew Thompson 	 * callbacks. One for non-Giant locked callbacks. This should
7002ac6454SAndrew Thompson 	 * avoid congestion and reduce response time in most cases.
7102ac6454SAndrew Thompson 	 */
7202ac6454SAndrew Thompson 	struct usb2_process giant_callback_proc;
7302ac6454SAndrew Thompson 	struct usb2_process non_giant_callback_proc;
74672c9965SAndrew Thompson 
75672c9965SAndrew Thompson 	/* Explore process */
76672c9965SAndrew Thompson 	struct usb2_process explore_proc;
77672c9965SAndrew Thompson 
78672c9965SAndrew Thompson 	/* Control request process */
79672c9965SAndrew Thompson 	struct usb2_process control_xfer_proc;
80672c9965SAndrew Thompson 
8102ac6454SAndrew Thompson 	struct usb2_bus_msg explore_msg[2];
8202ac6454SAndrew Thompson 	struct usb2_bus_msg detach_msg[2];
8302ac6454SAndrew Thompson 	struct usb2_bus_msg attach_msg[2];
8402ac6454SAndrew Thompson 	/*
8502ac6454SAndrew Thompson 	 * This mutex protects the USB hardware:
8602ac6454SAndrew Thompson 	 */
8702ac6454SAndrew Thompson 	struct mtx bus_mtx;
8802ac6454SAndrew Thompson 	struct usb2_xfer_queue intr_q;
8902ac6454SAndrew Thompson 	struct usb2_callout power_wdog;	/* power management */
9002ac6454SAndrew Thompson 
9102ac6454SAndrew Thompson 	device_t parent;
9202ac6454SAndrew Thompson 	device_t bdev;			/* filled by HC driver */
9302ac6454SAndrew Thompson 
948755859aSAndrew Thompson #if USB_HAVE_BUSDMA
9502ac6454SAndrew Thompson 	struct usb2_dma_parent_tag dma_parent_tag[1];
9602ac6454SAndrew Thompson 	struct usb2_dma_tag dma_tags[USB_BUS_DMA_TAG_MAX];
978755859aSAndrew Thompson #endif
9802ac6454SAndrew Thompson 	struct usb2_bus_methods *methods;	/* filled by HC driver */
9902ac6454SAndrew Thompson 	struct usb2_device **devices;
10002ac6454SAndrew Thompson 
101578d0effSAndrew Thompson 	usb2_power_mask_t hw_power_state;	/* see USB_HW_POWER_XXX */
102578d0effSAndrew Thompson 	usb2_size_t uframe_usage[USB_HS_MICRO_FRAMES_MAX];
103578d0effSAndrew Thompson 
10402ac6454SAndrew Thompson 	uint16_t isoc_time_last;	/* in milliseconds */
10502ac6454SAndrew Thompson 
10602ac6454SAndrew Thompson 	uint8_t	alloc_failed;		/* Set if memory allocation failed. */
10702ac6454SAndrew Thompson 	uint8_t	driver_added_refcount;	/* Current driver generation count */
10802ac6454SAndrew Thompson 	uint8_t	usbrev;			/* USB revision. See "USB_REV_XXX". */
10902ac6454SAndrew Thompson 
11002ac6454SAndrew Thompson 	uint8_t	devices_max;		/* maximum number of USB devices */
11102ac6454SAndrew Thompson 	uint8_t	do_probe;		/* set if USB BUS should be re-probed */
11202ac6454SAndrew Thompson 
11302ac6454SAndrew Thompson 	union {
11402ac6454SAndrew Thompson 		struct usb2_hw_ep_scratch hw_ep_scratch[1];
11502ac6454SAndrew Thompson 		struct usb2_temp_setup temp_setup[1];
11602ac6454SAndrew Thompson 		uint8_t	data[128];
11702ac6454SAndrew Thompson 	}	scratch[1];
11802ac6454SAndrew Thompson };
11902ac6454SAndrew Thompson 
12002ac6454SAndrew Thompson #endif					/* _USB2_BUS_H_ */
121