master
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2008-2019 Hans Petter Selasky. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#ifndef _USB_BUS_H_
29#define _USB_BUS_H_
30
31struct usb_fs_privdata;
32
33/*
34 * The following structure defines the USB explore message sent to the USB
35 * explore process.
36 */
37
38struct usb_bus_msg {
39 struct usb_proc_msg hdr;
40 struct usb_bus *bus;
41};
42
43/*
44 * The following structure defines an USB BUS. There is one USB BUS
45 * for every Host or Device controller.
46 */
47struct usb_bus {
48#if USB_HAVE_ROOT_MOUNT_HOLD
49 struct root_hold_token *bus_roothold;
50#endif
51
52/* convenience macros */
53#define USB_BUS_TT_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus)
54#define USB_BUS_CS_PROC(bus) USB_BUS_NON_GIANT_ISOC_PROC(bus)
55
56#if USB_HAVE_PER_BUS_PROCESS
57#define USB_BUS_GIANT_PROC(bus) (&(bus)->giant_callback_proc)
58#define USB_BUS_NON_GIANT_ISOC_PROC(bus) (&(bus)->non_giant_isoc_callback_proc)
59#define USB_BUS_NON_GIANT_BULK_PROC(bus) (&(bus)->non_giant_bulk_callback_proc)
60#define USB_BUS_EXPLORE_PROC(bus) (&(bus)->explore_proc)
61#define USB_BUS_CONTROL_XFER_PROC(bus) (&(bus)->control_xfer_proc)
62 /*
63 * There are three callback processes. One for Giant locked
64 * callbacks. One for non-Giant locked non-periodic callbacks
65 * and one for non-Giant locked periodic callbacks. This
66 * should avoid congestion and reduce response time in most
67 * cases.
68 */
69 struct usb_process giant_callback_proc;
70 struct usb_process non_giant_isoc_callback_proc;
71 struct usb_process non_giant_bulk_callback_proc;
72
73 /* Explore process */
74 struct usb_process explore_proc;
75
76 /* Control request process */
77 struct usb_process control_xfer_proc;
78#endif
79
80 struct usb_bus_msg explore_msg[2];
81 struct usb_bus_msg detach_msg[2];
82 struct usb_bus_msg attach_msg[2];
83 struct usb_bus_msg suspend_msg[2];
84 struct usb_bus_msg resume_msg[2];
85 struct usb_bus_msg reset_msg[2];
86 struct usb_bus_msg shutdown_msg[2];
87#if USB_HAVE_UGEN
88 struct usb_bus_msg cleanup_msg[2];
89 LIST_HEAD(,usb_fs_privdata) pd_cleanup_list;
90#endif
91 /*
92 * This mutex protects the USB hardware:
93 */
94 struct mtx bus_mtx;
95 struct mtx bus_spin_lock;
96 struct usb_xfer_queue intr_q;
97 struct usb_callout power_wdog; /* power management */
98
99 device_t parent;
100 device_t bdev; /* filled by HC driver */
101
102#if USB_HAVE_BUSDMA
103 struct usb_dma_parent_tag dma_parent_tag[1];
104 struct usb_dma_tag dma_tags[USB_BUS_DMA_TAG_MAX];
105#endif
106 const struct usb_bus_methods *methods; /* filled by HC driver */
107 struct usb_device **devices;
108
109 struct ifnet *ifp; /* only for USB Packet Filter */
110
111 usb_power_mask_t hw_power_state; /* see USB_HW_POWER_XXX */
112 usb_size_t uframe_usage[USB_HS_MICRO_FRAMES_MAX];
113
114 uint16_t isoc_time_last; /* in milliseconds */
115
116 uint8_t alloc_failed; /* Set if memory allocation failed. */
117 uint8_t driver_added_refcount; /* Current driver generation count */
118 enum usb_revision usbrev; /* USB revision. See "USB_REV_XXX". */
119
120 uint8_t devices_max; /* maximum number of USB devices */
121 uint8_t do_probe; /* set if USB should be re-probed */
122 uint8_t no_explore; /* don't explore USB ports */
123 uint8_t dma_bits; /* number of DMA address lines */
124 uint8_t control_ep_quirk; /* need 64kByte buffer for data stage */
125};
126
127#endif /* _USB_BUS_H_ */