xref: /freebsd-13-stable/sys/mips/cavium/usb/octusb.h (revision 4fbf14e22d7b83de7080a8e491ba14a5785a0ff4)
1 
2 /*-
3  * SPDX-License-Identifier: BSD-2-Clause
4  *
5  * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _OCTUSB_H_
30 #define	_OCTUSB_H_
31 
32 #define	OCTUSB_MAX_DEVICES MIN(USB_MAX_DEVICES, 64)
33 #define	OCTUSB_MAX_PORTS	2	/* hardcoded */
34 #define	OCTUSB_MAX_FIXUP	4096	/* bytes */
35 #define	OCTUSB_INTR_ENDPT	0x01
36 
37 struct octusb_qh;
38 struct octusb_td;
39 struct octusb_softc;
40 
41 typedef uint8_t (octusb_cmd_t)(struct octusb_td *td);
42 
43 struct octusb_td {
44 	struct octusb_qh *qh;
45 	struct octusb_td *obj_next;
46 	struct usb_page_cache *pc;
47 	octusb_cmd_t *func;
48 
49 	uint32_t remainder;
50 	uint32_t offset;
51 
52 	uint8_t	error_any:1;
53 	uint8_t	error_stall:1;
54 	uint8_t	short_pkt:1;
55 	uint8_t	alt_next:1;
56 	uint8_t	reserved:4;
57 };
58 
59 struct octusb_qh {
60 	uint64_t fixup_phys;
61 
62 	struct octusb_softc *sc;
63 	struct usb_page_cache *fixup_pc;
64 	uint8_t *fixup_buf;
65 
66 	cvmx_usb_iso_packet_t iso_pkt;
67 
68 	uint32_t fixup_off;
69 
70 	uint16_t max_frame_size;
71 	uint16_t max_packet_size;
72 	uint16_t fixup_actlen;
73 	uint16_t fixup_len;
74 	uint16_t ep_interval;
75 
76 	uint8_t	dev_addr;
77 	uint8_t	dev_speed;
78 	uint8_t	ep_allocated;
79 	uint8_t	ep_mult;
80 	uint8_t	ep_num;
81 	uint8_t	ep_type;
82 	uint8_t	ep_toggle_next;
83 	uint8_t	root_port_index;
84 	uint8_t	fixup_complete;
85 	uint8_t	fixup_pending;
86 	uint8_t	hs_hub_addr;
87 	uint8_t	hs_hub_port;
88 
89 	int	fixup_handle;
90 	int	ep_handle;
91 };
92 
93 struct octusb_config_desc {
94 	struct usb_config_descriptor confd;
95 	struct usb_interface_descriptor ifcd;
96 	struct usb_endpoint_descriptor endpd;
97 } __packed;
98 
99 union octusb_hub_desc {
100 	struct usb_status stat;
101 	struct usb_port_status ps;
102 	uint8_t	temp[128];
103 };
104 
105 struct octusb_port {
106 	cvmx_usb_state_t state;
107 	uint8_t	disabled;
108 };
109 
110 struct octusb_softc {
111 	struct usb_bus sc_bus;		/* base device */
112 	union octusb_hub_desc sc_hub_desc;
113 
114 	struct usb_device *sc_devices[OCTUSB_MAX_DEVICES];
115 
116 	struct resource *sc_irq_res[OCTUSB_MAX_PORTS];
117 	void   *sc_intr_hdl[OCTUSB_MAX_PORTS];
118 
119 	struct octusb_port sc_port[OCTUSB_MAX_PORTS];
120 	device_t sc_dev;
121 
122 	struct usb_hub_descriptor_min sc_hubd;
123 
124 	uint8_t	sc_noport;		/* number of ports */
125 	uint8_t	sc_addr;		/* device address */
126 	uint8_t	sc_conf;		/* device configuration */
127 	uint8_t	sc_isreset;		/* set if current port is reset */
128 
129 	uint8_t	sc_hub_idata[1];
130 };
131 
132 usb_bus_mem_cb_t octusb_iterate_hw_softc;
133 usb_error_t octusb_init(struct octusb_softc *);
134 usb_error_t octusb_uninit(struct octusb_softc *);
135 void	octusb_interrupt(struct octusb_softc *);
136 
137 #endif					/* _OCTUSB_H_ */
138