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