]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/usb/host/xhci.h
USB: Fix parsing of SuperSpeed Endpoint Companion descriptor.
[mirror_ubuntu-artful-kernel.git] / drivers / usb / host / xhci.h
CommitLineData
74c68741
SS
1/*
2 * xHCI host controller driver
3 *
4 * Copyright (C) 2008 Intel Corp.
5 *
6 * Author: Sarah Sharp
7 * Some code borrowed from the Linux EHCI driver.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#ifndef __LINUX_XHCI_HCD_H
24#define __LINUX_XHCI_HCD_H
25
26#include <linux/usb.h>
7f84eef0 27#include <linux/timer.h>
8e595a5d 28#include <linux/kernel.h>
74c68741
SS
29
30#include "../core/hcd.h"
31/* Code sharing between pci-quirks and xhci hcd */
32#include "xhci-ext-caps.h"
33
34/* xHCI PCI Configuration Registers */
35#define XHCI_SBRN_OFFSET (0x60)
36
66d4eadd
SS
37/* Max number of USB devices for any host controller - limit in section 6.1 */
38#define MAX_HC_SLOTS 256
0f2a7930
SS
39/* Section 5.3.3 - MaxPorts */
40#define MAX_HC_PORTS 127
66d4eadd 41
74c68741
SS
42/*
43 * xHCI register interface.
44 * This corresponds to the eXtensible Host Controller Interface (xHCI)
45 * Revision 0.95 specification
74c68741
SS
46 */
47
48/**
49 * struct xhci_cap_regs - xHCI Host Controller Capability Registers.
50 * @hc_capbase: length of the capabilities register and HC version number
51 * @hcs_params1: HCSPARAMS1 - Structural Parameters 1
52 * @hcs_params2: HCSPARAMS2 - Structural Parameters 2
53 * @hcs_params3: HCSPARAMS3 - Structural Parameters 3
54 * @hcc_params: HCCPARAMS - Capability Parameters
55 * @db_off: DBOFF - Doorbell array offset
56 * @run_regs_off: RTSOFF - Runtime register space offset
57 */
58struct xhci_cap_regs {
59 u32 hc_capbase;
60 u32 hcs_params1;
61 u32 hcs_params2;
62 u32 hcs_params3;
63 u32 hcc_params;
64 u32 db_off;
65 u32 run_regs_off;
66 /* Reserved up to (CAPLENGTH - 0x1C) */
98441973 67};
74c68741
SS
68
69/* hc_capbase bitmasks */
70/* bits 7:0 - how long is the Capabilities register */
71#define HC_LENGTH(p) XHCI_HC_LENGTH(p)
72/* bits 31:16 */
73#define HC_VERSION(p) (((p) >> 16) & 0xffff)
74
75/* HCSPARAMS1 - hcs_params1 - bitmasks */
76/* bits 0:7, Max Device Slots */
77#define HCS_MAX_SLOTS(p) (((p) >> 0) & 0xff)
78#define HCS_SLOTS_MASK 0xff
79/* bits 8:18, Max Interrupters */
80#define HCS_MAX_INTRS(p) (((p) >> 8) & 0x7ff)
81/* bits 24:31, Max Ports - max value is 0x7F = 127 ports */
82#define HCS_MAX_PORTS(p) (((p) >> 24) & 0x7f)
83
84/* HCSPARAMS2 - hcs_params2 - bitmasks */
85/* bits 0:3, frames or uframes that SW needs to queue transactions
86 * ahead of the HW to meet periodic deadlines */
87#define HCS_IST(p) (((p) >> 0) & 0xf)
88/* bits 4:7, max number of Event Ring segments */
89#define HCS_ERST_MAX(p) (((p) >> 4) & 0xf)
90/* bit 26 Scratchpad restore - for save/restore HW state - not used yet */
91/* bits 27:31 number of Scratchpad buffers SW must allocate for the HW */
92
93/* HCSPARAMS3 - hcs_params3 - bitmasks */
94/* bits 0:7, Max U1 to U0 latency for the roothub ports */
95#define HCS_U1_LATENCY(p) (((p) >> 0) & 0xff)
96/* bits 16:31, Max U2 to U0 latency for the roothub ports */
97#define HCS_U2_LATENCY(p) (((p) >> 16) & 0xffff)
98
99/* HCCPARAMS - hcc_params - bitmasks */
100/* true: HC can use 64-bit address pointers */
101#define HCC_64BIT_ADDR(p) ((p) & (1 << 0))
102/* true: HC can do bandwidth negotiation */
103#define HCC_BANDWIDTH_NEG(p) ((p) & (1 << 1))
104/* true: HC uses 64-byte Device Context structures
105 * FIXME 64-byte context structures aren't supported yet.
106 */
107#define HCC_64BYTE_CONTEXT(p) ((p) & (1 << 2))
108/* true: HC has port power switches */
109#define HCC_PPC(p) ((p) & (1 << 3))
110/* true: HC has port indicators */
111#define HCS_INDICATOR(p) ((p) & (1 << 4))
112/* true: HC has Light HC Reset Capability */
113#define HCC_LIGHT_RESET(p) ((p) & (1 << 5))
114/* true: HC supports latency tolerance messaging */
115#define HCC_LTC(p) ((p) & (1 << 6))
116/* true: no secondary Stream ID Support */
117#define HCC_NSS(p) ((p) & (1 << 7))
118/* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15 */
119#define HCC_MAX_PSA (1 << ((((p) >> 12) & 0xf) + 1))
120/* Extended Capabilities pointer from PCI base - section 5.3.6 */
121#define HCC_EXT_CAPS(p) XHCI_HCC_EXT_CAPS(p)
122
123/* db_off bitmask - bits 0:1 reserved */
124#define DBOFF_MASK (~0x3)
125
126/* run_regs_off bitmask - bits 0:4 reserved */
127#define RTSOFF_MASK (~0x1f)
128
129
130/* Number of registers per port */
131#define NUM_PORT_REGS 4
132
133/**
134 * struct xhci_op_regs - xHCI Host Controller Operational Registers.
135 * @command: USBCMD - xHC command register
136 * @status: USBSTS - xHC status register
137 * @page_size: This indicates the page size that the host controller
138 * supports. If bit n is set, the HC supports a page size
139 * of 2^(n+12), up to a 128MB page size.
140 * 4K is the minimum page size.
141 * @cmd_ring: CRP - 64-bit Command Ring Pointer
142 * @dcbaa_ptr: DCBAAP - 64-bit Device Context Base Address Array Pointer
143 * @config_reg: CONFIG - Configure Register
144 * @port_status_base: PORTSCn - base address for Port Status and Control
145 * Each port has a Port Status and Control register,
146 * followed by a Port Power Management Status and Control
147 * register, a Port Link Info register, and a reserved
148 * register.
149 * @port_power_base: PORTPMSCn - base address for
150 * Port Power Management Status and Control
151 * @port_link_base: PORTLIn - base address for Port Link Info (current
152 * Link PM state and control) for USB 2.1 and USB 3.0
153 * devices.
154 */
155struct xhci_op_regs {
156 u32 command;
157 u32 status;
158 u32 page_size;
159 u32 reserved1;
160 u32 reserved2;
161 u32 dev_notification;
8e595a5d 162 u64 cmd_ring;
74c68741
SS
163 /* rsvd: offset 0x20-2F */
164 u32 reserved3[4];
8e595a5d 165 u64 dcbaa_ptr;
74c68741
SS
166 u32 config_reg;
167 /* rsvd: offset 0x3C-3FF */
168 u32 reserved4[241];
169 /* port 1 registers, which serve as a base address for other ports */
170 u32 port_status_base;
171 u32 port_power_base;
172 u32 port_link_base;
173 u32 reserved5;
174 /* registers for ports 2-255 */
175 u32 reserved6[NUM_PORT_REGS*254];
98441973 176};
74c68741
SS
177
178/* USBCMD - USB command - command bitmasks */
179/* start/stop HC execution - do not write unless HC is halted*/
180#define CMD_RUN XHCI_CMD_RUN
181/* Reset HC - resets internal HC state machine and all registers (except
182 * PCI config regs). HC does NOT drive a USB reset on the downstream ports.
183 * The xHCI driver must reinitialize the xHC after setting this bit.
184 */
185#define CMD_RESET (1 << 1)
186/* Event Interrupt Enable - a '1' allows interrupts from the host controller */
187#define CMD_EIE XHCI_CMD_EIE
188/* Host System Error Interrupt Enable - get out-of-band signal for HC errors */
189#define CMD_HSEIE XHCI_CMD_HSEIE
190/* bits 4:6 are reserved (and should be preserved on writes). */
191/* light reset (port status stays unchanged) - reset completed when this is 0 */
192#define CMD_LRESET (1 << 7)
193/* FIXME: ignoring host controller save/restore state for now. */
194#define CMD_CSS (1 << 8)
195#define CMD_CRS (1 << 9)
196/* Enable Wrap Event - '1' means xHC generates an event when MFINDEX wraps. */
197#define CMD_EWE XHCI_CMD_EWE
198/* MFINDEX power management - '1' means xHC can stop MFINDEX counter if all root
199 * hubs are in U3 (selective suspend), disconnect, disabled, or powered-off.
200 * '0' means the xHC can power it off if all ports are in the disconnect,
201 * disabled, or powered-off state.
202 */
203#define CMD_PM_INDEX (1 << 11)
204/* bits 12:31 are reserved (and should be preserved on writes). */
205
206/* USBSTS - USB status - status bitmasks */
207/* HC not running - set to 1 when run/stop bit is cleared. */
208#define STS_HALT XHCI_STS_HALT
209/* serious error, e.g. PCI parity error. The HC will clear the run/stop bit. */
210#define STS_FATAL (1 << 2)
211/* event interrupt - clear this prior to clearing any IP flags in IR set*/
212#define STS_EINT (1 << 3)
213/* port change detect */
214#define STS_PORT (1 << 4)
215/* bits 5:7 reserved and zeroed */
216/* save state status - '1' means xHC is saving state */
217#define STS_SAVE (1 << 8)
218/* restore state status - '1' means xHC is restoring state */
219#define STS_RESTORE (1 << 9)
220/* true: save or restore error */
221#define STS_SRE (1 << 10)
222/* true: Controller Not Ready to accept doorbell or op reg writes after reset */
223#define STS_CNR XHCI_STS_CNR
224/* true: internal Host Controller Error - SW needs to reset and reinitialize */
225#define STS_HCE (1 << 12)
226/* bits 13:31 reserved and should be preserved */
227
228/*
229 * DNCTRL - Device Notification Control Register - dev_notification bitmasks
230 * Generate a device notification event when the HC sees a transaction with a
231 * notification type that matches a bit set in this bit field.
232 */
233#define DEV_NOTE_MASK (0xffff)
234#define ENABLE_DEV_NOTE(x) (1 << x)
235/* Most of the device notification types should only be used for debug.
236 * SW does need to pay attention to function wake notifications.
237 */
238#define DEV_NOTE_FWAKE ENABLE_DEV_NOTE(1)
239
0ebbab37
SS
240/* CRCR - Command Ring Control Register - cmd_ring bitmasks */
241/* bit 0 is the command ring cycle state */
242/* stop ring operation after completion of the currently executing command */
243#define CMD_RING_PAUSE (1 << 1)
244/* stop ring immediately - abort the currently executing command */
245#define CMD_RING_ABORT (1 << 2)
246/* true: command ring is running */
247#define CMD_RING_RUNNING (1 << 3)
248/* bits 4:5 reserved and should be preserved */
249/* Command Ring pointer - bit mask for the lower 32 bits. */
8e595a5d 250#define CMD_RING_RSVD_BITS (0x3f)
0ebbab37 251
74c68741
SS
252/* CONFIG - Configure Register - config_reg bitmasks */
253/* bits 0:7 - maximum number of device slots enabled (NumSlotsEn) */
254#define MAX_DEVS(p) ((p) & 0xff)
255/* bits 8:31 - reserved and should be preserved */
256
257/* PORTSC - Port Status and Control Register - port_status_base bitmasks */
258/* true: device connected */
259#define PORT_CONNECT (1 << 0)
260/* true: port enabled */
261#define PORT_PE (1 << 1)
262/* bit 2 reserved and zeroed */
263/* true: port has an over-current condition */
264#define PORT_OC (1 << 3)
265/* true: port reset signaling asserted */
266#define PORT_RESET (1 << 4)
267/* Port Link State - bits 5:8
268 * A read gives the current link PM state of the port,
269 * a write with Link State Write Strobe set sets the link state.
270 */
271/* true: port has power (see HCC_PPC) */
272#define PORT_POWER (1 << 9)
273/* bits 10:13 indicate device speed:
274 * 0 - undefined speed - port hasn't be initialized by a reset yet
275 * 1 - full speed
276 * 2 - low speed
277 * 3 - high speed
278 * 4 - super speed
279 * 5-15 reserved
280 */
3ffbba95
SS
281#define DEV_SPEED_MASK (0xf << 10)
282#define XDEV_FS (0x1 << 10)
283#define XDEV_LS (0x2 << 10)
284#define XDEV_HS (0x3 << 10)
285#define XDEV_SS (0x4 << 10)
74c68741 286#define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10))
3ffbba95
SS
287#define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS)
288#define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS)
289#define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS)
290#define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS)
291/* Bits 20:23 in the Slot Context are the speed for the device */
292#define SLOT_SPEED_FS (XDEV_FS << 10)
293#define SLOT_SPEED_LS (XDEV_LS << 10)
294#define SLOT_SPEED_HS (XDEV_HS << 10)
295#define SLOT_SPEED_SS (XDEV_SS << 10)
74c68741
SS
296/* Port Indicator Control */
297#define PORT_LED_OFF (0 << 14)
298#define PORT_LED_AMBER (1 << 14)
299#define PORT_LED_GREEN (2 << 14)
300#define PORT_LED_MASK (3 << 14)
301/* Port Link State Write Strobe - set this when changing link state */
302#define PORT_LINK_STROBE (1 << 16)
303/* true: connect status change */
304#define PORT_CSC (1 << 17)
305/* true: port enable change */
306#define PORT_PEC (1 << 18)
307/* true: warm reset for a USB 3.0 device is done. A "hot" reset puts the port
308 * into an enabled state, and the device into the default state. A "warm" reset
309 * also resets the link, forcing the device through the link training sequence.
310 * SW can also look at the Port Reset register to see when warm reset is done.
311 */
312#define PORT_WRC (1 << 19)
313/* true: over-current change */
314#define PORT_OCC (1 << 20)
315/* true: reset change - 1 to 0 transition of PORT_RESET */
316#define PORT_RC (1 << 21)
317/* port link status change - set on some port link state transitions:
318 * Transition Reason
319 * ------------------------------------------------------------------------------
320 * - U3 to Resume Wakeup signaling from a device
321 * - Resume to Recovery to U0 USB 3.0 device resume
322 * - Resume to U0 USB 2.0 device resume
323 * - U3 to Recovery to U0 Software resume of USB 3.0 device complete
324 * - U3 to U0 Software resume of USB 2.0 device complete
325 * - U2 to U0 L1 resume of USB 2.1 device complete
326 * - U0 to U0 (???) L1 entry rejection by USB 2.1 device
327 * - U0 to disabled L1 entry error with USB 2.1 device
328 * - Any state to inactive Error on USB 3.0 port
329 */
330#define PORT_PLC (1 << 22)
331/* port configure error change - port failed to configure its link partner */
332#define PORT_CEC (1 << 23)
333/* bit 24 reserved */
334/* wake on connect (enable) */
335#define PORT_WKCONN_E (1 << 25)
336/* wake on disconnect (enable) */
337#define PORT_WKDISC_E (1 << 26)
338/* wake on over-current (enable) */
339#define PORT_WKOC_E (1 << 27)
340/* bits 28:29 reserved */
341/* true: device is removable - for USB 3.0 roothub emulation */
342#define PORT_DEV_REMOVE (1 << 30)
343/* Initiate a warm port reset - complete when PORT_WRC is '1' */
344#define PORT_WR (1 << 31)
345
346/* Port Power Management Status and Control - port_power_base bitmasks */
347/* Inactivity timer value for transitions into U1, in microseconds.
348 * Timeout can be up to 127us. 0xFF means an infinite timeout.
349 */
350#define PORT_U1_TIMEOUT(p) ((p) & 0xff)
351/* Inactivity timer value for transitions into U2 */
352#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
353/* Bits 24:31 for port testing */
354
355
356/**
98441973 357 * struct xhci_intr_reg - Interrupt Register Set
74c68741
SS
358 * @irq_pending: IMAN - Interrupt Management Register. Used to enable
359 * interrupts and check for pending interrupts.
360 * @irq_control: IMOD - Interrupt Moderation Register.
361 * Used to throttle interrupts.
362 * @erst_size: Number of segments in the Event Ring Segment Table (ERST).
363 * @erst_base: ERST base address.
364 * @erst_dequeue: Event ring dequeue pointer.
365 *
366 * Each interrupter (defined by a MSI-X vector) has an event ring and an Event
367 * Ring Segment Table (ERST) associated with it. The event ring is comprised of
368 * multiple segments of the same size. The HC places events on the ring and
369 * "updates the Cycle bit in the TRBs to indicate to software the current
370 * position of the Enqueue Pointer." The HCD (Linux) processes those events and
371 * updates the dequeue pointer.
372 */
98441973 373struct xhci_intr_reg {
74c68741
SS
374 u32 irq_pending;
375 u32 irq_control;
376 u32 erst_size;
377 u32 rsvd;
8e595a5d
SS
378 u64 erst_base;
379 u64 erst_dequeue;
98441973 380};
74c68741 381
66d4eadd 382/* irq_pending bitmasks */
74c68741 383#define ER_IRQ_PENDING(p) ((p) & 0x1)
66d4eadd 384/* bits 2:31 need to be preserved */
7f84eef0 385/* THIS IS BUGGY - FIXME - IP IS WRITE 1 TO CLEAR */
66d4eadd
SS
386#define ER_IRQ_CLEAR(p) ((p) & 0xfffffffe)
387#define ER_IRQ_ENABLE(p) ((ER_IRQ_CLEAR(p)) | 0x2)
388#define ER_IRQ_DISABLE(p) ((ER_IRQ_CLEAR(p)) & ~(0x2))
389
390/* irq_control bitmasks */
391/* Minimum interval between interrupts (in 250ns intervals). The interval
392 * between interrupts will be longer if there are no events on the event ring.
393 * Default is 4000 (1 ms).
394 */
395#define ER_IRQ_INTERVAL_MASK (0xffff)
396/* Counter used to count down the time to the next interrupt - HW use only */
397#define ER_IRQ_COUNTER_MASK (0xffff << 16)
398
399/* erst_size bitmasks */
74c68741 400/* Preserve bits 16:31 of erst_size */
66d4eadd
SS
401#define ERST_SIZE_MASK (0xffff << 16)
402
403/* erst_dequeue bitmasks */
404/* Dequeue ERST Segment Index (DESI) - Segment number (or alias)
405 * where the current dequeue pointer lies. This is an optional HW hint.
406 */
407#define ERST_DESI_MASK (0x7)
408/* Event Handler Busy (EHB) - is the event ring scheduled to be serviced by
409 * a work queue (or delayed service routine)?
410 */
411#define ERST_EHB (1 << 3)
0ebbab37 412#define ERST_PTR_MASK (0xf)
74c68741
SS
413
414/**
415 * struct xhci_run_regs
416 * @microframe_index:
417 * MFINDEX - current microframe number
418 *
419 * Section 5.5 Host Controller Runtime Registers:
420 * "Software should read and write these registers using only Dword (32 bit)
421 * or larger accesses"
422 */
423struct xhci_run_regs {
98441973
SS
424 u32 microframe_index;
425 u32 rsvd[7];
426 struct xhci_intr_reg ir_set[128];
427};
74c68741 428
0ebbab37
SS
429/**
430 * struct doorbell_array
431 *
432 * Section 5.6
433 */
434struct xhci_doorbell_array {
435 u32 doorbell[256];
98441973 436};
0ebbab37
SS
437
438#define DB_TARGET_MASK 0xFFFFFF00
439#define DB_STREAM_ID_MASK 0x0000FFFF
440#define DB_TARGET_HOST 0x0
441#define DB_STREAM_ID_HOST 0x0
442#define DB_MASK (0xff << 8)
443
d0e96f5a
SS
444/* Endpoint Target - bits 0:7 */
445#define EPI_TO_DB(p) (((p) + 1) & 0xff)
446
0ebbab37 447
a74588f9
SS
448/**
449 * struct xhci_slot_ctx
450 * @dev_info: Route string, device speed, hub info, and last valid endpoint
451 * @dev_info2: Max exit latency for device number, root hub port number
452 * @tt_info: tt_info is used to construct split transaction tokens
453 * @dev_state: slot state and device address
454 *
455 * Slot Context - section 6.2.1.1. This assumes the HC uses 32-byte context
456 * structures. If the HC uses 64-byte contexts, there is an additional 32 bytes
457 * reserved at the end of the slot context for HC internal use.
458 */
459struct xhci_slot_ctx {
460 u32 dev_info;
461 u32 dev_info2;
462 u32 tt_info;
463 u32 dev_state;
464 /* offset 0x10 to 0x1f reserved for HC internal use */
465 u32 reserved[4];
98441973 466};
a74588f9
SS
467
468/* dev_info bitmasks */
469/* Route String - 0:19 */
470#define ROUTE_STRING_MASK (0xfffff)
471/* Device speed - values defined by PORTSC Device Speed field - 20:23 */
472#define DEV_SPEED (0xf << 20)
473/* bit 24 reserved */
474/* Is this LS/FS device connected through a HS hub? - bit 25 */
475#define DEV_MTT (0x1 << 25)
476/* Set if the device is a hub - bit 26 */
477#define DEV_HUB (0x1 << 26)
478/* Index of the last valid endpoint context in this device context - 27:31 */
3ffbba95
SS
479#define LAST_CTX_MASK (0x1f << 27)
480#define LAST_CTX(p) ((p) << 27)
481#define LAST_CTX_TO_EP_NUM(p) (((p) >> 27) - 1)
3ffbba95
SS
482#define SLOT_FLAG (1 << 0)
483#define EP0_FLAG (1 << 1)
a74588f9
SS
484
485/* dev_info2 bitmasks */
486/* Max Exit Latency (ms) - worst case time to wake up all links in dev path */
487#define MAX_EXIT (0xffff)
488/* Root hub port number that is needed to access the USB device */
3ffbba95 489#define ROOT_HUB_PORT(p) (((p) & 0xff) << 16)
a74588f9
SS
490
491/* tt_info bitmasks */
492/*
493 * TT Hub Slot ID - for low or full speed devices attached to a high-speed hub
494 * The Slot ID of the hub that isolates the high speed signaling from
495 * this low or full-speed device. '0' if attached to root hub port.
496 */
497#define TT_SLOT (0xff)
498/*
499 * The number of the downstream facing port of the high-speed hub
500 * '0' if the device is not low or full speed.
501 */
502#define TT_PORT (0xff << 8)
503
504/* dev_state bitmasks */
505/* USB device address - assigned by the HC */
3ffbba95 506#define DEV_ADDR_MASK (0xff)
a74588f9
SS
507/* bits 8:26 reserved */
508/* Slot state */
509#define SLOT_STATE (0x1f << 27)
ae636747 510#define GET_SLOT_STATE(p) (((p) & (0x1f << 27)) >> 27)
a74588f9
SS
511
512
513/**
514 * struct xhci_ep_ctx
515 * @ep_info: endpoint state, streams, mult, and interval information.
516 * @ep_info2: information on endpoint type, max packet size, max burst size,
517 * error count, and whether the HC will force an event for all
518 * transactions.
3ffbba95
SS
519 * @deq: 64-bit ring dequeue pointer address. If the endpoint only
520 * defines one stream, this points to the endpoint transfer ring.
521 * Otherwise, it points to a stream context array, which has a
522 * ring pointer for each flow.
523 * @tx_info:
524 * Average TRB lengths for the endpoint ring and
525 * max payload within an Endpoint Service Interval Time (ESIT).
a74588f9
SS
526 *
527 * Endpoint Context - section 6.2.1.2. This assumes the HC uses 32-byte context
528 * structures. If the HC uses 64-byte contexts, there is an additional 32 bytes
529 * reserved at the end of the endpoint context for HC internal use.
530 */
531struct xhci_ep_ctx {
532 u32 ep_info;
533 u32 ep_info2;
8e595a5d 534 u64 deq;
3ffbba95 535 u32 tx_info;
a74588f9 536 /* offset 0x14 - 0x1f reserved for HC internal use */
3ffbba95 537 u32 reserved[3];
98441973 538};
a74588f9
SS
539
540/* ep_info bitmasks */
541/*
542 * Endpoint State - bits 0:2
543 * 0 - disabled
544 * 1 - running
545 * 2 - halted due to halt condition - ok to manipulate endpoint ring
546 * 3 - stopped
547 * 4 - TRB error
548 * 5-7 - reserved
549 */
d0e96f5a
SS
550#define EP_STATE_MASK (0xf)
551#define EP_STATE_DISABLED 0
552#define EP_STATE_RUNNING 1
553#define EP_STATE_HALTED 2
554#define EP_STATE_STOPPED 3
555#define EP_STATE_ERROR 4
a74588f9
SS
556/* Mult - Max number of burtst within an interval, in EP companion desc. */
557#define EP_MULT(p) ((p & 0x3) << 8)
558/* bits 10:14 are Max Primary Streams */
559/* bit 15 is Linear Stream Array */
560/* Interval - period between requests to an endpoint - 125u increments. */
f94e0186 561#define EP_INTERVAL(p) ((p & 0xff) << 16)
a74588f9
SS
562
563/* ep_info2 bitmasks */
564/*
565 * Force Event - generate transfer events for all TRBs for this endpoint
566 * This will tell the HC to ignore the IOC and ISP flags (for debugging only).
567 */
568#define FORCE_EVENT (0x1)
569#define ERROR_COUNT(p) (((p) & 0x3) << 1)
570#define EP_TYPE(p) ((p) << 3)
571#define ISOC_OUT_EP 1
572#define BULK_OUT_EP 2
573#define INT_OUT_EP 3
574#define CTRL_EP 4
575#define ISOC_IN_EP 5
576#define BULK_IN_EP 6
577#define INT_IN_EP 7
578/* bit 6 reserved */
579/* bit 7 is Host Initiate Disable - for disabling stream selection */
580#define MAX_BURST(p) (((p)&0xff) << 8)
581#define MAX_PACKET(p) (((p)&0xffff) << 16)
582
583
584/**
585 * struct xhci_device_control
586 * Input/Output context; see section 6.2.5.
587 *
588 * @drop_context: set the bit of the endpoint context you want to disable
589 * @add_context: set the bit of the endpoint context you want to enable
590 */
591struct xhci_device_control {
592 u32 drop_flags;
593 u32 add_flags;
594 u32 rsvd[6];
595 struct xhci_slot_ctx slot;
596 struct xhci_ep_ctx ep[31];
98441973 597};
a74588f9
SS
598
599/* drop context bitmasks */
600#define DROP_EP(x) (0x1 << x)
601/* add context bitmasks */
602#define ADD_EP(x) (0x1 << x)
603
604
3ffbba95
SS
605struct xhci_virt_device {
606 /*
607 * Commands to the hardware are passed an "input context" that
608 * tells the hardware what to change in its data structures.
609 * The hardware will return changes in an "output context" that
610 * software must allocate for the hardware. We need to keep
611 * track of input and output contexts separately because
612 * these commands might fail and we don't trust the hardware.
613 */
614 struct xhci_device_control *out_ctx;
615 dma_addr_t out_ctx_dma;
616 /* Used for addressing devices and configuration changes */
617 struct xhci_device_control *in_ctx;
618 dma_addr_t in_ctx_dma;
619 /* FIXME when stream support is added */
620 struct xhci_ring *ep_rings[31];
f94e0186
SS
621 /* Temporary storage in case the configure endpoint command fails and we
622 * have to restore the device state to the previous state
623 */
624 struct xhci_ring *new_ep_rings[31];
625 struct completion cmd_completion;
3ffbba95
SS
626 /* Status of the last command issued for this device */
627 u32 cmd_status;
628};
629
630
a74588f9
SS
631/**
632 * struct xhci_device_context_array
633 * @dev_context_ptr array of 64-bit DMA addresses for device contexts
634 */
635struct xhci_device_context_array {
636 /* 64-bit device addresses; we only write 32-bit addresses */
8e595a5d 637 u64 dev_context_ptrs[MAX_HC_SLOTS];
a74588f9
SS
638 /* private xHCD pointers */
639 dma_addr_t dma;
98441973 640};
a74588f9
SS
641/* TODO: write function to set the 64-bit device DMA address */
642/*
643 * TODO: change this to be dynamically sized at HC mem init time since the HC
644 * might not be able to handle the maximum number of devices possible.
645 */
646
647
648struct xhci_stream_ctx {
649 /* 64-bit stream ring address, cycle state, and stream type */
8e595a5d 650 u64 stream_ring;
a74588f9
SS
651 /* offset 0x14 - 0x1f reserved for HC internal use */
652 u32 reserved[2];
98441973 653};
a74588f9
SS
654
655
0ebbab37
SS
656struct xhci_transfer_event {
657 /* 64-bit buffer address, or immediate data */
8e595a5d 658 u64 buffer;
0ebbab37
SS
659 u32 transfer_len;
660 /* This field is interpreted differently based on the type of TRB */
661 u32 flags;
98441973 662};
0ebbab37 663
d0e96f5a
SS
664/** Transfer Event bit fields **/
665#define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f)
666
0ebbab37
SS
667/* Completion Code - only applicable for some types of TRBs */
668#define COMP_CODE_MASK (0xff << 24)
669#define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24)
670#define COMP_SUCCESS 1
671/* Data Buffer Error */
672#define COMP_DB_ERR 2
673/* Babble Detected Error */
674#define COMP_BABBLE 3
675/* USB Transaction Error */
676#define COMP_TX_ERR 4
677/* TRB Error - some TRB field is invalid */
678#define COMP_TRB_ERR 5
679/* Stall Error - USB device is stalled */
680#define COMP_STALL 6
681/* Resource Error - HC doesn't have memory for that device configuration */
682#define COMP_ENOMEM 7
683/* Bandwidth Error - not enough room in schedule for this dev config */
684#define COMP_BW_ERR 8
685/* No Slots Available Error - HC ran out of device slots */
686#define COMP_ENOSLOTS 9
687/* Invalid Stream Type Error */
688#define COMP_STREAM_ERR 10
689/* Slot Not Enabled Error - doorbell rung for disabled device slot */
690#define COMP_EBADSLT 11
691/* Endpoint Not Enabled Error */
692#define COMP_EBADEP 12
693/* Short Packet */
694#define COMP_SHORT_TX 13
695/* Ring Underrun - doorbell rung for an empty isoc OUT ep ring */
696#define COMP_UNDERRUN 14
697/* Ring Overrun - isoc IN ep ring is empty when ep is scheduled to RX */
698#define COMP_OVERRUN 15
699/* Virtual Function Event Ring Full Error */
700#define COMP_VF_FULL 16
701/* Parameter Error - Context parameter is invalid */
702#define COMP_EINVAL 17
703/* Bandwidth Overrun Error - isoc ep exceeded its allocated bandwidth */
704#define COMP_BW_OVER 18
705/* Context State Error - illegal context state transition requested */
706#define COMP_CTX_STATE 19
707/* No Ping Response Error - HC didn't get PING_RESPONSE in time to TX */
708#define COMP_PING_ERR 20
709/* Event Ring is full */
710#define COMP_ER_FULL 21
711/* Missed Service Error - HC couldn't service an isoc ep within interval */
712#define COMP_MISSED_INT 23
713/* Successfully stopped command ring */
714#define COMP_CMD_STOP 24
715/* Successfully aborted current command and stopped command ring */
716#define COMP_CMD_ABORT 25
717/* Stopped - transfer was terminated by a stop endpoint command */
718#define COMP_STOP 26
719/* Same as COMP_EP_STOPPED, but the transfered length in the event is invalid */
720#define COMP_STOP_INVAL 27
721/* Control Abort Error - Debug Capability - control pipe aborted */
722#define COMP_DBG_ABORT 28
723/* TRB type 29 and 30 reserved */
724/* Isoc Buffer Overrun - an isoc IN ep sent more data than could fit in TD */
725#define COMP_BUFF_OVER 31
726/* Event Lost Error - xHC has an "internal event overrun condition" */
727#define COMP_ISSUES 32
728/* Undefined Error - reported when other error codes don't apply */
729#define COMP_UNKNOWN 33
730/* Invalid Stream ID Error */
731#define COMP_STRID_ERR 34
732/* Secondary Bandwidth Error - may be returned by a Configure Endpoint cmd */
733/* FIXME - check for this */
734#define COMP_2ND_BW_ERR 35
735/* Split Transaction Error */
736#define COMP_SPLIT_ERR 36
737
738struct xhci_link_trb {
739 /* 64-bit segment pointer*/
8e595a5d 740 u64 segment_ptr;
0ebbab37
SS
741 u32 intr_target;
742 u32 control;
98441973 743};
0ebbab37
SS
744
745/* control bitfields */
746#define LINK_TOGGLE (0x1<<1)
747
7f84eef0
SS
748/* Command completion event TRB */
749struct xhci_event_cmd {
750 /* Pointer to command TRB, or the value passed by the event data trb */
8e595a5d 751 u64 cmd_trb;
7f84eef0
SS
752 u32 status;
753 u32 flags;
98441973 754};
0ebbab37 755
3ffbba95
SS
756/* flags bitmasks */
757/* bits 16:23 are the virtual function ID */
758/* bits 24:31 are the slot ID */
759#define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24)
760#define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24)
0ebbab37 761
ae636747
SS
762/* Stop Endpoint TRB - ep_index to endpoint ID for this TRB */
763#define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1)
764#define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16)
765
766
0f2a7930
SS
767/* Port Status Change Event TRB fields */
768/* Port ID - bits 31:24 */
769#define GET_PORT_ID(p) (((p) & (0xff << 24)) >> 24)
770
0ebbab37
SS
771/* Normal TRB fields */
772/* transfer_len bitmasks - bits 0:16 */
773#define TRB_LEN(p) ((p) & 0x1ffff)
774/* TD size - number of bytes remaining in the TD (including this TRB):
775 * bits 17 - 21. Shift the number of bytes by 10. */
776#define TD_REMAINDER(p) ((((p) >> 10) & 0x1f) << 17)
777/* Interrupter Target - which MSI-X vector to target the completion event at */
778#define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
779#define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
780
781/* Cycle bit - indicates TRB ownership by HC or HCD */
782#define TRB_CYCLE (1<<0)
783/*
784 * Force next event data TRB to be evaluated before task switch.
785 * Used to pass OS data back after a TD completes.
786 */
787#define TRB_ENT (1<<1)
788/* Interrupt on short packet */
789#define TRB_ISP (1<<2)
790/* Set PCIe no snoop attribute */
791#define TRB_NO_SNOOP (1<<3)
792/* Chain multiple TRBs into a TD */
793#define TRB_CHAIN (1<<4)
794/* Interrupt on completion */
795#define TRB_IOC (1<<5)
796/* The buffer pointer contains immediate data */
797#define TRB_IDT (1<<6)
798
799
800/* Control transfer TRB specific fields */
801#define TRB_DIR_IN (1<<16)
802
7f84eef0
SS
803struct xhci_generic_trb {
804 u32 field[4];
98441973 805};
7f84eef0
SS
806
807union xhci_trb {
808 struct xhci_link_trb link;
809 struct xhci_transfer_event trans_event;
810 struct xhci_event_cmd event_cmd;
811 struct xhci_generic_trb generic;
812};
813
0ebbab37
SS
814/* TRB bit mask */
815#define TRB_TYPE_BITMASK (0xfc00)
816#define TRB_TYPE(p) ((p) << 10)
817/* TRB type IDs */
818/* bulk, interrupt, isoc scatter/gather, and control data stage */
819#define TRB_NORMAL 1
820/* setup stage for control transfers */
821#define TRB_SETUP 2
822/* data stage for control transfers */
823#define TRB_DATA 3
824/* status stage for control transfers */
825#define TRB_STATUS 4
826/* isoc transfers */
827#define TRB_ISOC 5
828/* TRB for linking ring segments */
829#define TRB_LINK 6
830#define TRB_EVENT_DATA 7
831/* Transfer Ring No-op (not for the command ring) */
832#define TRB_TR_NOOP 8
833/* Command TRBs */
834/* Enable Slot Command */
835#define TRB_ENABLE_SLOT 9
836/* Disable Slot Command */
837#define TRB_DISABLE_SLOT 10
838/* Address Device Command */
839#define TRB_ADDR_DEV 11
840/* Configure Endpoint Command */
841#define TRB_CONFIG_EP 12
842/* Evaluate Context Command */
843#define TRB_EVAL_CONTEXT 13
a1587d97
SS
844/* Reset Endpoint Command */
845#define TRB_RESET_EP 14
0ebbab37
SS
846/* Stop Transfer Ring Command */
847#define TRB_STOP_RING 15
848/* Set Transfer Ring Dequeue Pointer Command */
849#define TRB_SET_DEQ 16
850/* Reset Device Command */
851#define TRB_RESET_DEV 17
852/* Force Event Command (opt) */
853#define TRB_FORCE_EVENT 18
854/* Negotiate Bandwidth Command (opt) */
855#define TRB_NEG_BANDWIDTH 19
856/* Set Latency Tolerance Value Command (opt) */
857#define TRB_SET_LT 20
858/* Get port bandwidth Command */
859#define TRB_GET_BW 21
860/* Force Header Command - generate a transaction or link management packet */
861#define TRB_FORCE_HEADER 22
862/* No-op Command - not for transfer rings */
863#define TRB_CMD_NOOP 23
864/* TRB IDs 24-31 reserved */
865/* Event TRBS */
866/* Transfer Event */
867#define TRB_TRANSFER 32
868/* Command Completion Event */
869#define TRB_COMPLETION 33
870/* Port Status Change Event */
871#define TRB_PORT_STATUS 34
872/* Bandwidth Request Event (opt) */
873#define TRB_BANDWIDTH_EVENT 35
874/* Doorbell Event (opt) */
875#define TRB_DOORBELL 36
876/* Host Controller Event */
877#define TRB_HC_EVENT 37
878/* Device Notification Event - device sent function wake notification */
879#define TRB_DEV_NOTE 38
880/* MFINDEX Wrap Event - microframe counter wrapped */
881#define TRB_MFINDEX_WRAP 39
882/* TRB IDs 40-47 reserved, 48-63 is vendor-defined */
883
884/*
885 * TRBS_PER_SEGMENT must be a multiple of 4,
886 * since the command ring is 64-byte aligned.
887 * It must also be greater than 16.
888 */
889#define TRBS_PER_SEGMENT 64
890#define SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
b10de142
SS
891/* TRB buffer pointers can't cross 64KB boundaries */
892#define TRB_MAX_BUFF_SHIFT 16
893#define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT)
0ebbab37
SS
894
895struct xhci_segment {
896 union xhci_trb *trbs;
897 /* private to HCD */
898 struct xhci_segment *next;
899 dma_addr_t dma;
98441973 900};
0ebbab37 901
ae636747
SS
902struct xhci_td {
903 struct list_head td_list;
904 struct list_head cancelled_td_list;
905 struct urb *urb;
906 struct xhci_segment *start_seg;
907 union xhci_trb *first_trb;
908 union xhci_trb *last_trb;
909};
910
0ebbab37
SS
911struct xhci_ring {
912 struct xhci_segment *first_seg;
913 union xhci_trb *enqueue;
7f84eef0
SS
914 struct xhci_segment *enq_seg;
915 unsigned int enq_updates;
0ebbab37 916 union xhci_trb *dequeue;
7f84eef0
SS
917 struct xhci_segment *deq_seg;
918 unsigned int deq_updates;
d0e96f5a 919 struct list_head td_list;
ae636747
SS
920 /* ---- Related to URB cancellation ---- */
921 struct list_head cancelled_td_list;
922 unsigned int cancels_pending;
923 unsigned int state;
924#define SET_DEQ_PENDING (1 << 0)
a1587d97 925#define EP_HALTED (1 << 1)
ae636747
SS
926 /* The TRB that was last reported in a stopped endpoint ring */
927 union xhci_trb *stopped_trb;
928 struct xhci_td *stopped_td;
0ebbab37
SS
929 /*
930 * Write the cycle state into the TRB cycle field to give ownership of
931 * the TRB to the host controller (if we are the producer), or to check
932 * if we own the TRB (if we are the consumer). See section 4.9.1.
933 */
934 u32 cycle_state;
935};
936
937struct xhci_erst_entry {
938 /* 64-bit event ring segment address */
8e595a5d 939 u64 seg_addr;
0ebbab37
SS
940 u32 seg_size;
941 /* Set to zero */
942 u32 rsvd;
98441973 943};
0ebbab37
SS
944
945struct xhci_erst {
946 struct xhci_erst_entry *entries;
947 unsigned int num_entries;
948 /* xhci->event_ring keeps track of segment dma addresses */
949 dma_addr_t erst_dma_addr;
950 /* Num entries the ERST can contain */
951 unsigned int erst_size;
952};
953
954/*
955 * Each segment table entry is 4*32bits long. 1K seems like an ok size:
956 * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table,
957 * meaning 64 ring segments.
958 * Initial allocated size of the ERST, in number of entries */
959#define ERST_NUM_SEGS 1
960/* Initial allocated size of the ERST, in number of entries */
961#define ERST_SIZE 64
962/* Initial number of event segment rings allocated */
963#define ERST_ENTRIES 1
7f84eef0
SS
964/* Poll every 60 seconds */
965#define POLL_TIMEOUT 60
0ebbab37
SS
966/* XXX: Make these module parameters */
967
74c68741
SS
968
969/* There is one ehci_hci structure per controller */
970struct xhci_hcd {
971 /* glue to PCI and HCD framework */
972 struct xhci_cap_regs __iomem *cap_regs;
973 struct xhci_op_regs __iomem *op_regs;
974 struct xhci_run_regs __iomem *run_regs;
0ebbab37 975 struct xhci_doorbell_array __iomem *dba;
66d4eadd 976 /* Our HCD's current interrupter register set */
98441973 977 struct xhci_intr_reg __iomem *ir_set;
74c68741
SS
978
979 /* Cached register copies of read-only HC data */
980 __u32 hcs_params1;
981 __u32 hcs_params2;
982 __u32 hcs_params3;
983 __u32 hcc_params;
984
985 spinlock_t lock;
986
987 /* packed release number */
988 u8 sbrn;
989 u16 hci_version;
990 u8 max_slots;
991 u8 max_interrupters;
992 u8 max_ports;
993 u8 isoc_threshold;
994 int event_ring_max;
995 int addr_64;
66d4eadd 996 /* 4KB min, 128MB max */
74c68741 997 int page_size;
66d4eadd
SS
998 /* Valid values are 12 to 20, inclusive */
999 int page_shift;
1000 /* only one MSI vector for now, but might need more later */
1001 int msix_count;
1002 struct msix_entry *msix_entries;
0ebbab37 1003 /* data structures */
a74588f9 1004 struct xhci_device_context_array *dcbaa;
0ebbab37
SS
1005 struct xhci_ring *cmd_ring;
1006 struct xhci_ring *event_ring;
1007 struct xhci_erst erst;
3ffbba95
SS
1008 /* slot enabling and address device helpers */
1009 struct completion addr_dev;
1010 int slot_id;
1011 /* Internal mirror of the HW's dcbaa */
1012 struct xhci_virt_device *devs[MAX_HC_SLOTS];
0ebbab37
SS
1013
1014 /* DMA pools */
1015 struct dma_pool *device_pool;
1016 struct dma_pool *segment_pool;
7f84eef0
SS
1017
1018#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
1019 /* Poll the rings - for debugging */
1020 struct timer_list event_ring_timer;
1021 int zombie;
1022#endif
1023 /* Statistics */
1024 int noops_submitted;
1025 int noops_handled;
1026 int error_bitmask;
74c68741
SS
1027};
1028
7f84eef0
SS
1029/* For testing purposes */
1030#define NUM_TEST_NOOPS 0
1031
74c68741
SS
1032/* convert between an HCD pointer and the corresponding EHCI_HCD */
1033static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd)
1034{
1035 return (struct xhci_hcd *) (hcd->hcd_priv);
1036}
1037
1038static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
1039{
1040 return container_of((void *) xhci, struct usb_hcd, hcd_priv);
1041}
1042
1043#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
1044#define XHCI_DEBUG 1
1045#else
1046#define XHCI_DEBUG 0
1047#endif
1048
1049#define xhci_dbg(xhci, fmt, args...) \
1050 do { if (XHCI_DEBUG) dev_dbg(xhci_to_hcd(xhci)->self.controller , fmt , ## args); } while (0)
1051#define xhci_info(xhci, fmt, args...) \
1052 do { if (XHCI_DEBUG) dev_info(xhci_to_hcd(xhci)->self.controller , fmt , ## args); } while (0)
1053#define xhci_err(xhci, fmt, args...) \
1054 dev_err(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1055#define xhci_warn(xhci, fmt, args...) \
1056 dev_warn(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1057
1058/* TODO: copied from ehci.h - can be refactored? */
1059/* xHCI spec says all registers are little endian */
1060static inline unsigned int xhci_readl(const struct xhci_hcd *xhci,
1061 __u32 __iomem *regs)
1062{
1063 return readl(regs);
1064}
045f123d 1065static inline void xhci_writel(struct xhci_hcd *xhci,
74c68741
SS
1066 const unsigned int val, __u32 __iomem *regs)
1067{
66e49d87
SS
1068 xhci_dbg(xhci,
1069 "`MEM_WRITE_DWORD(3'b000, 32'h%p, 32'h%0x, 4'hf);\n",
1070 regs, val);
74c68741
SS
1071 writel(val, regs);
1072}
1073
8e595a5d
SS
1074/*
1075 * Registers should always be accessed with double word or quad word accesses.
1076 *
1077 * Some xHCI implementations may support 64-bit address pointers. Registers
1078 * with 64-bit address pointers should be written to with dword accesses by
1079 * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second.
1080 * xHCI implementations that do not support 64-bit address pointers will ignore
1081 * the high dword, and write order is irrelevant.
1082 */
1083static inline u64 xhci_read_64(const struct xhci_hcd *xhci,
1084 __u64 __iomem *regs)
1085{
1086 __u32 __iomem *ptr = (__u32 __iomem *) regs;
1087 u64 val_lo = readl(ptr);
1088 u64 val_hi = readl(ptr + 1);
1089 return val_lo + (val_hi << 32);
1090}
1091static inline void xhci_write_64(struct xhci_hcd *xhci,
1092 const u64 val, __u64 __iomem *regs)
1093{
1094 __u32 __iomem *ptr = (__u32 __iomem *) regs;
1095 u32 val_lo = lower_32_bits(val);
1096 u32 val_hi = upper_32_bits(val);
1097
66e49d87
SS
1098 xhci_dbg(xhci,
1099 "`MEM_WRITE_DWORD(3'b000, 64'h%p, 64'h%0lx, 4'hf);\n",
1100 regs, (long unsigned int) val);
8e595a5d
SS
1101 writel(val_lo, ptr);
1102 writel(val_hi, ptr + 1);
1103}
1104
66d4eadd 1105/* xHCI debugging */
98441973 1106void xhci_print_ir_set(struct xhci_hcd *xhci, struct xhci_intr_reg *ir_set, int set_num);
66d4eadd 1107void xhci_print_registers(struct xhci_hcd *xhci);
0ebbab37
SS
1108void xhci_dbg_regs(struct xhci_hcd *xhci);
1109void xhci_print_run_regs(struct xhci_hcd *xhci);
d0e96f5a
SS
1110void xhci_print_trb_offsets(struct xhci_hcd *xhci, union xhci_trb *trb);
1111void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb);
7f84eef0 1112void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg);
0ebbab37
SS
1113void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring);
1114void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
1115void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci);
7f84eef0 1116void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring);
3ffbba95 1117void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_device_control *ctx, dma_addr_t dma, unsigned int last_ep);
66d4eadd
SS
1118
1119/* xHCI memory managment */
1120void xhci_mem_cleanup(struct xhci_hcd *xhci);
1121int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags);
3ffbba95
SS
1122void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id);
1123int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device *udev, gfp_t flags);
1124int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev);
d0e96f5a 1125unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc);
f94e0186
SS
1126unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc);
1127void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep);
f88ba78d
SS
1128int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev,
1129 struct usb_device *udev, struct usb_host_endpoint *ep,
1130 gfp_t mem_flags);
f94e0186 1131void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring);
66d4eadd
SS
1132
1133#ifdef CONFIG_PCI
1134/* xHCI PCI glue */
1135int xhci_register_pci(void);
1136void xhci_unregister_pci(void);
1137#endif
1138
1139/* xHCI host controller glue */
1140int xhci_halt(struct xhci_hcd *xhci);
1141int xhci_reset(struct xhci_hcd *xhci);
1142int xhci_init(struct usb_hcd *hcd);
1143int xhci_run(struct usb_hcd *hcd);
1144void xhci_stop(struct usb_hcd *hcd);
1145void xhci_shutdown(struct usb_hcd *hcd);
1146int xhci_get_frame(struct usb_hcd *hcd);
7f84eef0 1147irqreturn_t xhci_irq(struct usb_hcd *hcd);
3ffbba95
SS
1148int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
1149void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
1150int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
d0e96f5a
SS
1151int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
1152int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
f94e0186
SS
1153int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
1154int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
a1587d97 1155void xhci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
f94e0186
SS
1156int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1157void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
7f84eef0
SS
1158
1159/* xHCI ring, segment, TRB, and TD functions */
23e3be11
SS
1160dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
1161void xhci_ring_cmd_db(struct xhci_hcd *xhci);
1162void *xhci_setup_one_noop(struct xhci_hcd *xhci);
b7258a4a 1163void xhci_handle_event(struct xhci_hcd *xhci);
23e3be11
SS
1164void xhci_set_hc_event_deq(struct xhci_hcd *xhci);
1165int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id);
1166int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1167 u32 slot_id);
1168int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
ae636747 1169 unsigned int ep_index);
23e3be11
SS
1170int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1171 int slot_id, unsigned int ep_index);
1172int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1173 int slot_id, unsigned int ep_index);
1174int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1175 u32 slot_id);
a1587d97
SS
1176int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
1177 unsigned int ep_index);
66d4eadd 1178
0f2a7930
SS
1179/* xHCI roothub code */
1180int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
1181 char *buf, u16 wLength);
1182int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);
1183
74c68741 1184#endif /* __LINUX_XHCI_HCD_H */