1143fc13bSJean-Jacques Hiblot /*
2143fc13bSJean-Jacques Hiblot * USB HOST XHCI Controller
3143fc13bSJean-Jacques Hiblot *
4143fc13bSJean-Jacques Hiblot * Based on xHCI host controller driver in linux-kernel
5143fc13bSJean-Jacques Hiblot * by Sarah Sharp.
6143fc13bSJean-Jacques Hiblot *
7143fc13bSJean-Jacques Hiblot * Copyright (C) 2008 Intel Corp.
8143fc13bSJean-Jacques Hiblot * Author: Sarah Sharp
9143fc13bSJean-Jacques Hiblot *
10143fc13bSJean-Jacques Hiblot * Copyright (C) 2013 Samsung Electronics Co.Ltd
11143fc13bSJean-Jacques Hiblot * Authors: Vivek Gautam <gautam.vivek@samsung.com>
12143fc13bSJean-Jacques Hiblot * Vikas Sajjan <vikas.sajjan@samsung.com>
13143fc13bSJean-Jacques Hiblot *
14143fc13bSJean-Jacques Hiblot * SPDX-License-Identifier: GPL-2.0+
15143fc13bSJean-Jacques Hiblot */
16143fc13bSJean-Jacques Hiblot
17143fc13bSJean-Jacques Hiblot #ifndef HOST_XHCI_H_
18143fc13bSJean-Jacques Hiblot #define HOST_XHCI_H_
19143fc13bSJean-Jacques Hiblot
20143fc13bSJean-Jacques Hiblot #include <asm/types.h>
21143fc13bSJean-Jacques Hiblot #include <asm/cache.h>
22143fc13bSJean-Jacques Hiblot #include <asm/io.h>
23143fc13bSJean-Jacques Hiblot #include <linux/list.h>
24143fc13bSJean-Jacques Hiblot #include <linux/compat.h>
25143fc13bSJean-Jacques Hiblot
26143fc13bSJean-Jacques Hiblot #define MAX_EP_CTX_NUM 31
27143fc13bSJean-Jacques Hiblot #define XHCI_ALIGNMENT 64
28143fc13bSJean-Jacques Hiblot /* Generic timeout for XHCI events */
29143fc13bSJean-Jacques Hiblot #define XHCI_TIMEOUT 5000
30143fc13bSJean-Jacques Hiblot /* Max number of USB devices for any host controller - limit in section 6.1 */
31143fc13bSJean-Jacques Hiblot #define MAX_HC_SLOTS 256
32143fc13bSJean-Jacques Hiblot /* Section 5.3.3 - MaxPorts */
33143fc13bSJean-Jacques Hiblot #define MAX_HC_PORTS 255
34143fc13bSJean-Jacques Hiblot
35143fc13bSJean-Jacques Hiblot /* Up to 16 ms to halt an HC */
36143fc13bSJean-Jacques Hiblot #define XHCI_MAX_HALT_USEC (16*1000)
37143fc13bSJean-Jacques Hiblot
38143fc13bSJean-Jacques Hiblot #define XHCI_MAX_RESET_USEC (250*1000)
39143fc13bSJean-Jacques Hiblot
40143fc13bSJean-Jacques Hiblot /*
41143fc13bSJean-Jacques Hiblot * These bits are Read Only (RO) and should be saved and written to the
42143fc13bSJean-Jacques Hiblot * registers: 0, 3, 10:13, 30
43143fc13bSJean-Jacques Hiblot * connect status, over-current status, port speed, and device removable.
44143fc13bSJean-Jacques Hiblot * connect status and port speed are also sticky - meaning they're in
45143fc13bSJean-Jacques Hiblot * the AUX well and they aren't changed by a hot, warm, or cold reset.
46143fc13bSJean-Jacques Hiblot */
47143fc13bSJean-Jacques Hiblot #define XHCI_PORT_RO ((1 << 0) | (1 << 3) | (0xf << 10) | (1 << 30))
48143fc13bSJean-Jacques Hiblot /*
49143fc13bSJean-Jacques Hiblot * These bits are RW; writing a 0 clears the bit, writing a 1 sets the bit:
50143fc13bSJean-Jacques Hiblot * bits 5:8, 9, 14:15, 25:27
51143fc13bSJean-Jacques Hiblot * link state, port power, port indicator state, "wake on" enable state
52143fc13bSJean-Jacques Hiblot */
53143fc13bSJean-Jacques Hiblot #define XHCI_PORT_RWS ((0xf << 5) | (1 << 9) | (0x3 << 14) | (0x7 << 25))
54143fc13bSJean-Jacques Hiblot /*
55143fc13bSJean-Jacques Hiblot * These bits are RW; writing a 1 sets the bit, writing a 0 has no effect:
56143fc13bSJean-Jacques Hiblot * bit 4 (port reset)
57143fc13bSJean-Jacques Hiblot */
58143fc13bSJean-Jacques Hiblot #define XHCI_PORT_RW1S ((1 << 4))
59143fc13bSJean-Jacques Hiblot /*
60143fc13bSJean-Jacques Hiblot * These bits are RW; writing a 1 clears the bit, writing a 0 has no effect:
61143fc13bSJean-Jacques Hiblot * bits 1, 17, 18, 19, 20, 21, 22, 23
62143fc13bSJean-Jacques Hiblot * port enable/disable, and
63143fc13bSJean-Jacques Hiblot * change bits: connect, PED,
64143fc13bSJean-Jacques Hiblot * warm port reset changed (reserved zero for USB 2.0 ports),
65143fc13bSJean-Jacques Hiblot * over-current, reset, link state, and L1 change
66143fc13bSJean-Jacques Hiblot */
67143fc13bSJean-Jacques Hiblot #define XHCI_PORT_RW1CS ((1 << 1) | (0x7f << 17))
68143fc13bSJean-Jacques Hiblot /*
69143fc13bSJean-Jacques Hiblot * Bit 16 is RW, and writing a '1' to it causes the link state control to be
70143fc13bSJean-Jacques Hiblot * latched in
71143fc13bSJean-Jacques Hiblot */
72143fc13bSJean-Jacques Hiblot #define XHCI_PORT_RW ((1 << 16))
73143fc13bSJean-Jacques Hiblot /*
74143fc13bSJean-Jacques Hiblot * These bits are Reserved Zero (RsvdZ) and zero should be written to them:
75143fc13bSJean-Jacques Hiblot * bits 2, 24, 28:31
76143fc13bSJean-Jacques Hiblot */
77143fc13bSJean-Jacques Hiblot #define XHCI_PORT_RZ ((1 << 2) | (1 << 24) | (0xf << 28))
78143fc13bSJean-Jacques Hiblot
79143fc13bSJean-Jacques Hiblot /*
80143fc13bSJean-Jacques Hiblot * XHCI Register Space.
81143fc13bSJean-Jacques Hiblot */
82143fc13bSJean-Jacques Hiblot struct xhci_hccr {
83143fc13bSJean-Jacques Hiblot uint32_t cr_capbase;
84143fc13bSJean-Jacques Hiblot uint32_t cr_hcsparams1;
85143fc13bSJean-Jacques Hiblot uint32_t cr_hcsparams2;
86143fc13bSJean-Jacques Hiblot uint32_t cr_hcsparams3;
87143fc13bSJean-Jacques Hiblot uint32_t cr_hccparams;
88143fc13bSJean-Jacques Hiblot uint32_t cr_dboff;
89143fc13bSJean-Jacques Hiblot uint32_t cr_rtsoff;
90143fc13bSJean-Jacques Hiblot
91143fc13bSJean-Jacques Hiblot /* hc_capbase bitmasks */
92143fc13bSJean-Jacques Hiblot /* bits 7:0 - how long is the Capabilities register */
93143fc13bSJean-Jacques Hiblot #define HC_LENGTH(p) XHCI_HC_LENGTH(p)
94143fc13bSJean-Jacques Hiblot /* bits 31:16 */
95143fc13bSJean-Jacques Hiblot #define HC_VERSION(p) (((p) >> 16) & 0xffff)
96143fc13bSJean-Jacques Hiblot
97143fc13bSJean-Jacques Hiblot /* HCSPARAMS1 - hcs_params1 - bitmasks */
98143fc13bSJean-Jacques Hiblot /* bits 0:7, Max Device Slots */
99143fc13bSJean-Jacques Hiblot #define HCS_MAX_SLOTS(p) (((p) >> 0) & 0xff)
100143fc13bSJean-Jacques Hiblot #define HCS_SLOTS_MASK 0xff
101143fc13bSJean-Jacques Hiblot /* bits 8:18, Max Interrupters */
102143fc13bSJean-Jacques Hiblot #define HCS_MAX_INTRS(p) (((p) >> 8) & 0x7ff)
103143fc13bSJean-Jacques Hiblot /* bits 24:31, Max Ports - max value is 0x7F = 127 ports */
104143fc13bSJean-Jacques Hiblot #define HCS_MAX_PORTS_SHIFT 24
105143fc13bSJean-Jacques Hiblot #define HCS_MAX_PORTS_MASK (0xff << HCS_MAX_PORTS_SHIFT)
106143fc13bSJean-Jacques Hiblot #define HCS_MAX_PORTS(p) (((p) >> 24) & 0xff)
107143fc13bSJean-Jacques Hiblot
108143fc13bSJean-Jacques Hiblot /* HCSPARAMS2 - hcs_params2 - bitmasks */
109143fc13bSJean-Jacques Hiblot /* bits 0:3, frames or uframes that SW needs to queue transactions
110143fc13bSJean-Jacques Hiblot * ahead of the HW to meet periodic deadlines */
111143fc13bSJean-Jacques Hiblot #define HCS_IST(p) (((p) >> 0) & 0xf)
112143fc13bSJean-Jacques Hiblot /* bits 4:7, max number of Event Ring segments */
113143fc13bSJean-Jacques Hiblot #define HCS_ERST_MAX(p) (((p) >> 4) & 0xf)
114143fc13bSJean-Jacques Hiblot /* bits 21:25 Hi 5 bits of Scratchpad buffers SW must allocate for the HW */
115143fc13bSJean-Jacques Hiblot /* bit 26 Scratchpad restore - for save/restore HW state - not used yet */
116143fc13bSJean-Jacques Hiblot /* bits 27:31 Lo 5 bits of Scratchpad buffers SW must allocate for the HW */
117143fc13bSJean-Jacques Hiblot #define HCS_MAX_SCRATCHPAD(p) ((((p) >> 16) & 0x3e0) | (((p) >> 27) & 0x1f))
118143fc13bSJean-Jacques Hiblot
119143fc13bSJean-Jacques Hiblot /* HCSPARAMS3 - hcs_params3 - bitmasks */
120143fc13bSJean-Jacques Hiblot /* bits 0:7, Max U1 to U0 latency for the roothub ports */
121143fc13bSJean-Jacques Hiblot #define HCS_U1_LATENCY(p) (((p) >> 0) & 0xff)
122143fc13bSJean-Jacques Hiblot /* bits 16:31, Max U2 to U0 latency for the roothub ports */
123143fc13bSJean-Jacques Hiblot #define HCS_U2_LATENCY(p) (((p) >> 16) & 0xffff)
124143fc13bSJean-Jacques Hiblot
125143fc13bSJean-Jacques Hiblot /* HCCPARAMS - hcc_params - bitmasks */
126143fc13bSJean-Jacques Hiblot /* true: HC can use 64-bit address pointers */
127143fc13bSJean-Jacques Hiblot #define HCC_64BIT_ADDR(p) ((p) & (1 << 0))
128143fc13bSJean-Jacques Hiblot /* true: HC can do bandwidth negotiation */
129143fc13bSJean-Jacques Hiblot #define HCC_BANDWIDTH_NEG(p) ((p) & (1 << 1))
130143fc13bSJean-Jacques Hiblot /* true: HC uses 64-byte Device Context structures
131143fc13bSJean-Jacques Hiblot * FIXME 64-byte context structures aren't supported yet.
132143fc13bSJean-Jacques Hiblot */
133143fc13bSJean-Jacques Hiblot #define HCC_64BYTE_CONTEXT(p) ((p) & (1 << 2))
134143fc13bSJean-Jacques Hiblot /* true: HC has port power switches */
135143fc13bSJean-Jacques Hiblot #define HCC_PPC(p) ((p) & (1 << 3))
136143fc13bSJean-Jacques Hiblot /* true: HC has port indicators */
137143fc13bSJean-Jacques Hiblot #define HCS_INDICATOR(p) ((p) & (1 << 4))
138143fc13bSJean-Jacques Hiblot /* true: HC has Light HC Reset Capability */
139143fc13bSJean-Jacques Hiblot #define HCC_LIGHT_RESET(p) ((p) & (1 << 5))
140143fc13bSJean-Jacques Hiblot /* true: HC supports latency tolerance messaging */
141143fc13bSJean-Jacques Hiblot #define HCC_LTC(p) ((p) & (1 << 6))
142143fc13bSJean-Jacques Hiblot /* true: no secondary Stream ID Support */
143143fc13bSJean-Jacques Hiblot #define HCC_NSS(p) ((p) & (1 << 7))
144143fc13bSJean-Jacques Hiblot /* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15 */
145143fc13bSJean-Jacques Hiblot #define HCC_MAX_PSA(p) (1 << ((((p) >> 12) & 0xf) + 1))
146143fc13bSJean-Jacques Hiblot /* Extended Capabilities pointer from PCI base - section 5.3.6 */
147143fc13bSJean-Jacques Hiblot #define HCC_EXT_CAPS(p) XHCI_HCC_EXT_CAPS(p)
148143fc13bSJean-Jacques Hiblot
149143fc13bSJean-Jacques Hiblot /* db_off bitmask - bits 0:1 reserved */
150143fc13bSJean-Jacques Hiblot #define DBOFF_MASK (~0x3)
151143fc13bSJean-Jacques Hiblot
152143fc13bSJean-Jacques Hiblot /* run_regs_off bitmask - bits 0:4 reserved */
153143fc13bSJean-Jacques Hiblot #define RTSOFF_MASK (~0x1f)
154143fc13bSJean-Jacques Hiblot
155143fc13bSJean-Jacques Hiblot };
156143fc13bSJean-Jacques Hiblot
157143fc13bSJean-Jacques Hiblot struct xhci_hcor_port_regs {
158143fc13bSJean-Jacques Hiblot volatile uint32_t or_portsc;
159143fc13bSJean-Jacques Hiblot volatile uint32_t or_portpmsc;
160143fc13bSJean-Jacques Hiblot volatile uint32_t or_portli;
161143fc13bSJean-Jacques Hiblot volatile uint32_t reserved_3;
162143fc13bSJean-Jacques Hiblot };
163143fc13bSJean-Jacques Hiblot
164143fc13bSJean-Jacques Hiblot struct xhci_hcor {
165143fc13bSJean-Jacques Hiblot volatile uint32_t or_usbcmd;
166143fc13bSJean-Jacques Hiblot volatile uint32_t or_usbsts;
167143fc13bSJean-Jacques Hiblot volatile uint32_t or_pagesize;
168143fc13bSJean-Jacques Hiblot volatile uint32_t reserved_0[2];
169143fc13bSJean-Jacques Hiblot volatile uint32_t or_dnctrl;
170143fc13bSJean-Jacques Hiblot volatile uint64_t or_crcr;
171143fc13bSJean-Jacques Hiblot volatile uint32_t reserved_1[4];
172143fc13bSJean-Jacques Hiblot volatile uint64_t or_dcbaap;
173143fc13bSJean-Jacques Hiblot volatile uint32_t or_config;
174143fc13bSJean-Jacques Hiblot volatile uint32_t reserved_2[241];
175143fc13bSJean-Jacques Hiblot struct xhci_hcor_port_regs portregs[MAX_HC_PORTS];
176143fc13bSJean-Jacques Hiblot };
177143fc13bSJean-Jacques Hiblot
178143fc13bSJean-Jacques Hiblot /* USBCMD - USB command - command bitmasks */
179143fc13bSJean-Jacques Hiblot /* start/stop HC execution - do not write unless HC is halted*/
180143fc13bSJean-Jacques Hiblot #define CMD_RUN XHCI_CMD_RUN
181143fc13bSJean-Jacques Hiblot /* Reset HC - resets internal HC state machine and all registers (except
182143fc13bSJean-Jacques Hiblot * PCI config regs). HC does NOT drive a USB reset on the downstream ports.
183143fc13bSJean-Jacques Hiblot * The xHCI driver must reinitialize the xHC after setting this bit.
184143fc13bSJean-Jacques Hiblot */
185143fc13bSJean-Jacques Hiblot #define CMD_RESET (1 << 1)
186143fc13bSJean-Jacques Hiblot /* Event Interrupt Enable - a '1' allows interrupts from the host controller */
187143fc13bSJean-Jacques Hiblot #define CMD_EIE XHCI_CMD_EIE
188143fc13bSJean-Jacques Hiblot /* Host System Error Interrupt Enable - get out-of-band signal for HC errors */
189143fc13bSJean-Jacques Hiblot #define CMD_HSEIE XHCI_CMD_HSEIE
190143fc13bSJean-Jacques Hiblot /* bits 4:6 are reserved (and should be preserved on writes). */
191143fc13bSJean-Jacques Hiblot /* light reset (port status stays unchanged) - reset completed when this is 0 */
192143fc13bSJean-Jacques Hiblot #define CMD_LRESET (1 << 7)
193143fc13bSJean-Jacques Hiblot /* host controller save/restore state. */
194143fc13bSJean-Jacques Hiblot #define CMD_CSS (1 << 8)
195143fc13bSJean-Jacques Hiblot #define CMD_CRS (1 << 9)
196143fc13bSJean-Jacques Hiblot /* Enable Wrap Event - '1' means xHC generates an event when MFINDEX wraps. */
197143fc13bSJean-Jacques Hiblot #define CMD_EWE XHCI_CMD_EWE
198143fc13bSJean-Jacques Hiblot /* MFINDEX power management - '1' means xHC can stop MFINDEX counter if all root
199143fc13bSJean-Jacques Hiblot * hubs are in U3 (selective suspend), disconnect, disabled, or powered-off.
200143fc13bSJean-Jacques Hiblot * '0' means the xHC can power it off if all ports are in the disconnect,
201143fc13bSJean-Jacques Hiblot * disabled, or powered-off state.
202143fc13bSJean-Jacques Hiblot */
203143fc13bSJean-Jacques Hiblot #define CMD_PM_INDEX (1 << 11)
204143fc13bSJean-Jacques Hiblot /* bits 12:31 are reserved (and should be preserved on writes). */
205143fc13bSJean-Jacques Hiblot
206143fc13bSJean-Jacques Hiblot /* USBSTS - USB status - status bitmasks */
207143fc13bSJean-Jacques Hiblot /* HC not running - set to 1 when run/stop bit is cleared. */
208143fc13bSJean-Jacques Hiblot #define STS_HALT XHCI_STS_HALT
209143fc13bSJean-Jacques Hiblot /* serious error, e.g. PCI parity error. The HC will clear the run/stop bit. */
210143fc13bSJean-Jacques Hiblot #define STS_FATAL (1 << 2)
211143fc13bSJean-Jacques Hiblot /* event interrupt - clear this prior to clearing any IP flags in IR set*/
212143fc13bSJean-Jacques Hiblot #define STS_EINT (1 << 3)
213143fc13bSJean-Jacques Hiblot /* port change detect */
214143fc13bSJean-Jacques Hiblot #define STS_PORT (1 << 4)
215143fc13bSJean-Jacques Hiblot /* bits 5:7 reserved and zeroed */
216143fc13bSJean-Jacques Hiblot /* save state status - '1' means xHC is saving state */
217143fc13bSJean-Jacques Hiblot #define STS_SAVE (1 << 8)
218143fc13bSJean-Jacques Hiblot /* restore state status - '1' means xHC is restoring state */
219143fc13bSJean-Jacques Hiblot #define STS_RESTORE (1 << 9)
220143fc13bSJean-Jacques Hiblot /* true: save or restore error */
221143fc13bSJean-Jacques Hiblot #define STS_SRE (1 << 10)
222143fc13bSJean-Jacques Hiblot /* true: Controller Not Ready to accept doorbell or op reg writes after reset */
223143fc13bSJean-Jacques Hiblot #define STS_CNR XHCI_STS_CNR
224143fc13bSJean-Jacques Hiblot /* true: internal Host Controller Error - SW needs to reset and reinitialize */
225143fc13bSJean-Jacques Hiblot #define STS_HCE (1 << 12)
226143fc13bSJean-Jacques Hiblot /* bits 13:31 reserved and should be preserved */
227143fc13bSJean-Jacques Hiblot
228143fc13bSJean-Jacques Hiblot /*
229143fc13bSJean-Jacques Hiblot * DNCTRL - Device Notification Control Register - dev_notification bitmasks
230143fc13bSJean-Jacques Hiblot * Generate a device notification event when the HC sees a transaction with a
231143fc13bSJean-Jacques Hiblot * notification type that matches a bit set in this bit field.
232143fc13bSJean-Jacques Hiblot */
233143fc13bSJean-Jacques Hiblot #define DEV_NOTE_MASK (0xffff)
234143fc13bSJean-Jacques Hiblot #define ENABLE_DEV_NOTE(x) (1 << (x))
235143fc13bSJean-Jacques Hiblot /* Most of the device notification types should only be used for debug.
236143fc13bSJean-Jacques Hiblot * SW does need to pay attention to function wake notifications.
237143fc13bSJean-Jacques Hiblot */
238143fc13bSJean-Jacques Hiblot #define DEV_NOTE_FWAKE ENABLE_DEV_NOTE(1)
239143fc13bSJean-Jacques Hiblot
240143fc13bSJean-Jacques Hiblot /* CRCR - Command Ring Control Register - cmd_ring bitmasks */
241143fc13bSJean-Jacques Hiblot /* bit 0 is the command ring cycle state */
242143fc13bSJean-Jacques Hiblot /* stop ring operation after completion of the currently executing command */
243143fc13bSJean-Jacques Hiblot #define CMD_RING_PAUSE (1 << 1)
244143fc13bSJean-Jacques Hiblot /* stop ring immediately - abort the currently executing command */
245143fc13bSJean-Jacques Hiblot #define CMD_RING_ABORT (1 << 2)
246143fc13bSJean-Jacques Hiblot /* true: command ring is running */
247143fc13bSJean-Jacques Hiblot #define CMD_RING_RUNNING (1 << 3)
248143fc13bSJean-Jacques Hiblot /* bits 4:5 reserved and should be preserved */
249143fc13bSJean-Jacques Hiblot /* Command Ring pointer - bit mask for the lower 32 bits. */
250143fc13bSJean-Jacques Hiblot #define CMD_RING_RSVD_BITS (0x3f)
251143fc13bSJean-Jacques Hiblot
252143fc13bSJean-Jacques Hiblot /* CONFIG - Configure Register - config_reg bitmasks */
253143fc13bSJean-Jacques Hiblot /* bits 0:7 - maximum number of device slots enabled (NumSlotsEn) */
254143fc13bSJean-Jacques Hiblot #define MAX_DEVS(p) ((p) & 0xff)
255143fc13bSJean-Jacques Hiblot /* bits 8:31 - reserved and should be preserved */
256143fc13bSJean-Jacques Hiblot
257143fc13bSJean-Jacques Hiblot /* PORTSC - Port Status and Control Register - port_status_base bitmasks */
258143fc13bSJean-Jacques Hiblot /* true: device connected */
259143fc13bSJean-Jacques Hiblot #define PORT_CONNECT (1 << 0)
260143fc13bSJean-Jacques Hiblot /* true: port enabled */
261143fc13bSJean-Jacques Hiblot #define PORT_PE (1 << 1)
262143fc13bSJean-Jacques Hiblot /* bit 2 reserved and zeroed */
263143fc13bSJean-Jacques Hiblot /* true: port has an over-current condition */
264143fc13bSJean-Jacques Hiblot #define PORT_OC (1 << 3)
265143fc13bSJean-Jacques Hiblot /* true: port reset signaling asserted */
266143fc13bSJean-Jacques Hiblot #define PORT_RESET (1 << 4)
267143fc13bSJean-Jacques Hiblot /* Port Link State - bits 5:8
268143fc13bSJean-Jacques Hiblot * A read gives the current link PM state of the port,
269143fc13bSJean-Jacques Hiblot * a write with Link State Write Strobe set sets the link state.
270143fc13bSJean-Jacques Hiblot */
271143fc13bSJean-Jacques Hiblot #define PORT_PLS_MASK (0xf << 5)
272143fc13bSJean-Jacques Hiblot #define XDEV_U0 (0x0 << 5)
273143fc13bSJean-Jacques Hiblot #define XDEV_U2 (0x2 << 5)
274143fc13bSJean-Jacques Hiblot #define XDEV_U3 (0x3 << 5)
275143fc13bSJean-Jacques Hiblot #define XDEV_RESUME (0xf << 5)
276143fc13bSJean-Jacques Hiblot /* true: port has power (see HCC_PPC) */
277143fc13bSJean-Jacques Hiblot #define PORT_POWER (1 << 9)
278143fc13bSJean-Jacques Hiblot /* bits 10:13 indicate device speed:
279143fc13bSJean-Jacques Hiblot * 0 - undefined speed - port hasn't be initialized by a reset yet
280143fc13bSJean-Jacques Hiblot * 1 - full speed
281143fc13bSJean-Jacques Hiblot * 2 - low speed
282143fc13bSJean-Jacques Hiblot * 3 - high speed
283143fc13bSJean-Jacques Hiblot * 4 - super speed
284143fc13bSJean-Jacques Hiblot * 5-15 reserved
285143fc13bSJean-Jacques Hiblot */
286143fc13bSJean-Jacques Hiblot #define DEV_SPEED_MASK (0xf << 10)
287143fc13bSJean-Jacques Hiblot #define XDEV_FS (0x1 << 10)
288143fc13bSJean-Jacques Hiblot #define XDEV_LS (0x2 << 10)
289143fc13bSJean-Jacques Hiblot #define XDEV_HS (0x3 << 10)
290143fc13bSJean-Jacques Hiblot #define XDEV_SS (0x4 << 10)
291143fc13bSJean-Jacques Hiblot #define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10))
292143fc13bSJean-Jacques Hiblot #define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS)
293143fc13bSJean-Jacques Hiblot #define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS)
294143fc13bSJean-Jacques Hiblot #define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS)
295143fc13bSJean-Jacques Hiblot #define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS)
296143fc13bSJean-Jacques Hiblot /* Bits 20:23 in the Slot Context are the speed for the device */
297143fc13bSJean-Jacques Hiblot #define SLOT_SPEED_FS (XDEV_FS << 10)
298143fc13bSJean-Jacques Hiblot #define SLOT_SPEED_LS (XDEV_LS << 10)
299143fc13bSJean-Jacques Hiblot #define SLOT_SPEED_HS (XDEV_HS << 10)
300143fc13bSJean-Jacques Hiblot #define SLOT_SPEED_SS (XDEV_SS << 10)
301143fc13bSJean-Jacques Hiblot /* Port Indicator Control */
302143fc13bSJean-Jacques Hiblot #define PORT_LED_OFF (0 << 14)
303143fc13bSJean-Jacques Hiblot #define PORT_LED_AMBER (1 << 14)
304143fc13bSJean-Jacques Hiblot #define PORT_LED_GREEN (2 << 14)
305143fc13bSJean-Jacques Hiblot #define PORT_LED_MASK (3 << 14)
306143fc13bSJean-Jacques Hiblot /* Port Link State Write Strobe - set this when changing link state */
307143fc13bSJean-Jacques Hiblot #define PORT_LINK_STROBE (1 << 16)
308143fc13bSJean-Jacques Hiblot /* true: connect status change */
309143fc13bSJean-Jacques Hiblot #define PORT_CSC (1 << 17)
310143fc13bSJean-Jacques Hiblot /* true: port enable change */
311143fc13bSJean-Jacques Hiblot #define PORT_PEC (1 << 18)
312143fc13bSJean-Jacques Hiblot /* true: warm reset for a USB 3.0 device is done. A "hot" reset puts the port
313143fc13bSJean-Jacques Hiblot * into an enabled state, and the device into the default state. A "warm" reset
314143fc13bSJean-Jacques Hiblot * also resets the link, forcing the device through the link training sequence.
315143fc13bSJean-Jacques Hiblot * SW can also look at the Port Reset register to see when warm reset is done.
316143fc13bSJean-Jacques Hiblot */
317143fc13bSJean-Jacques Hiblot #define PORT_WRC (1 << 19)
318143fc13bSJean-Jacques Hiblot /* true: over-current change */
319143fc13bSJean-Jacques Hiblot #define PORT_OCC (1 << 20)
320143fc13bSJean-Jacques Hiblot /* true: reset change - 1 to 0 transition of PORT_RESET */
321143fc13bSJean-Jacques Hiblot #define PORT_RC (1 << 21)
322143fc13bSJean-Jacques Hiblot /* port link status change - set on some port link state transitions:
323143fc13bSJean-Jacques Hiblot * Transition Reason
324143fc13bSJean-Jacques Hiblot * --------------------------------------------------------------------------
325143fc13bSJean-Jacques Hiblot * - U3 to Resume Wakeup signaling from a device
326143fc13bSJean-Jacques Hiblot * - Resume to Recovery to U0 USB 3.0 device resume
327143fc13bSJean-Jacques Hiblot * - Resume to U0 USB 2.0 device resume
328143fc13bSJean-Jacques Hiblot * - U3 to Recovery to U0 Software resume of USB 3.0 device complete
329143fc13bSJean-Jacques Hiblot * - U3 to U0 Software resume of USB 2.0 device complete
330143fc13bSJean-Jacques Hiblot * - U2 to U0 L1 resume of USB 2.1 device complete
331143fc13bSJean-Jacques Hiblot * - U0 to U0 (???) L1 entry rejection by USB 2.1 device
332143fc13bSJean-Jacques Hiblot * - U0 to disabled L1 entry error with USB 2.1 device
333143fc13bSJean-Jacques Hiblot * - Any state to inactive Error on USB 3.0 port
334143fc13bSJean-Jacques Hiblot */
335143fc13bSJean-Jacques Hiblot #define PORT_PLC (1 << 22)
336143fc13bSJean-Jacques Hiblot /* port configure error change - port failed to configure its link partner */
337143fc13bSJean-Jacques Hiblot #define PORT_CEC (1 << 23)
338143fc13bSJean-Jacques Hiblot /* bit 24 reserved */
339143fc13bSJean-Jacques Hiblot /* wake on connect (enable) */
340143fc13bSJean-Jacques Hiblot #define PORT_WKCONN_E (1 << 25)
341143fc13bSJean-Jacques Hiblot /* wake on disconnect (enable) */
342143fc13bSJean-Jacques Hiblot #define PORT_WKDISC_E (1 << 26)
343143fc13bSJean-Jacques Hiblot /* wake on over-current (enable) */
344143fc13bSJean-Jacques Hiblot #define PORT_WKOC_E (1 << 27)
345143fc13bSJean-Jacques Hiblot /* bits 28:29 reserved */
346143fc13bSJean-Jacques Hiblot /* true: device is removable - for USB 3.0 roothub emulation */
347143fc13bSJean-Jacques Hiblot #define PORT_DEV_REMOVE (1 << 30)
348143fc13bSJean-Jacques Hiblot /* Initiate a warm port reset - complete when PORT_WRC is '1' */
349143fc13bSJean-Jacques Hiblot #define PORT_WR (1 << 31)
350143fc13bSJean-Jacques Hiblot
351143fc13bSJean-Jacques Hiblot /* We mark duplicate entries with -1 */
352143fc13bSJean-Jacques Hiblot #define DUPLICATE_ENTRY ((u8)(-1))
353143fc13bSJean-Jacques Hiblot
354143fc13bSJean-Jacques Hiblot /* Port Power Management Status and Control - port_power_base bitmasks */
355143fc13bSJean-Jacques Hiblot /* Inactivity timer value for transitions into U1, in microseconds.
356143fc13bSJean-Jacques Hiblot * Timeout can be up to 127us. 0xFF means an infinite timeout.
357143fc13bSJean-Jacques Hiblot */
358143fc13bSJean-Jacques Hiblot #define PORT_U1_TIMEOUT(p) ((p) & 0xff)
359143fc13bSJean-Jacques Hiblot /* Inactivity timer value for transitions into U2 */
360143fc13bSJean-Jacques Hiblot #define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
361143fc13bSJean-Jacques Hiblot /* Bits 24:31 for port testing */
362143fc13bSJean-Jacques Hiblot
363143fc13bSJean-Jacques Hiblot /* USB2 Protocol PORTSPMSC */
364143fc13bSJean-Jacques Hiblot #define PORT_L1S_MASK 7
365143fc13bSJean-Jacques Hiblot #define PORT_L1S_SUCCESS 1
366143fc13bSJean-Jacques Hiblot #define PORT_RWE (1 << 3)
367143fc13bSJean-Jacques Hiblot #define PORT_HIRD(p) (((p) & 0xf) << 4)
368143fc13bSJean-Jacques Hiblot #define PORT_HIRD_MASK (0xf << 4)
369143fc13bSJean-Jacques Hiblot #define PORT_L1DS(p) (((p) & 0xff) << 8)
370143fc13bSJean-Jacques Hiblot #define PORT_HLE (1 << 16)
371143fc13bSJean-Jacques Hiblot
372143fc13bSJean-Jacques Hiblot /**
373143fc13bSJean-Jacques Hiblot * struct xhci_intr_reg - Interrupt Register Set
374143fc13bSJean-Jacques Hiblot * @irq_pending: IMAN - Interrupt Management Register. Used to enable
375143fc13bSJean-Jacques Hiblot * interrupts and check for pending interrupts.
376143fc13bSJean-Jacques Hiblot * @irq_control: IMOD - Interrupt Moderation Register.
377143fc13bSJean-Jacques Hiblot * Used to throttle interrupts.
378143fc13bSJean-Jacques Hiblot * @erst_size: Number of segments in the
379143fc13bSJean-Jacques Hiblot Event Ring Segment Table (ERST).
380143fc13bSJean-Jacques Hiblot * @erst_base: ERST base address.
381143fc13bSJean-Jacques Hiblot * @erst_dequeue: Event ring dequeue pointer.
382143fc13bSJean-Jacques Hiblot *
383143fc13bSJean-Jacques Hiblot * Each interrupter (defined by a MSI-X vector) has an event ring and an Event
384143fc13bSJean-Jacques Hiblot * Ring Segment Table (ERST) associated with it.
385143fc13bSJean-Jacques Hiblot * The event ring is comprised of multiple segments of the same size.
386143fc13bSJean-Jacques Hiblot * The HC places events on the ring and "updates the Cycle bit in the TRBs to
387143fc13bSJean-Jacques Hiblot * indicate to software the current position of the Enqueue Pointer."
388143fc13bSJean-Jacques Hiblot * The HCD (Linux) processes those events and updates the dequeue pointer.
389143fc13bSJean-Jacques Hiblot */
390143fc13bSJean-Jacques Hiblot struct xhci_intr_reg {
391143fc13bSJean-Jacques Hiblot volatile __le32 irq_pending;
392143fc13bSJean-Jacques Hiblot volatile __le32 irq_control;
393143fc13bSJean-Jacques Hiblot volatile __le32 erst_size;
394143fc13bSJean-Jacques Hiblot volatile __le32 rsvd;
395143fc13bSJean-Jacques Hiblot volatile __le64 erst_base;
396143fc13bSJean-Jacques Hiblot volatile __le64 erst_dequeue;
397143fc13bSJean-Jacques Hiblot };
398143fc13bSJean-Jacques Hiblot
399143fc13bSJean-Jacques Hiblot /* irq_pending bitmasks */
400143fc13bSJean-Jacques Hiblot #define ER_IRQ_PENDING(p) ((p) & 0x1)
401143fc13bSJean-Jacques Hiblot /* bits 2:31 need to be preserved */
402143fc13bSJean-Jacques Hiblot /* THIS IS BUGGY - FIXME - IP IS WRITE 1 TO CLEAR */
403143fc13bSJean-Jacques Hiblot #define ER_IRQ_CLEAR(p) ((p) & 0xfffffffe)
404143fc13bSJean-Jacques Hiblot #define ER_IRQ_ENABLE(p) ((ER_IRQ_CLEAR(p)) | 0x2)
405143fc13bSJean-Jacques Hiblot #define ER_IRQ_DISABLE(p) ((ER_IRQ_CLEAR(p)) & ~(0x2))
406143fc13bSJean-Jacques Hiblot
407143fc13bSJean-Jacques Hiblot /* irq_control bitmasks */
408143fc13bSJean-Jacques Hiblot /* Minimum interval between interrupts (in 250ns intervals). The interval
409143fc13bSJean-Jacques Hiblot * between interrupts will be longer if there are no events on the event ring.
410143fc13bSJean-Jacques Hiblot * Default is 4000 (1 ms).
411143fc13bSJean-Jacques Hiblot */
412143fc13bSJean-Jacques Hiblot #define ER_IRQ_INTERVAL_MASK (0xffff)
413143fc13bSJean-Jacques Hiblot /* Counter used to count down the time to the next interrupt - HW use only */
414143fc13bSJean-Jacques Hiblot #define ER_IRQ_COUNTER_MASK (0xffff << 16)
415143fc13bSJean-Jacques Hiblot
416143fc13bSJean-Jacques Hiblot /* erst_size bitmasks */
417143fc13bSJean-Jacques Hiblot /* Preserve bits 16:31 of erst_size */
418143fc13bSJean-Jacques Hiblot #define ERST_SIZE_MASK (0xffff << 16)
419143fc13bSJean-Jacques Hiblot
420143fc13bSJean-Jacques Hiblot /* erst_dequeue bitmasks */
421143fc13bSJean-Jacques Hiblot /* Dequeue ERST Segment Index (DESI) - Segment number (or alias)
422143fc13bSJean-Jacques Hiblot * where the current dequeue pointer lies. This is an optional HW hint.
423143fc13bSJean-Jacques Hiblot */
424143fc13bSJean-Jacques Hiblot #define ERST_DESI_MASK (0x7)
425143fc13bSJean-Jacques Hiblot /* Event Handler Busy (EHB) - is the event ring scheduled to be serviced by
426143fc13bSJean-Jacques Hiblot * a work queue (or delayed service routine)?
427143fc13bSJean-Jacques Hiblot */
428143fc13bSJean-Jacques Hiblot #define ERST_EHB (1 << 3)
429143fc13bSJean-Jacques Hiblot #define ERST_PTR_MASK (0xf)
430143fc13bSJean-Jacques Hiblot
431143fc13bSJean-Jacques Hiblot /**
432143fc13bSJean-Jacques Hiblot * struct xhci_run_regs
433143fc13bSJean-Jacques Hiblot * @microframe_index: MFINDEX - current microframe number
434143fc13bSJean-Jacques Hiblot *
435143fc13bSJean-Jacques Hiblot * Section 5.5 Host Controller Runtime Registers:
436143fc13bSJean-Jacques Hiblot * "Software should read and write these registers using only Dword (32 bit)
437143fc13bSJean-Jacques Hiblot * or larger accesses"
438143fc13bSJean-Jacques Hiblot */
439143fc13bSJean-Jacques Hiblot struct xhci_run_regs {
440143fc13bSJean-Jacques Hiblot __le32 microframe_index;
441143fc13bSJean-Jacques Hiblot __le32 rsvd[7];
442143fc13bSJean-Jacques Hiblot struct xhci_intr_reg ir_set[128];
443143fc13bSJean-Jacques Hiblot };
444143fc13bSJean-Jacques Hiblot
445143fc13bSJean-Jacques Hiblot /**
446143fc13bSJean-Jacques Hiblot * struct doorbell_array
447143fc13bSJean-Jacques Hiblot *
448143fc13bSJean-Jacques Hiblot * Bits 0 - 7: Endpoint target
449143fc13bSJean-Jacques Hiblot * Bits 8 - 15: RsvdZ
450143fc13bSJean-Jacques Hiblot * Bits 16 - 31: Stream ID
451143fc13bSJean-Jacques Hiblot *
452143fc13bSJean-Jacques Hiblot * Section 5.6
453143fc13bSJean-Jacques Hiblot */
454143fc13bSJean-Jacques Hiblot struct xhci_doorbell_array {
455143fc13bSJean-Jacques Hiblot volatile __le32 doorbell[256];
456143fc13bSJean-Jacques Hiblot };
457143fc13bSJean-Jacques Hiblot
458143fc13bSJean-Jacques Hiblot #define DB_VALUE(ep, stream) ((((ep) + 1) & 0xff) | ((stream) << 16))
459143fc13bSJean-Jacques Hiblot #define DB_VALUE_HOST 0x00000000
460143fc13bSJean-Jacques Hiblot
461143fc13bSJean-Jacques Hiblot /**
462143fc13bSJean-Jacques Hiblot * struct xhci_protocol_caps
463143fc13bSJean-Jacques Hiblot * @revision: major revision, minor revision, capability ID,
464143fc13bSJean-Jacques Hiblot * and next capability pointer.
465143fc13bSJean-Jacques Hiblot * @name_string: Four ASCII characters to say which spec this xHC
466143fc13bSJean-Jacques Hiblot * follows, typically "USB ".
467143fc13bSJean-Jacques Hiblot * @port_info: Port offset, count, and protocol-defined information.
468143fc13bSJean-Jacques Hiblot */
469143fc13bSJean-Jacques Hiblot struct xhci_protocol_caps {
470143fc13bSJean-Jacques Hiblot u32 revision;
471143fc13bSJean-Jacques Hiblot u32 name_string;
472143fc13bSJean-Jacques Hiblot u32 port_info;
473143fc13bSJean-Jacques Hiblot };
474143fc13bSJean-Jacques Hiblot
475143fc13bSJean-Jacques Hiblot #define XHCI_EXT_PORT_MAJOR(x) (((x) >> 24) & 0xff)
476143fc13bSJean-Jacques Hiblot #define XHCI_EXT_PORT_OFF(x) ((x) & 0xff)
477143fc13bSJean-Jacques Hiblot #define XHCI_EXT_PORT_COUNT(x) (((x) >> 8) & 0xff)
478143fc13bSJean-Jacques Hiblot
479143fc13bSJean-Jacques Hiblot /**
480143fc13bSJean-Jacques Hiblot * struct xhci_container_ctx
481143fc13bSJean-Jacques Hiblot * @type: Type of context. Used to calculated offsets to contained contexts.
482143fc13bSJean-Jacques Hiblot * @size: Size of the context data
483143fc13bSJean-Jacques Hiblot * @bytes: The raw context data given to HW
484143fc13bSJean-Jacques Hiblot *
485143fc13bSJean-Jacques Hiblot * Represents either a Device or Input context. Holds a pointer to the raw
486143fc13bSJean-Jacques Hiblot * memory used for the context (bytes).
487143fc13bSJean-Jacques Hiblot */
488143fc13bSJean-Jacques Hiblot struct xhci_container_ctx {
489143fc13bSJean-Jacques Hiblot unsigned type;
490143fc13bSJean-Jacques Hiblot #define XHCI_CTX_TYPE_DEVICE 0x1
491143fc13bSJean-Jacques Hiblot #define XHCI_CTX_TYPE_INPUT 0x2
492143fc13bSJean-Jacques Hiblot
493143fc13bSJean-Jacques Hiblot int size;
494143fc13bSJean-Jacques Hiblot u8 *bytes;
495143fc13bSJean-Jacques Hiblot };
496143fc13bSJean-Jacques Hiblot
497143fc13bSJean-Jacques Hiblot /**
498143fc13bSJean-Jacques Hiblot * struct xhci_slot_ctx
499143fc13bSJean-Jacques Hiblot * @dev_info: Route string, device speed, hub info, and last valid endpoint
500143fc13bSJean-Jacques Hiblot * @dev_info2: Max exit latency for device number, root hub port number
501143fc13bSJean-Jacques Hiblot * @tt_info: tt_info is used to construct split transaction tokens
502143fc13bSJean-Jacques Hiblot * @dev_state: slot state and device address
503143fc13bSJean-Jacques Hiblot *
504143fc13bSJean-Jacques Hiblot * Slot Context - section 6.2.1.1. This assumes the HC uses 32-byte context
505143fc13bSJean-Jacques Hiblot * structures. If the HC uses 64-byte contexts, there is an additional 32 bytes
506143fc13bSJean-Jacques Hiblot * reserved at the end of the slot context for HC internal use.
507143fc13bSJean-Jacques Hiblot */
508143fc13bSJean-Jacques Hiblot struct xhci_slot_ctx {
509143fc13bSJean-Jacques Hiblot __le32 dev_info;
510143fc13bSJean-Jacques Hiblot __le32 dev_info2;
511143fc13bSJean-Jacques Hiblot __le32 tt_info;
512143fc13bSJean-Jacques Hiblot __le32 dev_state;
513143fc13bSJean-Jacques Hiblot /* offset 0x10 to 0x1f reserved for HC internal use */
514143fc13bSJean-Jacques Hiblot __le32 reserved[4];
515143fc13bSJean-Jacques Hiblot };
516143fc13bSJean-Jacques Hiblot
517143fc13bSJean-Jacques Hiblot /* dev_info bitmasks */
518143fc13bSJean-Jacques Hiblot /* Route String - 0:19 */
519143fc13bSJean-Jacques Hiblot #define ROUTE_STRING_MASK (0xfffff)
520143fc13bSJean-Jacques Hiblot /* Device speed - values defined by PORTSC Device Speed field - 20:23 */
521143fc13bSJean-Jacques Hiblot #define DEV_SPEED (0xf << 20)
522143fc13bSJean-Jacques Hiblot /* bit 24 reserved */
523143fc13bSJean-Jacques Hiblot /* Is this LS/FS device connected through a HS hub? - bit 25 */
524143fc13bSJean-Jacques Hiblot #define DEV_MTT (0x1 << 25)
525143fc13bSJean-Jacques Hiblot /* Set if the device is a hub - bit 26 */
526143fc13bSJean-Jacques Hiblot #define DEV_HUB (0x1 << 26)
527143fc13bSJean-Jacques Hiblot /* Index of the last valid endpoint context in this device context - 27:31 */
528143fc13bSJean-Jacques Hiblot #define LAST_CTX_MASK (0x1f << 27)
529143fc13bSJean-Jacques Hiblot #define LAST_CTX(p) ((p) << 27)
530143fc13bSJean-Jacques Hiblot #define LAST_CTX_TO_EP_NUM(p) (((p) >> 27) - 1)
531143fc13bSJean-Jacques Hiblot #define SLOT_FLAG (1 << 0)
532143fc13bSJean-Jacques Hiblot #define EP0_FLAG (1 << 1)
533143fc13bSJean-Jacques Hiblot
534143fc13bSJean-Jacques Hiblot /* dev_info2 bitmasks */
535143fc13bSJean-Jacques Hiblot /* Max Exit Latency (ms) - worst case time to wake up all links in dev path */
536143fc13bSJean-Jacques Hiblot #define MAX_EXIT (0xffff)
537143fc13bSJean-Jacques Hiblot /* Root hub port number that is needed to access the USB device */
538143fc13bSJean-Jacques Hiblot #define ROOT_HUB_PORT(p) (((p) & 0xff) << 16)
539143fc13bSJean-Jacques Hiblot #define ROOT_HUB_PORT_MASK (0xff)
540143fc13bSJean-Jacques Hiblot #define ROOT_HUB_PORT_SHIFT (16)
541143fc13bSJean-Jacques Hiblot #define DEVINFO_TO_ROOT_HUB_PORT(p) (((p) >> 16) & 0xff)
542143fc13bSJean-Jacques Hiblot /* Maximum number of ports under a hub device */
543143fc13bSJean-Jacques Hiblot #define XHCI_MAX_PORTS(p) (((p) & 0xff) << 24)
544143fc13bSJean-Jacques Hiblot
545143fc13bSJean-Jacques Hiblot /* tt_info bitmasks */
546143fc13bSJean-Jacques Hiblot /*
547143fc13bSJean-Jacques Hiblot * TT Hub Slot ID - for low or full speed devices attached to a high-speed hub
548143fc13bSJean-Jacques Hiblot * The Slot ID of the hub that isolates the high speed signaling from
549143fc13bSJean-Jacques Hiblot * this low or full-speed device. '0' if attached to root hub port.
550143fc13bSJean-Jacques Hiblot */
551143fc13bSJean-Jacques Hiblot #define TT_SLOT(p) (((p) & 0xff) << 0)
552143fc13bSJean-Jacques Hiblot /*
553143fc13bSJean-Jacques Hiblot * The number of the downstream facing port of the high-speed hub
554143fc13bSJean-Jacques Hiblot * '0' if the device is not low or full speed.
555143fc13bSJean-Jacques Hiblot */
556143fc13bSJean-Jacques Hiblot #define TT_PORT(p) (((p) & 0xff) << 8)
557143fc13bSJean-Jacques Hiblot #define TT_THINK_TIME(p) (((p) & 0x3) << 16)
558143fc13bSJean-Jacques Hiblot
559143fc13bSJean-Jacques Hiblot /* dev_state bitmasks */
560143fc13bSJean-Jacques Hiblot /* USB device address - assigned by the HC */
561143fc13bSJean-Jacques Hiblot #define DEV_ADDR_MASK (0xff)
562143fc13bSJean-Jacques Hiblot /* bits 8:26 reserved */
563143fc13bSJean-Jacques Hiblot /* Slot state */
564143fc13bSJean-Jacques Hiblot #define SLOT_STATE (0x1f << 27)
565143fc13bSJean-Jacques Hiblot #define GET_SLOT_STATE(p) (((p) & (0x1f << 27)) >> 27)
566143fc13bSJean-Jacques Hiblot
567143fc13bSJean-Jacques Hiblot #define SLOT_STATE_DISABLED 0
568143fc13bSJean-Jacques Hiblot #define SLOT_STATE_ENABLED SLOT_STATE_DISABLED
569143fc13bSJean-Jacques Hiblot #define SLOT_STATE_DEFAULT 1
570143fc13bSJean-Jacques Hiblot #define SLOT_STATE_ADDRESSED 2
571143fc13bSJean-Jacques Hiblot #define SLOT_STATE_CONFIGURED 3
572143fc13bSJean-Jacques Hiblot
573143fc13bSJean-Jacques Hiblot /**
574143fc13bSJean-Jacques Hiblot * struct xhci_ep_ctx
575143fc13bSJean-Jacques Hiblot * @ep_info: endpoint state, streams, mult, and interval information.
576143fc13bSJean-Jacques Hiblot * @ep_info2: information on endpoint type, max packet size, max burst size,
577143fc13bSJean-Jacques Hiblot * error count, and whether the HC will force an event for all
578143fc13bSJean-Jacques Hiblot * transactions.
579143fc13bSJean-Jacques Hiblot * @deq: 64-bit ring dequeue pointer address. If the endpoint only
580143fc13bSJean-Jacques Hiblot * defines one stream, this points to the endpoint transfer ring.
581143fc13bSJean-Jacques Hiblot * Otherwise, it points to a stream context array, which has a
582143fc13bSJean-Jacques Hiblot * ring pointer for each flow.
583143fc13bSJean-Jacques Hiblot * @tx_info:
584143fc13bSJean-Jacques Hiblot * Average TRB lengths for the endpoint ring and
585143fc13bSJean-Jacques Hiblot * max payload within an Endpoint Service Interval Time (ESIT).
586143fc13bSJean-Jacques Hiblot *
587143fc13bSJean-Jacques Hiblot * Endpoint Context - section 6.2.1.2.This assumes the HC uses 32-byte context
588143fc13bSJean-Jacques Hiblot * structures.If the HC uses 64-byte contexts, there is an additional 32 bytes
589143fc13bSJean-Jacques Hiblot * reserved at the end of the endpoint context for HC internal use.
590143fc13bSJean-Jacques Hiblot */
591143fc13bSJean-Jacques Hiblot struct xhci_ep_ctx {
592143fc13bSJean-Jacques Hiblot __le32 ep_info;
593143fc13bSJean-Jacques Hiblot __le32 ep_info2;
594143fc13bSJean-Jacques Hiblot __le64 deq;
595143fc13bSJean-Jacques Hiblot __le32 tx_info;
596143fc13bSJean-Jacques Hiblot /* offset 0x14 - 0x1f reserved for HC internal use */
597143fc13bSJean-Jacques Hiblot __le32 reserved[3];
598143fc13bSJean-Jacques Hiblot };
599143fc13bSJean-Jacques Hiblot
600143fc13bSJean-Jacques Hiblot /* ep_info bitmasks */
601143fc13bSJean-Jacques Hiblot /*
602143fc13bSJean-Jacques Hiblot * Endpoint State - bits 0:2
603143fc13bSJean-Jacques Hiblot * 0 - disabled
604143fc13bSJean-Jacques Hiblot * 1 - running
605143fc13bSJean-Jacques Hiblot * 2 - halted due to halt condition - ok to manipulate endpoint ring
606143fc13bSJean-Jacques Hiblot * 3 - stopped
607143fc13bSJean-Jacques Hiblot * 4 - TRB error
608143fc13bSJean-Jacques Hiblot * 5-7 - reserved
609143fc13bSJean-Jacques Hiblot */
610143fc13bSJean-Jacques Hiblot #define EP_STATE_MASK (0xf)
611143fc13bSJean-Jacques Hiblot #define EP_STATE_DISABLED 0
612143fc13bSJean-Jacques Hiblot #define EP_STATE_RUNNING 1
613143fc13bSJean-Jacques Hiblot #define EP_STATE_HALTED 2
614143fc13bSJean-Jacques Hiblot #define EP_STATE_STOPPED 3
615143fc13bSJean-Jacques Hiblot #define EP_STATE_ERROR 4
616143fc13bSJean-Jacques Hiblot /* Mult - Max number of burtst within an interval, in EP companion desc. */
617143fc13bSJean-Jacques Hiblot #define EP_MULT(p) (((p) & 0x3) << 8)
618143fc13bSJean-Jacques Hiblot #define CTX_TO_EP_MULT(p) (((p) >> 8) & 0x3)
619143fc13bSJean-Jacques Hiblot /* bits 10:14 are Max Primary Streams */
620143fc13bSJean-Jacques Hiblot /* bit 15 is Linear Stream Array */
621143fc13bSJean-Jacques Hiblot /* Interval - period between requests to an endpoint - 125u increments. */
622143fc13bSJean-Jacques Hiblot #define EP_INTERVAL(p) (((p) & 0xff) << 16)
623143fc13bSJean-Jacques Hiblot #define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff))
624143fc13bSJean-Jacques Hiblot #define CTX_TO_EP_INTERVAL(p) (((p) >> 16) & 0xff)
625143fc13bSJean-Jacques Hiblot #define EP_MAXPSTREAMS_MASK (0x1f << 10)
626143fc13bSJean-Jacques Hiblot #define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK)
627143fc13bSJean-Jacques Hiblot /* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */
628143fc13bSJean-Jacques Hiblot #define EP_HAS_LSA (1 << 15)
629143fc13bSJean-Jacques Hiblot
630143fc13bSJean-Jacques Hiblot /* ep_info2 bitmasks */
631143fc13bSJean-Jacques Hiblot /*
632143fc13bSJean-Jacques Hiblot * Force Event - generate transfer events for all TRBs for this endpoint
633143fc13bSJean-Jacques Hiblot * This will tell the HC to ignore the IOC and ISP flags (for debugging only).
634143fc13bSJean-Jacques Hiblot */
635143fc13bSJean-Jacques Hiblot #define FORCE_EVENT (0x1)
636143fc13bSJean-Jacques Hiblot #define ERROR_COUNT(p) (((p) & 0x3) << 1)
637143fc13bSJean-Jacques Hiblot #define ERROR_COUNT_SHIFT (1)
638143fc13bSJean-Jacques Hiblot #define ERROR_COUNT_MASK (0x3)
639143fc13bSJean-Jacques Hiblot #define CTX_TO_EP_TYPE(p) (((p) >> 3) & 0x7)
640143fc13bSJean-Jacques Hiblot #define EP_TYPE(p) ((p) << 3)
641143fc13bSJean-Jacques Hiblot #define EP_TYPE_SHIFT (3)
642143fc13bSJean-Jacques Hiblot #define ISOC_OUT_EP 1
643143fc13bSJean-Jacques Hiblot #define BULK_OUT_EP 2
644143fc13bSJean-Jacques Hiblot #define INT_OUT_EP 3
645143fc13bSJean-Jacques Hiblot #define CTRL_EP 4
646143fc13bSJean-Jacques Hiblot #define ISOC_IN_EP 5
647143fc13bSJean-Jacques Hiblot #define BULK_IN_EP 6
648143fc13bSJean-Jacques Hiblot #define INT_IN_EP 7
649143fc13bSJean-Jacques Hiblot /* bit 6 reserved */
650143fc13bSJean-Jacques Hiblot /* bit 7 is Host Initiate Disable - for disabling stream selection */
651143fc13bSJean-Jacques Hiblot #define MAX_BURST(p) (((p)&0xff) << 8)
652143fc13bSJean-Jacques Hiblot #define MAX_BURST_MASK (0xff)
653143fc13bSJean-Jacques Hiblot #define MAX_BURST_SHIFT (8)
654143fc13bSJean-Jacques Hiblot #define CTX_TO_MAX_BURST(p) (((p) >> 8) & 0xff)
655143fc13bSJean-Jacques Hiblot #define MAX_PACKET(p) (((p)&0xffff) << 16)
656143fc13bSJean-Jacques Hiblot #define MAX_PACKET_MASK (0xffff)
657143fc13bSJean-Jacques Hiblot #define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff)
658143fc13bSJean-Jacques Hiblot #define MAX_PACKET_SHIFT (16)
659143fc13bSJean-Jacques Hiblot
660143fc13bSJean-Jacques Hiblot /* Get max packet size from ep desc. Bit 10..0 specify the max packet size.
661143fc13bSJean-Jacques Hiblot * USB2.0 spec 9.6.6.
662143fc13bSJean-Jacques Hiblot */
663143fc13bSJean-Jacques Hiblot #define GET_MAX_PACKET(p) ((p) & 0x7ff)
664143fc13bSJean-Jacques Hiblot
665143fc13bSJean-Jacques Hiblot /* tx_info bitmasks */
666143fc13bSJean-Jacques Hiblot #define EP_AVG_TRB_LENGTH(p) ((p) & 0xffff)
667143fc13bSJean-Jacques Hiblot #define EP_MAX_ESIT_PAYLOAD_LO(p) (((p) & 0xffff) << 16)
668143fc13bSJean-Jacques Hiblot #define EP_MAX_ESIT_PAYLOAD_HI(p) ((((p) >> 16) & 0xff) << 24)
669143fc13bSJean-Jacques Hiblot #define CTX_TO_MAX_ESIT_PAYLOAD(p) (((p) >> 16) & 0xffff)
670143fc13bSJean-Jacques Hiblot
671143fc13bSJean-Jacques Hiblot /* deq bitmasks */
672143fc13bSJean-Jacques Hiblot #define EP_CTX_CYCLE_MASK (1 << 0)
673143fc13bSJean-Jacques Hiblot
674143fc13bSJean-Jacques Hiblot
675143fc13bSJean-Jacques Hiblot /**
676143fc13bSJean-Jacques Hiblot * struct xhci_input_control_context
677143fc13bSJean-Jacques Hiblot * Input control context; see section 6.2.5.
678143fc13bSJean-Jacques Hiblot *
679143fc13bSJean-Jacques Hiblot * @drop_context: set the bit of the endpoint context you want to disable
680143fc13bSJean-Jacques Hiblot * @add_context: set the bit of the endpoint context you want to enable
681143fc13bSJean-Jacques Hiblot */
682143fc13bSJean-Jacques Hiblot struct xhci_input_control_ctx {
683143fc13bSJean-Jacques Hiblot volatile __le32 drop_flags;
684143fc13bSJean-Jacques Hiblot volatile __le32 add_flags;
685143fc13bSJean-Jacques Hiblot __le32 rsvd2[6];
686143fc13bSJean-Jacques Hiblot };
687143fc13bSJean-Jacques Hiblot
688143fc13bSJean-Jacques Hiblot
689143fc13bSJean-Jacques Hiblot /**
690143fc13bSJean-Jacques Hiblot * struct xhci_device_context_array
691143fc13bSJean-Jacques Hiblot * @dev_context_ptr array of 64-bit DMA addresses for device contexts
692143fc13bSJean-Jacques Hiblot */
693143fc13bSJean-Jacques Hiblot struct xhci_device_context_array {
694143fc13bSJean-Jacques Hiblot /* 64-bit device addresses; we only write 32-bit addresses */
695143fc13bSJean-Jacques Hiblot __le64 dev_context_ptrs[MAX_HC_SLOTS];
696143fc13bSJean-Jacques Hiblot };
697143fc13bSJean-Jacques Hiblot /* TODO: write function to set the 64-bit device DMA address */
698143fc13bSJean-Jacques Hiblot /*
699143fc13bSJean-Jacques Hiblot * TODO: change this to be dynamically sized at HC mem init time since the HC
700143fc13bSJean-Jacques Hiblot * might not be able to handle the maximum number of devices possible.
701143fc13bSJean-Jacques Hiblot */
702143fc13bSJean-Jacques Hiblot
703143fc13bSJean-Jacques Hiblot
704143fc13bSJean-Jacques Hiblot struct xhci_transfer_event {
705143fc13bSJean-Jacques Hiblot /* 64-bit buffer address, or immediate data */
706143fc13bSJean-Jacques Hiblot __le64 buffer;
707143fc13bSJean-Jacques Hiblot __le32 transfer_len;
708143fc13bSJean-Jacques Hiblot /* This field is interpreted differently based on the type of TRB */
709143fc13bSJean-Jacques Hiblot volatile __le32 flags;
710143fc13bSJean-Jacques Hiblot };
711143fc13bSJean-Jacques Hiblot
712143fc13bSJean-Jacques Hiblot /* Transfer event TRB length bit mask */
713143fc13bSJean-Jacques Hiblot /* bits 0:23 */
714143fc13bSJean-Jacques Hiblot #define EVENT_TRB_LEN(p) ((p) & 0xffffff)
715143fc13bSJean-Jacques Hiblot
716143fc13bSJean-Jacques Hiblot /** Transfer Event bit fields **/
717143fc13bSJean-Jacques Hiblot #define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f)
718143fc13bSJean-Jacques Hiblot
719143fc13bSJean-Jacques Hiblot /* Completion Code - only applicable for some types of TRBs */
720143fc13bSJean-Jacques Hiblot #define COMP_CODE_MASK (0xff << 24)
721143fc13bSJean-Jacques Hiblot #define COMP_CODE_SHIFT (24)
722143fc13bSJean-Jacques Hiblot #define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24)
723143fc13bSJean-Jacques Hiblot
724143fc13bSJean-Jacques Hiblot typedef enum {
725143fc13bSJean-Jacques Hiblot COMP_SUCCESS = 1,
726143fc13bSJean-Jacques Hiblot /* Data Buffer Error */
727143fc13bSJean-Jacques Hiblot COMP_DB_ERR, /* 2 */
728143fc13bSJean-Jacques Hiblot /* Babble Detected Error */
729143fc13bSJean-Jacques Hiblot COMP_BABBLE, /* 3 */
730143fc13bSJean-Jacques Hiblot /* USB Transaction Error */
731143fc13bSJean-Jacques Hiblot COMP_TX_ERR, /* 4 */
732143fc13bSJean-Jacques Hiblot /* TRB Error - some TRB field is invalid */
733143fc13bSJean-Jacques Hiblot COMP_TRB_ERR, /* 5 */
734143fc13bSJean-Jacques Hiblot /* Stall Error - USB device is stalled */
735143fc13bSJean-Jacques Hiblot COMP_STALL, /* 6 */
736143fc13bSJean-Jacques Hiblot /* Resource Error - HC doesn't have memory for that device configuration */
737143fc13bSJean-Jacques Hiblot COMP_ENOMEM, /* 7 */
738143fc13bSJean-Jacques Hiblot /* Bandwidth Error - not enough room in schedule for this dev config */
739143fc13bSJean-Jacques Hiblot COMP_BW_ERR, /* 8 */
740143fc13bSJean-Jacques Hiblot /* No Slots Available Error - HC ran out of device slots */
741143fc13bSJean-Jacques Hiblot COMP_ENOSLOTS, /* 9 */
742143fc13bSJean-Jacques Hiblot /* Invalid Stream Type Error */
743143fc13bSJean-Jacques Hiblot COMP_STREAM_ERR, /* 10 */
744143fc13bSJean-Jacques Hiblot /* Slot Not Enabled Error - doorbell rung for disabled device slot */
745143fc13bSJean-Jacques Hiblot COMP_EBADSLT, /* 11 */
746143fc13bSJean-Jacques Hiblot /* Endpoint Not Enabled Error */
747143fc13bSJean-Jacques Hiblot COMP_EBADEP,/* 12 */
748143fc13bSJean-Jacques Hiblot /* Short Packet */
749143fc13bSJean-Jacques Hiblot COMP_SHORT_TX, /* 13 */
750143fc13bSJean-Jacques Hiblot /* Ring Underrun - doorbell rung for an empty isoc OUT ep ring */
751143fc13bSJean-Jacques Hiblot COMP_UNDERRUN, /* 14 */
752143fc13bSJean-Jacques Hiblot /* Ring Overrun - isoc IN ep ring is empty when ep is scheduled to RX */
753143fc13bSJean-Jacques Hiblot COMP_OVERRUN, /* 15 */
754143fc13bSJean-Jacques Hiblot /* Virtual Function Event Ring Full Error */
755143fc13bSJean-Jacques Hiblot COMP_VF_FULL, /* 16 */
756143fc13bSJean-Jacques Hiblot /* Parameter Error - Context parameter is invalid */
757143fc13bSJean-Jacques Hiblot COMP_EINVAL, /* 17 */
758143fc13bSJean-Jacques Hiblot /* Bandwidth Overrun Error - isoc ep exceeded its allocated bandwidth */
759143fc13bSJean-Jacques Hiblot COMP_BW_OVER,/* 18 */
760143fc13bSJean-Jacques Hiblot /* Context State Error - illegal context state transition requested */
761143fc13bSJean-Jacques Hiblot COMP_CTX_STATE,/* 19 */
762143fc13bSJean-Jacques Hiblot /* No Ping Response Error - HC didn't get PING_RESPONSE in time to TX */
763143fc13bSJean-Jacques Hiblot COMP_PING_ERR,/* 20 */
764143fc13bSJean-Jacques Hiblot /* Event Ring is full */
765143fc13bSJean-Jacques Hiblot COMP_ER_FULL,/* 21 */
766143fc13bSJean-Jacques Hiblot /* Incompatible Device Error */
767143fc13bSJean-Jacques Hiblot COMP_DEV_ERR,/* 22 */
768143fc13bSJean-Jacques Hiblot /* Missed Service Error - HC couldn't service an isoc ep within interval */
769143fc13bSJean-Jacques Hiblot COMP_MISSED_INT,/* 23 */
770143fc13bSJean-Jacques Hiblot /* Successfully stopped command ring */
771143fc13bSJean-Jacques Hiblot COMP_CMD_STOP, /* 24 */
772143fc13bSJean-Jacques Hiblot /* Successfully aborted current command and stopped command ring */
773143fc13bSJean-Jacques Hiblot COMP_CMD_ABORT, /* 25 */
774143fc13bSJean-Jacques Hiblot /* Stopped - transfer was terminated by a stop endpoint command */
775143fc13bSJean-Jacques Hiblot COMP_STOP,/* 26 */
776143fc13bSJean-Jacques Hiblot /* Same as COMP_EP_STOPPED, but the transferred length in the event
777143fc13bSJean-Jacques Hiblot * is invalid */
778143fc13bSJean-Jacques Hiblot COMP_STOP_INVAL, /* 27*/
779143fc13bSJean-Jacques Hiblot /* Control Abort Error - Debug Capability - control pipe aborted */
780143fc13bSJean-Jacques Hiblot COMP_DBG_ABORT, /* 28 */
781143fc13bSJean-Jacques Hiblot /* Max Exit Latency Too Large Error */
782143fc13bSJean-Jacques Hiblot COMP_MEL_ERR,/* 29 */
783143fc13bSJean-Jacques Hiblot /* TRB type 30 reserved */
784143fc13bSJean-Jacques Hiblot /* Isoc Buffer Overrun - an isoc IN ep sent more data than could fit in TD */
785143fc13bSJean-Jacques Hiblot COMP_BUFF_OVER = 31,
786143fc13bSJean-Jacques Hiblot /* Event Lost Error - xHC has an "internal event overrun condition" */
787143fc13bSJean-Jacques Hiblot COMP_ISSUES, /* 32 */
788143fc13bSJean-Jacques Hiblot /* Undefined Error - reported when other error codes don't apply */
789143fc13bSJean-Jacques Hiblot COMP_UNKNOWN, /* 33 */
790143fc13bSJean-Jacques Hiblot /* Invalid Stream ID Error */
791143fc13bSJean-Jacques Hiblot COMP_STRID_ERR, /* 34 */
792143fc13bSJean-Jacques Hiblot /* Secondary Bandwidth Error - may be returned by a Configure Endpoint cmd */
793143fc13bSJean-Jacques Hiblot COMP_2ND_BW_ERR, /* 35 */
794143fc13bSJean-Jacques Hiblot /* Split Transaction Error */
795143fc13bSJean-Jacques Hiblot COMP_SPLIT_ERR /* 36 */
796143fc13bSJean-Jacques Hiblot
797143fc13bSJean-Jacques Hiblot } xhci_comp_code;
798143fc13bSJean-Jacques Hiblot
799143fc13bSJean-Jacques Hiblot struct xhci_link_trb {
800143fc13bSJean-Jacques Hiblot /* 64-bit segment pointer*/
801143fc13bSJean-Jacques Hiblot volatile __le64 segment_ptr;
802143fc13bSJean-Jacques Hiblot volatile __le32 intr_target;
803143fc13bSJean-Jacques Hiblot volatile __le32 control;
804143fc13bSJean-Jacques Hiblot };
805143fc13bSJean-Jacques Hiblot
806143fc13bSJean-Jacques Hiblot /* control bitfields */
807143fc13bSJean-Jacques Hiblot #define LINK_TOGGLE (0x1 << 1)
808143fc13bSJean-Jacques Hiblot
809143fc13bSJean-Jacques Hiblot /* Command completion event TRB */
810143fc13bSJean-Jacques Hiblot struct xhci_event_cmd {
811143fc13bSJean-Jacques Hiblot /* Pointer to command TRB, or the value passed by the event data trb */
812143fc13bSJean-Jacques Hiblot volatile __le64 cmd_trb;
813143fc13bSJean-Jacques Hiblot volatile __le32 status;
814143fc13bSJean-Jacques Hiblot volatile __le32 flags;
815143fc13bSJean-Jacques Hiblot };
816143fc13bSJean-Jacques Hiblot
817143fc13bSJean-Jacques Hiblot /* flags bitmasks */
818143fc13bSJean-Jacques Hiblot /* bits 16:23 are the virtual function ID */
819143fc13bSJean-Jacques Hiblot /* bits 24:31 are the slot ID */
820143fc13bSJean-Jacques Hiblot #define TRB_TO_SLOT_ID(p) (((p) & (0xff << 24)) >> 24)
821143fc13bSJean-Jacques Hiblot #define TRB_TO_SLOT_ID_SHIFT (24)
822143fc13bSJean-Jacques Hiblot #define TRB_TO_SLOT_ID_MASK (0xff << TRB_TO_SLOT_ID_SHIFT)
823143fc13bSJean-Jacques Hiblot #define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24)
824143fc13bSJean-Jacques Hiblot #define SLOT_ID_FOR_TRB_MASK (0xff)
825143fc13bSJean-Jacques Hiblot #define SLOT_ID_FOR_TRB_SHIFT (24)
826143fc13bSJean-Jacques Hiblot
827143fc13bSJean-Jacques Hiblot /* Stop Endpoint TRB - ep_index to endpoint ID for this TRB */
828143fc13bSJean-Jacques Hiblot #define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1)
829143fc13bSJean-Jacques Hiblot #define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16)
830143fc13bSJean-Jacques Hiblot
831143fc13bSJean-Jacques Hiblot #define SUSPEND_PORT_FOR_TRB(p) (((p) & 1) << 23)
832143fc13bSJean-Jacques Hiblot #define TRB_TO_SUSPEND_PORT(p) (((p) & (1 << 23)) >> 23)
833143fc13bSJean-Jacques Hiblot #define LAST_EP_INDEX 30
834143fc13bSJean-Jacques Hiblot
835143fc13bSJean-Jacques Hiblot /* Set TR Dequeue Pointer command TRB fields */
836143fc13bSJean-Jacques Hiblot #define TRB_TO_STREAM_ID(p) ((((p) & (0xffff << 16)) >> 16))
837143fc13bSJean-Jacques Hiblot #define STREAM_ID_FOR_TRB(p) ((((p)) & 0xffff) << 16)
838143fc13bSJean-Jacques Hiblot
839143fc13bSJean-Jacques Hiblot
840143fc13bSJean-Jacques Hiblot /* Port Status Change Event TRB fields */
841143fc13bSJean-Jacques Hiblot /* Port ID - bits 31:24 */
842143fc13bSJean-Jacques Hiblot #define GET_PORT_ID(p) (((p) & (0xff << 24)) >> 24)
843143fc13bSJean-Jacques Hiblot #define PORT_ID_SHIFT (24)
844143fc13bSJean-Jacques Hiblot #define PORT_ID_MASK (0xff << PORT_ID_SHIFT)
845143fc13bSJean-Jacques Hiblot
846143fc13bSJean-Jacques Hiblot /* Normal TRB fields */
847143fc13bSJean-Jacques Hiblot /* transfer_len bitmasks - bits 0:16 */
848143fc13bSJean-Jacques Hiblot #define TRB_LEN(p) ((p) & 0x1ffff)
849143fc13bSJean-Jacques Hiblot #define TRB_LEN_MASK (0x1ffff)
850143fc13bSJean-Jacques Hiblot /* Interrupter Target - which MSI-X vector to target the completion event at */
851143fc13bSJean-Jacques Hiblot #define TRB_INTR_TARGET_SHIFT (22)
852143fc13bSJean-Jacques Hiblot #define TRB_INTR_TARGET_MASK (0x3ff)
853143fc13bSJean-Jacques Hiblot #define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
854143fc13bSJean-Jacques Hiblot #define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
855143fc13bSJean-Jacques Hiblot #define TRB_TBC(p) (((p) & 0x3) << 7)
856143fc13bSJean-Jacques Hiblot #define TRB_TLBPC(p) (((p) & 0xf) << 16)
857143fc13bSJean-Jacques Hiblot
858143fc13bSJean-Jacques Hiblot /* Cycle bit - indicates TRB ownership by HC or HCD */
859143fc13bSJean-Jacques Hiblot #define TRB_CYCLE (1<<0)
860143fc13bSJean-Jacques Hiblot /*
861143fc13bSJean-Jacques Hiblot * Force next event data TRB to be evaluated before task switch.
862143fc13bSJean-Jacques Hiblot * Used to pass OS data back after a TD completes.
863143fc13bSJean-Jacques Hiblot */
864143fc13bSJean-Jacques Hiblot #define TRB_ENT (1<<1)
865143fc13bSJean-Jacques Hiblot /* Interrupt on short packet */
866143fc13bSJean-Jacques Hiblot #define TRB_ISP (1<<2)
867143fc13bSJean-Jacques Hiblot /* Set PCIe no snoop attribute */
868143fc13bSJean-Jacques Hiblot #define TRB_NO_SNOOP (1<<3)
869143fc13bSJean-Jacques Hiblot /* Chain multiple TRBs into a TD */
870143fc13bSJean-Jacques Hiblot #define TRB_CHAIN (1<<4)
871143fc13bSJean-Jacques Hiblot /* Interrupt on completion */
872143fc13bSJean-Jacques Hiblot #define TRB_IOC (1<<5)
873143fc13bSJean-Jacques Hiblot /* The buffer pointer contains immediate data */
874143fc13bSJean-Jacques Hiblot #define TRB_IDT (1<<6)
875143fc13bSJean-Jacques Hiblot
876143fc13bSJean-Jacques Hiblot /* Block Event Interrupt */
877143fc13bSJean-Jacques Hiblot #define TRB_BEI (1<<9)
878143fc13bSJean-Jacques Hiblot
879143fc13bSJean-Jacques Hiblot /* Control transfer TRB specific fields */
880143fc13bSJean-Jacques Hiblot #define TRB_DIR_IN (1<<16)
881143fc13bSJean-Jacques Hiblot #define TRB_TX_TYPE(p) ((p) << 16)
882143fc13bSJean-Jacques Hiblot #define TRB_TX_TYPE_SHIFT (16)
883143fc13bSJean-Jacques Hiblot #define TRB_DATA_OUT 2
884143fc13bSJean-Jacques Hiblot #define TRB_DATA_IN 3
885143fc13bSJean-Jacques Hiblot
886143fc13bSJean-Jacques Hiblot /* Isochronous TRB specific fields */
887143fc13bSJean-Jacques Hiblot #define TRB_SIA (1 << 31)
888143fc13bSJean-Jacques Hiblot
889143fc13bSJean-Jacques Hiblot struct xhci_generic_trb {
890143fc13bSJean-Jacques Hiblot volatile __le32 field[4];
891143fc13bSJean-Jacques Hiblot };
892143fc13bSJean-Jacques Hiblot
893143fc13bSJean-Jacques Hiblot union xhci_trb {
894143fc13bSJean-Jacques Hiblot struct xhci_link_trb link;
895143fc13bSJean-Jacques Hiblot struct xhci_transfer_event trans_event;
896143fc13bSJean-Jacques Hiblot struct xhci_event_cmd event_cmd;
897143fc13bSJean-Jacques Hiblot struct xhci_generic_trb generic;
898143fc13bSJean-Jacques Hiblot };
899143fc13bSJean-Jacques Hiblot
900143fc13bSJean-Jacques Hiblot /* TRB bit mask */
901143fc13bSJean-Jacques Hiblot #define TRB_TYPE_BITMASK (0xfc00)
902143fc13bSJean-Jacques Hiblot #define TRB_TYPE(p) ((p) << 10)
903143fc13bSJean-Jacques Hiblot #define TRB_TYPE_SHIFT (10)
904143fc13bSJean-Jacques Hiblot #define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10)
905143fc13bSJean-Jacques Hiblot
906143fc13bSJean-Jacques Hiblot /* TRB type IDs */
907143fc13bSJean-Jacques Hiblot typedef enum {
908143fc13bSJean-Jacques Hiblot /* bulk, interrupt, isoc scatter/gather, and control data stage */
909143fc13bSJean-Jacques Hiblot TRB_NORMAL = 1,
910143fc13bSJean-Jacques Hiblot /* setup stage for control transfers */
911143fc13bSJean-Jacques Hiblot TRB_SETUP, /* 2 */
912143fc13bSJean-Jacques Hiblot /* data stage for control transfers */
913143fc13bSJean-Jacques Hiblot TRB_DATA, /* 3 */
914143fc13bSJean-Jacques Hiblot /* status stage for control transfers */
915143fc13bSJean-Jacques Hiblot TRB_STATUS, /* 4 */
916143fc13bSJean-Jacques Hiblot /* isoc transfers */
917143fc13bSJean-Jacques Hiblot TRB_ISOC, /* 5 */
918143fc13bSJean-Jacques Hiblot /* TRB for linking ring segments */
919143fc13bSJean-Jacques Hiblot TRB_LINK, /* 6 */
920143fc13bSJean-Jacques Hiblot /* TRB for EVENT DATA */
921143fc13bSJean-Jacques Hiblot TRB_EVENT_DATA, /* 7 */
922143fc13bSJean-Jacques Hiblot /* Transfer Ring No-op (not for the command ring) */
923143fc13bSJean-Jacques Hiblot TRB_TR_NOOP, /* 8 */
924143fc13bSJean-Jacques Hiblot /* Command TRBs */
925143fc13bSJean-Jacques Hiblot /* Enable Slot Command */
926143fc13bSJean-Jacques Hiblot TRB_ENABLE_SLOT, /* 9 */
927143fc13bSJean-Jacques Hiblot /* Disable Slot Command */
928143fc13bSJean-Jacques Hiblot TRB_DISABLE_SLOT, /* 10 */
929143fc13bSJean-Jacques Hiblot /* Address Device Command */
930143fc13bSJean-Jacques Hiblot TRB_ADDR_DEV, /* 11 */
931143fc13bSJean-Jacques Hiblot /* Configure Endpoint Command */
932143fc13bSJean-Jacques Hiblot TRB_CONFIG_EP, /* 12 */
933143fc13bSJean-Jacques Hiblot /* Evaluate Context Command */
934143fc13bSJean-Jacques Hiblot TRB_EVAL_CONTEXT, /* 13 */
935143fc13bSJean-Jacques Hiblot /* Reset Endpoint Command */
936143fc13bSJean-Jacques Hiblot TRB_RESET_EP, /* 14 */
937143fc13bSJean-Jacques Hiblot /* Stop Transfer Ring Command */
938143fc13bSJean-Jacques Hiblot TRB_STOP_RING, /* 15 */
939143fc13bSJean-Jacques Hiblot /* Set Transfer Ring Dequeue Pointer Command */
940143fc13bSJean-Jacques Hiblot TRB_SET_DEQ, /* 16 */
941143fc13bSJean-Jacques Hiblot /* Reset Device Command */
942143fc13bSJean-Jacques Hiblot TRB_RESET_DEV, /* 17 */
943143fc13bSJean-Jacques Hiblot /* Force Event Command (opt) */
944143fc13bSJean-Jacques Hiblot TRB_FORCE_EVENT, /* 18 */
945143fc13bSJean-Jacques Hiblot /* Negotiate Bandwidth Command (opt) */
946143fc13bSJean-Jacques Hiblot TRB_NEG_BANDWIDTH, /* 19 */
947143fc13bSJean-Jacques Hiblot /* Set Latency Tolerance Value Command (opt) */
948143fc13bSJean-Jacques Hiblot TRB_SET_LT, /* 20 */
949143fc13bSJean-Jacques Hiblot /* Get port bandwidth Command */
950143fc13bSJean-Jacques Hiblot TRB_GET_BW, /* 21 */
951143fc13bSJean-Jacques Hiblot /* Force Header Command - generate a transaction or link management packet */
952143fc13bSJean-Jacques Hiblot TRB_FORCE_HEADER, /* 22 */
953143fc13bSJean-Jacques Hiblot /* No-op Command - not for transfer rings */
954143fc13bSJean-Jacques Hiblot TRB_CMD_NOOP, /* 23 */
955143fc13bSJean-Jacques Hiblot /* TRB IDs 24-31 reserved */
956143fc13bSJean-Jacques Hiblot /* Event TRBS */
957143fc13bSJean-Jacques Hiblot /* Transfer Event */
958143fc13bSJean-Jacques Hiblot TRB_TRANSFER = 32,
959143fc13bSJean-Jacques Hiblot /* Command Completion Event */
960143fc13bSJean-Jacques Hiblot TRB_COMPLETION, /* 33 */
961143fc13bSJean-Jacques Hiblot /* Port Status Change Event */
962143fc13bSJean-Jacques Hiblot TRB_PORT_STATUS, /* 34 */
963143fc13bSJean-Jacques Hiblot /* Bandwidth Request Event (opt) */
964143fc13bSJean-Jacques Hiblot TRB_BANDWIDTH_EVENT, /* 35 */
965143fc13bSJean-Jacques Hiblot /* Doorbell Event (opt) */
966143fc13bSJean-Jacques Hiblot TRB_DOORBELL, /* 36 */
967143fc13bSJean-Jacques Hiblot /* Host Controller Event */
968143fc13bSJean-Jacques Hiblot TRB_HC_EVENT, /* 37 */
969143fc13bSJean-Jacques Hiblot /* Device Notification Event - device sent function wake notification */
970143fc13bSJean-Jacques Hiblot TRB_DEV_NOTE, /* 38 */
971143fc13bSJean-Jacques Hiblot /* MFINDEX Wrap Event - microframe counter wrapped */
972143fc13bSJean-Jacques Hiblot TRB_MFINDEX_WRAP, /* 39 */
973143fc13bSJean-Jacques Hiblot /* TRB IDs 40-47 reserved, 48-63 is vendor-defined */
974143fc13bSJean-Jacques Hiblot /* Nec vendor-specific command completion event. */
975143fc13bSJean-Jacques Hiblot TRB_NEC_CMD_COMP = 48, /* 48 */
976143fc13bSJean-Jacques Hiblot /* Get NEC firmware revision. */
977143fc13bSJean-Jacques Hiblot TRB_NEC_GET_FW, /* 49 */
978143fc13bSJean-Jacques Hiblot } trb_type;
979143fc13bSJean-Jacques Hiblot
980143fc13bSJean-Jacques Hiblot #define TRB_TYPE_LINK(x) (((x) & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
981143fc13bSJean-Jacques Hiblot /* Above, but for __le32 types -- can avoid work by swapping constants: */
982143fc13bSJean-Jacques Hiblot #define TRB_TYPE_LINK_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
983143fc13bSJean-Jacques Hiblot cpu_to_le32(TRB_TYPE(TRB_LINK)))
984143fc13bSJean-Jacques Hiblot #define TRB_TYPE_NOOP_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
985143fc13bSJean-Jacques Hiblot cpu_to_le32(TRB_TYPE(TRB_TR_NOOP)))
986143fc13bSJean-Jacques Hiblot
987143fc13bSJean-Jacques Hiblot /*
988143fc13bSJean-Jacques Hiblot * TRBS_PER_SEGMENT must be a multiple of 4,
989143fc13bSJean-Jacques Hiblot * since the command ring is 64-byte aligned.
990143fc13bSJean-Jacques Hiblot * It must also be greater than 16.
991143fc13bSJean-Jacques Hiblot */
992143fc13bSJean-Jacques Hiblot #define TRBS_PER_SEGMENT 64
993143fc13bSJean-Jacques Hiblot /* Allow two commands + a link TRB, along with any reserved command TRBs */
994143fc13bSJean-Jacques Hiblot #define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
995143fc13bSJean-Jacques Hiblot #define SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
996143fc13bSJean-Jacques Hiblot /* SEGMENT_SHIFT should be log2(SEGMENT_SIZE).
997143fc13bSJean-Jacques Hiblot * Change this if you change TRBS_PER_SEGMENT!
998143fc13bSJean-Jacques Hiblot */
999143fc13bSJean-Jacques Hiblot #define SEGMENT_SHIFT 10
1000143fc13bSJean-Jacques Hiblot /* TRB buffer pointers can't cross 64KB boundaries */
1001143fc13bSJean-Jacques Hiblot #define TRB_MAX_BUFF_SHIFT 16
1002143fc13bSJean-Jacques Hiblot #define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT)
1003143fc13bSJean-Jacques Hiblot
1004143fc13bSJean-Jacques Hiblot struct xhci_segment {
1005143fc13bSJean-Jacques Hiblot union xhci_trb *trbs;
1006143fc13bSJean-Jacques Hiblot /* private to HCD */
1007143fc13bSJean-Jacques Hiblot struct xhci_segment *next;
1008143fc13bSJean-Jacques Hiblot };
1009143fc13bSJean-Jacques Hiblot
1010143fc13bSJean-Jacques Hiblot struct xhci_ring {
1011143fc13bSJean-Jacques Hiblot struct xhci_segment *first_seg;
1012143fc13bSJean-Jacques Hiblot union xhci_trb *enqueue;
1013143fc13bSJean-Jacques Hiblot struct xhci_segment *enq_seg;
1014143fc13bSJean-Jacques Hiblot union xhci_trb *dequeue;
1015143fc13bSJean-Jacques Hiblot struct xhci_segment *deq_seg;
1016143fc13bSJean-Jacques Hiblot /*
1017143fc13bSJean-Jacques Hiblot * Write the cycle state into the TRB cycle field to give ownership of
1018143fc13bSJean-Jacques Hiblot * the TRB to the host controller (if we are the producer), or to check
1019143fc13bSJean-Jacques Hiblot * if we own the TRB (if we are the consumer). See section 4.9.1.
1020143fc13bSJean-Jacques Hiblot */
1021143fc13bSJean-Jacques Hiblot volatile u32 cycle_state;
1022143fc13bSJean-Jacques Hiblot unsigned int num_segs;
1023143fc13bSJean-Jacques Hiblot };
1024143fc13bSJean-Jacques Hiblot
1025143fc13bSJean-Jacques Hiblot struct xhci_erst_entry {
1026143fc13bSJean-Jacques Hiblot /* 64-bit event ring segment address */
1027143fc13bSJean-Jacques Hiblot __le64 seg_addr;
1028143fc13bSJean-Jacques Hiblot __le32 seg_size;
1029143fc13bSJean-Jacques Hiblot /* Set to zero */
1030143fc13bSJean-Jacques Hiblot __le32 rsvd;
1031143fc13bSJean-Jacques Hiblot };
1032143fc13bSJean-Jacques Hiblot
1033143fc13bSJean-Jacques Hiblot struct xhci_erst {
1034143fc13bSJean-Jacques Hiblot struct xhci_erst_entry *entries;
1035143fc13bSJean-Jacques Hiblot unsigned int num_entries;
1036143fc13bSJean-Jacques Hiblot /* Num entries the ERST can contain */
1037143fc13bSJean-Jacques Hiblot unsigned int erst_size;
1038143fc13bSJean-Jacques Hiblot };
1039143fc13bSJean-Jacques Hiblot
1040143fc13bSJean-Jacques Hiblot struct xhci_scratchpad {
1041143fc13bSJean-Jacques Hiblot u64 *sp_array;
1042143fc13bSJean-Jacques Hiblot };
1043143fc13bSJean-Jacques Hiblot
1044143fc13bSJean-Jacques Hiblot /*
1045143fc13bSJean-Jacques Hiblot * Each segment table entry is 4*32bits long. 1K seems like an ok size:
1046143fc13bSJean-Jacques Hiblot * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table,
1047143fc13bSJean-Jacques Hiblot * meaning 64 ring segments.
1048143fc13bSJean-Jacques Hiblot * Initial allocated size of the ERST, in number of entries */
1049143fc13bSJean-Jacques Hiblot #define ERST_NUM_SEGS 1
1050143fc13bSJean-Jacques Hiblot /* Initial number of event segment rings allocated */
1051143fc13bSJean-Jacques Hiblot #define ERST_ENTRIES 1
1052143fc13bSJean-Jacques Hiblot /* Initial allocated size of the ERST, in number of entries */
1053143fc13bSJean-Jacques Hiblot #define ERST_SIZE 64
1054143fc13bSJean-Jacques Hiblot /* Poll every 60 seconds */
1055143fc13bSJean-Jacques Hiblot #define POLL_TIMEOUT 60
1056143fc13bSJean-Jacques Hiblot /* Stop endpoint command timeout (secs) for URB cancellation watchdog timer */
1057143fc13bSJean-Jacques Hiblot #define XHCI_STOP_EP_CMD_TIMEOUT 5
1058143fc13bSJean-Jacques Hiblot /* XXX: Make these module parameters */
1059143fc13bSJean-Jacques Hiblot
1060143fc13bSJean-Jacques Hiblot struct xhci_virt_ep {
1061143fc13bSJean-Jacques Hiblot struct xhci_ring *ring;
1062143fc13bSJean-Jacques Hiblot unsigned int ep_state;
1063143fc13bSJean-Jacques Hiblot #define SET_DEQ_PENDING (1 << 0)
1064143fc13bSJean-Jacques Hiblot #define EP_HALTED (1 << 1) /* For stall handling */
1065143fc13bSJean-Jacques Hiblot #define EP_HALT_PENDING (1 << 2) /* For URB cancellation */
1066143fc13bSJean-Jacques Hiblot /* Transitioning the endpoint to using streams, don't enqueue URBs */
1067143fc13bSJean-Jacques Hiblot #define EP_GETTING_STREAMS (1 << 3)
1068143fc13bSJean-Jacques Hiblot #define EP_HAS_STREAMS (1 << 4)
1069143fc13bSJean-Jacques Hiblot /* Transitioning the endpoint to not using streams, don't enqueue URBs */
1070143fc13bSJean-Jacques Hiblot #define EP_GETTING_NO_STREAMS (1 << 5)
1071143fc13bSJean-Jacques Hiblot };
1072143fc13bSJean-Jacques Hiblot
1073143fc13bSJean-Jacques Hiblot #define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32)
1074143fc13bSJean-Jacques Hiblot
1075143fc13bSJean-Jacques Hiblot struct xhci_virt_device {
1076143fc13bSJean-Jacques Hiblot struct usb_device *udev;
1077143fc13bSJean-Jacques Hiblot /*
1078143fc13bSJean-Jacques Hiblot * Commands to the hardware are passed an "input context" that
1079143fc13bSJean-Jacques Hiblot * tells the hardware what to change in its data structures.
1080143fc13bSJean-Jacques Hiblot * The hardware will return changes in an "output context" that
1081143fc13bSJean-Jacques Hiblot * software must allocate for the hardware. We need to keep
1082143fc13bSJean-Jacques Hiblot * track of input and output contexts separately because
1083143fc13bSJean-Jacques Hiblot * these commands might fail and we don't trust the hardware.
1084143fc13bSJean-Jacques Hiblot */
1085143fc13bSJean-Jacques Hiblot struct xhci_container_ctx *out_ctx;
1086143fc13bSJean-Jacques Hiblot /* Used for addressing devices and configuration changes */
1087143fc13bSJean-Jacques Hiblot struct xhci_container_ctx *in_ctx;
1088143fc13bSJean-Jacques Hiblot /* Rings saved to ensure old alt settings can be re-instated */
1089143fc13bSJean-Jacques Hiblot #define XHCI_MAX_RINGS_CACHED 31
1090143fc13bSJean-Jacques Hiblot struct xhci_virt_ep eps[31];
1091143fc13bSJean-Jacques Hiblot };
1092143fc13bSJean-Jacques Hiblot
1093143fc13bSJean-Jacques Hiblot /* TODO: copied from ehci.h - can be refactored? */
1094143fc13bSJean-Jacques Hiblot /* xHCI spec says all registers are little endian */
xhci_readl(uint32_t volatile * regs)1095143fc13bSJean-Jacques Hiblot static inline unsigned int xhci_readl(uint32_t volatile *regs)
1096143fc13bSJean-Jacques Hiblot {
1097143fc13bSJean-Jacques Hiblot return readl(regs);
1098143fc13bSJean-Jacques Hiblot }
1099143fc13bSJean-Jacques Hiblot
xhci_writel(uint32_t volatile * regs,const unsigned int val)1100143fc13bSJean-Jacques Hiblot static inline void xhci_writel(uint32_t volatile *regs, const unsigned int val)
1101143fc13bSJean-Jacques Hiblot {
1102143fc13bSJean-Jacques Hiblot writel(val, regs);
1103143fc13bSJean-Jacques Hiblot }
1104143fc13bSJean-Jacques Hiblot
1105143fc13bSJean-Jacques Hiblot /*
1106143fc13bSJean-Jacques Hiblot * Registers should always be accessed with double word or quad word accesses.
1107143fc13bSJean-Jacques Hiblot * Some xHCI implementations may support 64-bit address pointers. Registers
1108143fc13bSJean-Jacques Hiblot * with 64-bit address pointers should be written to with dword accesses by
1109143fc13bSJean-Jacques Hiblot * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second.
1110143fc13bSJean-Jacques Hiblot * xHCI implementations that do not support 64-bit address pointers will ignore
1111143fc13bSJean-Jacques Hiblot * the high dword, and write order is irrelevant.
1112143fc13bSJean-Jacques Hiblot */
xhci_readq(__le64 volatile * regs)1113143fc13bSJean-Jacques Hiblot static inline u64 xhci_readq(__le64 volatile *regs)
1114143fc13bSJean-Jacques Hiblot {
1115143fc13bSJean-Jacques Hiblot #if BITS_PER_LONG == 64
1116143fc13bSJean-Jacques Hiblot return readq(regs);
1117143fc13bSJean-Jacques Hiblot #else
1118143fc13bSJean-Jacques Hiblot __u32 *ptr = (__u32 *)regs;
1119143fc13bSJean-Jacques Hiblot u64 val_lo = readl(ptr);
1120143fc13bSJean-Jacques Hiblot u64 val_hi = readl(ptr + 1);
1121143fc13bSJean-Jacques Hiblot return val_lo + (val_hi << 32);
1122143fc13bSJean-Jacques Hiblot #endif
1123143fc13bSJean-Jacques Hiblot }
1124143fc13bSJean-Jacques Hiblot
xhci_writeq(__le64 volatile * regs,const u64 val)1125143fc13bSJean-Jacques Hiblot static inline void xhci_writeq(__le64 volatile *regs, const u64 val)
1126143fc13bSJean-Jacques Hiblot {
1127143fc13bSJean-Jacques Hiblot #if BITS_PER_LONG == 64
1128143fc13bSJean-Jacques Hiblot writeq(val, regs);
1129143fc13bSJean-Jacques Hiblot #else
1130143fc13bSJean-Jacques Hiblot __u32 *ptr = (__u32 *)regs;
1131143fc13bSJean-Jacques Hiblot u32 val_lo = lower_32_bits(val);
1132143fc13bSJean-Jacques Hiblot /* FIXME */
1133143fc13bSJean-Jacques Hiblot u32 val_hi = upper_32_bits(val);
1134143fc13bSJean-Jacques Hiblot writel(val_lo, ptr);
1135143fc13bSJean-Jacques Hiblot writel(val_hi, ptr + 1);
1136143fc13bSJean-Jacques Hiblot #endif
1137143fc13bSJean-Jacques Hiblot }
1138143fc13bSJean-Jacques Hiblot
1139143fc13bSJean-Jacques Hiblot int xhci_hcd_init(int index, struct xhci_hccr **ret_hccr,
1140143fc13bSJean-Jacques Hiblot struct xhci_hcor **ret_hcor);
1141143fc13bSJean-Jacques Hiblot void xhci_hcd_stop(int index);
1142143fc13bSJean-Jacques Hiblot
1143143fc13bSJean-Jacques Hiblot
1144143fc13bSJean-Jacques Hiblot /*************************************************************
1145143fc13bSJean-Jacques Hiblot EXTENDED CAPABILITY DEFINITIONS
1146143fc13bSJean-Jacques Hiblot *************************************************************/
1147143fc13bSJean-Jacques Hiblot /* Up to 16 ms to halt an HC */
1148143fc13bSJean-Jacques Hiblot #define XHCI_MAX_HALT_USEC (16*1000)
1149143fc13bSJean-Jacques Hiblot /* HC not running - set to 1 when run/stop bit is cleared. */
1150143fc13bSJean-Jacques Hiblot #define XHCI_STS_HALT (1 << 0)
1151143fc13bSJean-Jacques Hiblot
1152143fc13bSJean-Jacques Hiblot /* HCCPARAMS offset from PCI base address */
1153143fc13bSJean-Jacques Hiblot #define XHCI_HCC_PARAMS_OFFSET 0x10
1154143fc13bSJean-Jacques Hiblot /* HCCPARAMS contains the first extended capability pointer */
1155143fc13bSJean-Jacques Hiblot #define XHCI_HCC_EXT_CAPS(p) (((p)>>16)&0xffff)
1156143fc13bSJean-Jacques Hiblot
1157143fc13bSJean-Jacques Hiblot /* Command and Status registers offset from the Operational Registers address */
1158143fc13bSJean-Jacques Hiblot #define XHCI_CMD_OFFSET 0x00
1159143fc13bSJean-Jacques Hiblot #define XHCI_STS_OFFSET 0x04
1160143fc13bSJean-Jacques Hiblot
1161143fc13bSJean-Jacques Hiblot #define XHCI_MAX_EXT_CAPS 50
1162143fc13bSJean-Jacques Hiblot
1163143fc13bSJean-Jacques Hiblot /* Capability Register */
1164143fc13bSJean-Jacques Hiblot /* bits 7:0 - how long is the Capabilities register */
1165143fc13bSJean-Jacques Hiblot #define XHCI_HC_LENGTH(p) (((p) >> 00) & 0x00ff)
1166143fc13bSJean-Jacques Hiblot
1167143fc13bSJean-Jacques Hiblot /* Extended capability register fields */
1168143fc13bSJean-Jacques Hiblot #define XHCI_EXT_CAPS_ID(p) (((p) >> 0) & 0xff)
1169143fc13bSJean-Jacques Hiblot #define XHCI_EXT_CAPS_NEXT(p) (((p) >> 8) & 0xff)
1170143fc13bSJean-Jacques Hiblot #define XHCI_EXT_CAPS_VAL(p) ((p) >> 16)
1171143fc13bSJean-Jacques Hiblot /* Extended capability IDs - ID 0 reserved */
1172143fc13bSJean-Jacques Hiblot #define XHCI_EXT_CAPS_LEGACY 1
1173143fc13bSJean-Jacques Hiblot #define XHCI_EXT_CAPS_PROTOCOL 2
1174143fc13bSJean-Jacques Hiblot #define XHCI_EXT_CAPS_PM 3
1175143fc13bSJean-Jacques Hiblot #define XHCI_EXT_CAPS_VIRT 4
1176143fc13bSJean-Jacques Hiblot #define XHCI_EXT_CAPS_ROUTE 5
1177143fc13bSJean-Jacques Hiblot /* IDs 6-9 reserved */
1178143fc13bSJean-Jacques Hiblot #define XHCI_EXT_CAPS_DEBUG 10
1179143fc13bSJean-Jacques Hiblot /* USB Legacy Support Capability - section 7.1.1 */
1180143fc13bSJean-Jacques Hiblot #define XHCI_HC_BIOS_OWNED (1 << 16)
1181143fc13bSJean-Jacques Hiblot #define XHCI_HC_OS_OWNED (1 << 24)
1182143fc13bSJean-Jacques Hiblot
1183143fc13bSJean-Jacques Hiblot /* USB Legacy Support Capability - section 7.1.1 */
1184143fc13bSJean-Jacques Hiblot /* Add this offset, plus the value of xECP in HCCPARAMS to the base address */
1185143fc13bSJean-Jacques Hiblot #define XHCI_LEGACY_SUPPORT_OFFSET (0x00)
1186143fc13bSJean-Jacques Hiblot
1187143fc13bSJean-Jacques Hiblot /* USB Legacy Support Control and Status Register - section 7.1.2 */
1188143fc13bSJean-Jacques Hiblot /* Add this offset, plus the value of xECP in HCCPARAMS to the base address */
1189143fc13bSJean-Jacques Hiblot #define XHCI_LEGACY_CONTROL_OFFSET (0x04)
1190143fc13bSJean-Jacques Hiblot /* bits 1:2, 5:12, and 17:19 need to be preserved; bits 21:28 should be zero */
1191143fc13bSJean-Jacques Hiblot #define XHCI_LEGACY_DISABLE_SMI ((0x3 << 1) + (0xff << 5) + (0x7 << 17))
1192143fc13bSJean-Jacques Hiblot
1193143fc13bSJean-Jacques Hiblot /* USB 2.0 xHCI 0.96 L1C capability - section 7.2.2.1.3.2 */
1194143fc13bSJean-Jacques Hiblot #define XHCI_L1C (1 << 16)
1195143fc13bSJean-Jacques Hiblot
1196143fc13bSJean-Jacques Hiblot /* USB 2.0 xHCI 1.0 hardware LMP capability - section 7.2.2.1.3.2 */
1197143fc13bSJean-Jacques Hiblot #define XHCI_HLC (1 << 19)
1198143fc13bSJean-Jacques Hiblot
1199143fc13bSJean-Jacques Hiblot /* command register values to disable interrupts and halt the HC */
1200143fc13bSJean-Jacques Hiblot /* start/stop HC execution - do not write unless HC is halted*/
1201143fc13bSJean-Jacques Hiblot #define XHCI_CMD_RUN (1 << 0)
1202143fc13bSJean-Jacques Hiblot /* Event Interrupt Enable - get irq when EINT bit is set in USBSTS register */
1203143fc13bSJean-Jacques Hiblot #define XHCI_CMD_EIE (1 << 2)
1204143fc13bSJean-Jacques Hiblot /* Host System Error Interrupt Enable - get irq when HSEIE bit set in USBSTS */
1205143fc13bSJean-Jacques Hiblot #define XHCI_CMD_HSEIE (1 << 3)
1206143fc13bSJean-Jacques Hiblot /* Enable Wrap Event - '1' means xHC generates an event when MFINDEX wraps. */
1207143fc13bSJean-Jacques Hiblot #define XHCI_CMD_EWE (1 << 10)
1208143fc13bSJean-Jacques Hiblot
1209143fc13bSJean-Jacques Hiblot #define XHCI_IRQS (XHCI_CMD_EIE | XHCI_CMD_HSEIE | XHCI_CMD_EWE)
1210143fc13bSJean-Jacques Hiblot
1211143fc13bSJean-Jacques Hiblot /* true: Controller Not Ready to accept doorbell or op reg writes after reset */
1212143fc13bSJean-Jacques Hiblot #define XHCI_STS_CNR (1 << 11)
1213143fc13bSJean-Jacques Hiblot
1214143fc13bSJean-Jacques Hiblot struct xhci_ctrl {
1215143fc13bSJean-Jacques Hiblot #if CONFIG_IS_ENABLED(DM_USB)
1216143fc13bSJean-Jacques Hiblot struct udevice *dev;
1217143fc13bSJean-Jacques Hiblot #endif
1218143fc13bSJean-Jacques Hiblot struct xhci_hccr *hccr; /* R/O registers, not need for volatile */
1219143fc13bSJean-Jacques Hiblot struct xhci_hcor *hcor;
1220143fc13bSJean-Jacques Hiblot struct xhci_doorbell_array *dba;
1221143fc13bSJean-Jacques Hiblot struct xhci_run_regs *run_regs;
1222143fc13bSJean-Jacques Hiblot struct xhci_device_context_array *dcbaa \
1223143fc13bSJean-Jacques Hiblot __attribute__ ((aligned(ARCH_DMA_MINALIGN)));
1224143fc13bSJean-Jacques Hiblot struct xhci_ring *event_ring;
1225143fc13bSJean-Jacques Hiblot struct xhci_ring *cmd_ring;
1226143fc13bSJean-Jacques Hiblot struct xhci_ring *transfer_ring;
1227143fc13bSJean-Jacques Hiblot struct xhci_segment *seg;
1228143fc13bSJean-Jacques Hiblot struct xhci_intr_reg *ir_set;
1229143fc13bSJean-Jacques Hiblot struct xhci_erst erst;
1230143fc13bSJean-Jacques Hiblot struct xhci_erst_entry entry[ERST_NUM_SEGS];
1231143fc13bSJean-Jacques Hiblot struct xhci_scratchpad *scratchpad;
1232143fc13bSJean-Jacques Hiblot struct xhci_virt_device *devs[MAX_HC_SLOTS];
1233*ce2f4ca4SFrank Wang struct usb_hub_descriptor hub;
1234143fc13bSJean-Jacques Hiblot int rootdev;
1235143fc13bSJean-Jacques Hiblot };
1236143fc13bSJean-Jacques Hiblot
1237143fc13bSJean-Jacques Hiblot unsigned long trb_addr(struct xhci_segment *seg, union xhci_trb *trb);
1238143fc13bSJean-Jacques Hiblot struct xhci_input_control_ctx
1239143fc13bSJean-Jacques Hiblot *xhci_get_input_control_ctx(struct xhci_container_ctx *ctx);
1240143fc13bSJean-Jacques Hiblot struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_ctrl *ctrl,
1241143fc13bSJean-Jacques Hiblot struct xhci_container_ctx *ctx);
1242143fc13bSJean-Jacques Hiblot struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_ctrl *ctrl,
1243143fc13bSJean-Jacques Hiblot struct xhci_container_ctx *ctx,
1244143fc13bSJean-Jacques Hiblot unsigned int ep_index);
1245143fc13bSJean-Jacques Hiblot void xhci_endpoint_copy(struct xhci_ctrl *ctrl,
1246143fc13bSJean-Jacques Hiblot struct xhci_container_ctx *in_ctx,
1247143fc13bSJean-Jacques Hiblot struct xhci_container_ctx *out_ctx,
1248143fc13bSJean-Jacques Hiblot unsigned int ep_index);
1249143fc13bSJean-Jacques Hiblot void xhci_slot_copy(struct xhci_ctrl *ctrl,
1250143fc13bSJean-Jacques Hiblot struct xhci_container_ctx *in_ctx,
1251143fc13bSJean-Jacques Hiblot struct xhci_container_ctx *out_ctx);
1252143fc13bSJean-Jacques Hiblot void xhci_setup_addressable_virt_dev(struct xhci_ctrl *ctrl,
1253143fc13bSJean-Jacques Hiblot struct usb_device *udev, int hop_portnr);
1254143fc13bSJean-Jacques Hiblot void xhci_queue_command(struct xhci_ctrl *ctrl, u8 *ptr,
1255143fc13bSJean-Jacques Hiblot u32 slot_id, u32 ep_index, trb_type cmd);
1256143fc13bSJean-Jacques Hiblot void xhci_acknowledge_event(struct xhci_ctrl *ctrl);
1257143fc13bSJean-Jacques Hiblot union xhci_trb *xhci_wait_for_event(struct xhci_ctrl *ctrl, trb_type expected);
1258143fc13bSJean-Jacques Hiblot int xhci_bulk_tx(struct usb_device *udev, unsigned long pipe,
1259143fc13bSJean-Jacques Hiblot int length, void *buffer);
1260143fc13bSJean-Jacques Hiblot int xhci_ctrl_tx(struct usb_device *udev, unsigned long pipe,
1261143fc13bSJean-Jacques Hiblot struct devrequest *req, int length, void *buffer);
1262143fc13bSJean-Jacques Hiblot int xhci_check_maxpacket(struct usb_device *udev);
1263143fc13bSJean-Jacques Hiblot void xhci_flush_cache(uintptr_t addr, u32 type_len);
1264143fc13bSJean-Jacques Hiblot void xhci_inval_cache(uintptr_t addr, u32 type_len);
1265143fc13bSJean-Jacques Hiblot void xhci_cleanup(struct xhci_ctrl *ctrl);
1266143fc13bSJean-Jacques Hiblot struct xhci_ring *xhci_ring_alloc(unsigned int num_segs, bool link_trbs);
1267143fc13bSJean-Jacques Hiblot int xhci_alloc_virt_device(struct xhci_ctrl *ctrl, unsigned int slot_id);
1268143fc13bSJean-Jacques Hiblot int xhci_mem_init(struct xhci_ctrl *ctrl, struct xhci_hccr *hccr,
1269143fc13bSJean-Jacques Hiblot struct xhci_hcor *hcor);
1270143fc13bSJean-Jacques Hiblot
1271143fc13bSJean-Jacques Hiblot /**
1272143fc13bSJean-Jacques Hiblot * xhci_deregister() - Unregister an XHCI controller
1273143fc13bSJean-Jacques Hiblot *
1274143fc13bSJean-Jacques Hiblot * @dev: Controller device
1275143fc13bSJean-Jacques Hiblot * @return 0 if registered, -ve on error
1276143fc13bSJean-Jacques Hiblot */
1277143fc13bSJean-Jacques Hiblot int xhci_deregister(struct udevice *dev);
1278143fc13bSJean-Jacques Hiblot
1279143fc13bSJean-Jacques Hiblot /**
1280143fc13bSJean-Jacques Hiblot * xhci_register() - Register a new XHCI controller
1281143fc13bSJean-Jacques Hiblot *
1282143fc13bSJean-Jacques Hiblot * @dev: Controller device
1283143fc13bSJean-Jacques Hiblot * @hccr: Host controller control registers
1284143fc13bSJean-Jacques Hiblot * @hcor: Not sure what this means
1285143fc13bSJean-Jacques Hiblot * @return 0 if registered, -ve on error
1286143fc13bSJean-Jacques Hiblot */
1287143fc13bSJean-Jacques Hiblot int xhci_register(struct udevice *dev, struct xhci_hccr *hccr,
1288143fc13bSJean-Jacques Hiblot struct xhci_hcor *hcor);
1289143fc13bSJean-Jacques Hiblot
1290143fc13bSJean-Jacques Hiblot extern struct dm_usb_ops xhci_usb_ops;
1291143fc13bSJean-Jacques Hiblot
1292143fc13bSJean-Jacques Hiblot struct xhci_ctrl *xhci_get_ctrl(struct usb_device *udev);
1293143fc13bSJean-Jacques Hiblot
1294143fc13bSJean-Jacques Hiblot #endif /* HOST_XHCI_H_ */
1295