xref: /freebsd/sys/dev/usb/usb_bus.h (revision 02ac6454880b59bbc5f3f74dffaffa90b30adc8b)
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 /*
3102ac6454SAndrew Thompson  * The following structure defines the USB explore message sent to the
3202ac6454SAndrew Thompson  * USB 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 /*
4802ac6454SAndrew Thompson  * The following structure defines an USB BUS. There is one USB BUS
4902ac6454SAndrew Thompson  * for every Host or Device controller.
5002ac6454SAndrew Thompson  */
5102ac6454SAndrew Thompson struct usb2_bus {
5202ac6454SAndrew Thompson 	struct usb2_bus_stat stats_err;
5302ac6454SAndrew Thompson 	struct usb2_bus_stat stats_ok;
5402ac6454SAndrew Thompson 	struct usb2_process explore_proc;
5502ac6454SAndrew Thompson 	struct usb2_process roothub_proc;
5602ac6454SAndrew Thompson 	struct root_hold_token *bus_roothold;
5702ac6454SAndrew Thompson 	/*
5802ac6454SAndrew Thompson 	 * There are two callback processes. One for Giant locked
5902ac6454SAndrew Thompson 	 * callbacks. One for non-Giant locked callbacks. This should
6002ac6454SAndrew Thompson 	 * avoid congestion and reduce response time in most cases.
6102ac6454SAndrew Thompson 	 */
6202ac6454SAndrew Thompson 	struct usb2_process giant_callback_proc;
6302ac6454SAndrew Thompson 	struct usb2_process non_giant_callback_proc;
6402ac6454SAndrew Thompson 	struct usb2_bus_msg explore_msg[2];
6502ac6454SAndrew Thompson 	struct usb2_bus_msg detach_msg[2];
6602ac6454SAndrew Thompson 	struct usb2_bus_msg attach_msg[2];
6702ac6454SAndrew Thompson 	struct usb2_bus_msg roothub_msg[2];
6802ac6454SAndrew Thompson 	/*
6902ac6454SAndrew Thompson 	 * This mutex protects the USB hardware:
7002ac6454SAndrew Thompson 	 */
7102ac6454SAndrew Thompson 	struct mtx bus_mtx;
7202ac6454SAndrew Thompson 	struct usb2_perm perm;
7302ac6454SAndrew Thompson 	struct usb2_xfer_queue intr_q;
7402ac6454SAndrew Thompson 	struct usb2_callout power_wdog;	/* power management */
7502ac6454SAndrew Thompson 
7602ac6454SAndrew Thompson 	device_t parent;
7702ac6454SAndrew Thompson 	device_t bdev;			/* filled by HC driver */
7802ac6454SAndrew Thompson 
7902ac6454SAndrew Thompson 	struct usb2_dma_parent_tag dma_parent_tag[1];
8002ac6454SAndrew Thompson 	struct usb2_dma_tag dma_tags[USB_BUS_DMA_TAG_MAX];
8102ac6454SAndrew Thompson 
8202ac6454SAndrew Thompson 	struct usb2_bus_methods *methods;	/* filled by HC driver */
8302ac6454SAndrew Thompson 	struct usb2_device **devices;
8402ac6454SAndrew Thompson 
8502ac6454SAndrew Thompson 	uint32_t hw_power_state;	/* see USB_HW_POWER_XXX */
8602ac6454SAndrew Thompson 	uint32_t uframe_usage[USB_HS_MICRO_FRAMES_MAX];
8702ac6454SAndrew Thompson 	uint32_t transfer_count[4];
8802ac6454SAndrew Thompson 	uint16_t isoc_time_last;	/* in milliseconds */
8902ac6454SAndrew Thompson 
9002ac6454SAndrew Thompson 	uint8_t	alloc_failed;		/* Set if memory allocation failed. */
9102ac6454SAndrew Thompson 	uint8_t	driver_added_refcount;	/* Current driver generation count */
9202ac6454SAndrew Thompson 	uint8_t	usbrev;			/* USB revision. See "USB_REV_XXX". */
9302ac6454SAndrew Thompson 
9402ac6454SAndrew Thompson 	uint8_t	devices_max;		/* maximum number of USB devices */
9502ac6454SAndrew Thompson 	uint8_t	do_probe;		/* set if USB BUS should be re-probed */
9602ac6454SAndrew Thompson 
9702ac6454SAndrew Thompson 	union {
9802ac6454SAndrew Thompson 		struct usb2_hw_ep_scratch hw_ep_scratch[1];
9902ac6454SAndrew Thompson 		struct usb2_temp_setup temp_setup[1];
10002ac6454SAndrew Thompson 		uint8_t	data[128];
10102ac6454SAndrew Thompson 	}	scratch[1];
10202ac6454SAndrew Thompson };
10302ac6454SAndrew Thompson 
10402ac6454SAndrew Thompson #endif					/* _USB2_BUS_H_ */
105