xhci: Add defines for hardcoded slot states
[linux-flexiantxendom0-natty.git] / drivers / usb / host / xhci.h
index 059c659..1d9943e 100644 (file)
@@ -25,8 +25,9 @@
 
 #include <linux/usb.h>
 #include <linux/timer.h>
+#include <linux/kernel.h>
+#include <linux/usb/hcd.h>
 
-#include "../core/hcd.h"
 /* Code sharing between pci-quirks and xhci hcd */
 #include       "xhci-ext-caps.h"
 
  * xHCI register interface.
  * This corresponds to the eXtensible Host Controller Interface (xHCI)
  * Revision 0.95 specification
- *
- * Registers should always be accessed with double word or quad word accesses.
- *
- * Some xHCI implementations may support 64-bit address pointers.  Registers
- * with 64-bit address pointers should be written to with dword accesses by
- * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second.
- * xHCI implementations that do not support 64-bit address pointers will ignore
- * the high dword, and write order is irrelevant.
  */
 
 /**
@@ -71,7 +64,7 @@ struct xhci_cap_regs {
        u32     db_off;
        u32     run_regs_off;
        /* Reserved up to (CAPLENGTH - 0x1C) */
-} __attribute__ ((packed));
+};
 
 /* hc_capbase bitmasks */
 /* bits 7:0 - how long is the Capabilities register */
@@ -96,6 +89,7 @@ struct xhci_cap_regs {
 #define HCS_ERST_MAX(p)                (((p) >> 4) & 0xf)
 /* bit 26 Scratchpad restore - for save/restore HW state - not used yet */
 /* bits 27:31 number of Scratchpad buffers SW must allocate for the HW */
+#define HCS_MAX_SCRATCHPAD(p)   (((p) >> 27) & 0x1f)
 
 /* HCSPARAMS3 - hcs_params3 - bitmasks */
 /* bits 0:7, Max U1 to U0 latency for the roothub ports */
@@ -123,7 +117,7 @@ struct xhci_cap_regs {
 /* true: no secondary Stream ID Support */
 #define HCC_NSS(p)             ((p) & (1 << 7))
 /* Max size for Primary Stream Arrays - 2^(n+1), where n is bits 12:15 */
-#define HCC_MAX_PSA            (1 << ((((p) >> 12) & 0xf) + 1))
+#define HCC_MAX_PSA(p)         (1 << ((((p) >> 12) & 0xf) + 1))
 /* Extended Capabilities pointer from PCI base - section 5.3.6 */
 #define HCC_EXT_CAPS(p)                XHCI_HCC_EXT_CAPS(p)
 
@@ -166,10 +160,10 @@ struct xhci_op_regs {
        u32     reserved1;
        u32     reserved2;
        u32     dev_notification;
-       u32     cmd_ring[2];
+       u64     cmd_ring;
        /* rsvd: offset 0x20-2F */
        u32     reserved3[4];
-       u32     dcbaa_ptr[2];
+       u64     dcbaa_ptr;
        u32     config_reg;
        /* rsvd: offset 0x3C-3FF */
        u32     reserved4[241];
@@ -180,7 +174,7 @@ struct xhci_op_regs {
        u32     reserved5;
        /* registers for ports 2-255 */
        u32     reserved6[NUM_PORT_REGS*254];
-} __attribute__ ((packed));
+};
 
 /* USBCMD - USB command - command bitmasks */
 /* start/stop HC execution - do not write unless HC is halted*/
@@ -197,7 +191,7 @@ struct xhci_op_regs {
 /* bits 4:6 are reserved (and should be preserved on writes). */
 /* light reset (port status stays unchanged) - reset completed when this is 0 */
 #define CMD_LRESET     (1 << 7)
-/* FIXME: ignoring host controller save/restore state for now. */
+/* host controller save/restore state. */
 #define CMD_CSS                (1 << 8)
 #define CMD_CRS                (1 << 9)
 /* Enable Wrap Event - '1' means xHC generates an event when MFINDEX wraps. */
@@ -254,7 +248,7 @@ struct xhci_op_regs {
 #define CMD_RING_RUNNING       (1 << 3)
 /* bits 4:5 reserved and should be preserved */
 /* Command Ring pointer - bit mask for the lower 32 bits. */
-#define CMD_RING_ADDR_MASK     (0xffffffc0)
+#define CMD_RING_RSVD_BITS     (0x3f)
 
 /* CONFIG - Configure Register - config_reg bitmasks */
 /* bits 0:7 - maximum number of device slots enabled (NumSlotsEn) */
@@ -275,6 +269,10 @@ struct xhci_op_regs {
  * A read gives the current link PM state of the port,
  * a write with Link State Write Strobe set sets the link state.
  */
+#define PORT_PLS_MASK  (0xf << 5)
+#define XDEV_U0                (0x0 << 5)
+#define XDEV_U3                (0x3 << 5)
+#define XDEV_RESUME    (0xf << 5)
 /* true: port has power (see HCC_PPC) */
 #define PORT_POWER     (1 << 9)
 /* bits 10:13 indicate device speed:
@@ -285,12 +283,21 @@ struct xhci_op_regs {
  * 4 - super speed
  * 5-15 reserved
  */
-#define DEV_SPEED_MASK         (0xf<<10)
+#define DEV_SPEED_MASK         (0xf << 10)
+#define        XDEV_FS                 (0x1 << 10)
+#define        XDEV_LS                 (0x2 << 10)
+#define        XDEV_HS                 (0x3 << 10)
+#define        XDEV_SS                 (0x4 << 10)
 #define DEV_UNDEFSPEED(p)      (((p) & DEV_SPEED_MASK) == (0x0<<10))
-#define DEV_FULLSPEED(p)       (((p) & DEV_SPEED_MASK) == (0x1<<10))
-#define DEV_LOWSPEED(p)                (((p) & DEV_SPEED_MASK) == (0x2<<10))
-#define DEV_HIGHSPEED(p)       (((p) & DEV_SPEED_MASK) == (0x3<<10))
-#define DEV_SUPERSPEED(p)      (((p) & DEV_SPEED_MASK) == (0x4<<10))
+#define DEV_FULLSPEED(p)       (((p) & DEV_SPEED_MASK) == XDEV_FS)
+#define DEV_LOWSPEED(p)                (((p) & DEV_SPEED_MASK) == XDEV_LS)
+#define DEV_HIGHSPEED(p)       (((p) & DEV_SPEED_MASK) == XDEV_HS)
+#define DEV_SUPERSPEED(p)      (((p) & DEV_SPEED_MASK) == XDEV_SS)
+/* Bits 20:23 in the Slot Context are the speed for the device */
+#define        SLOT_SPEED_FS           (XDEV_FS << 10)
+#define        SLOT_SPEED_LS           (XDEV_LS << 10)
+#define        SLOT_SPEED_HS           (XDEV_HS << 10)
+#define        SLOT_SPEED_SS           (XDEV_SS << 10)
 /* Port Indicator Control */
 #define PORT_LED_OFF   (0 << 14)
 #define PORT_LED_AMBER (1 << 14)
@@ -350,9 +357,11 @@ struct xhci_op_regs {
 #define PORT_U2_TIMEOUT(p)     (((p) & 0xff) << 8)
 /* Bits 24:31 for port testing */
 
+/* USB2 Protocol PORTSPMSC */
+#define PORT_RWE       (1 << 0x3)
 
 /**
- * struct intr_reg - Interrupt Register Set
+ * struct xhci_intr_reg - Interrupt Register Set
  * @irq_pending:       IMAN - Interrupt Management Register.  Used to enable
  *                     interrupts and check for pending interrupts.
  * @irq_control:       IMOD - Interrupt Moderation Register.
@@ -368,14 +377,14 @@ struct xhci_op_regs {
  * position of the Enqueue Pointer." The HCD (Linux) processes those events and
  * updates the dequeue pointer.
  */
-struct intr_reg {
+struct xhci_intr_reg {
        u32     irq_pending;
        u32     irq_control;
        u32     erst_size;
        u32     rsvd;
-       u32     erst_base[2];
-       u32     erst_dequeue[2];
-} __attribute__ ((packed));
+       u64     erst_base;
+       u64     erst_dequeue;
+};
 
 /* irq_pending bitmasks */
 #define        ER_IRQ_PENDING(p)       ((p) & 0x1)
@@ -419,26 +428,65 @@ struct intr_reg {
  * or larger accesses"
  */
 struct xhci_run_regs {
-       u32     microframe_index;
-       u32     rsvd[7];
-       struct intr_reg ir_set[128];
-} __attribute__ ((packed));
+       u32                     microframe_index;
+       u32                     rsvd[7];
+       struct xhci_intr_reg    ir_set[128];
+};
 
 /**
  * struct doorbell_array
  *
+ * Bits  0 -  7: Endpoint target
+ * Bits  8 - 15: RsvdZ
+ * Bits 16 - 31: Stream ID
+ *
  * Section 5.6
  */
 struct xhci_doorbell_array {
        u32     doorbell[256];
-} __attribute__ ((packed));
+};
 
-#define        DB_TARGET_MASK          0xFFFFFF00
-#define        DB_STREAM_ID_MASK       0x0000FFFF
-#define        DB_TARGET_HOST          0x0
-#define        DB_STREAM_ID_HOST       0x0
-#define        DB_MASK                 (0xff << 8)
+#define DB_VALUE(ep, stream)   ((((ep) + 1) & 0xff) | ((stream) << 16))
+#define DB_VALUE_HOST          0x00000000
 
+/**
+ * struct xhci_protocol_caps
+ * @revision:          major revision, minor revision, capability ID,
+ *                     and next capability pointer.
+ * @name_string:       Four ASCII characters to say which spec this xHC
+ *                     follows, typically "USB ".
+ * @port_info:         Port offset, count, and protocol-defined information.
+ */
+struct xhci_protocol_caps {
+       u32     revision;
+       u32     name_string;
+       u32     port_info;
+};
+
+#define        XHCI_EXT_PORT_MAJOR(x)  (((x) >> 24) & 0xff)
+#define        XHCI_EXT_PORT_OFF(x)    ((x) & 0xff)
+#define        XHCI_EXT_PORT_COUNT(x)  (((x) >> 8) & 0xff)
+
+/**
+ * struct xhci_container_ctx
+ * @type: Type of context.  Used to calculated offsets to contained contexts.
+ * @size: Size of the context data
+ * @bytes: The raw context data given to HW
+ * @dma: dma address of the bytes
+ *
+ * Represents either a Device or Input context.  Holds a pointer to the raw
+ * memory used for the context (bytes) and dma address of it (dma).
+ */
+struct xhci_container_ctx {
+       unsigned type;
+#define XHCI_CTX_TYPE_DEVICE  0x1
+#define XHCI_CTX_TYPE_INPUT   0x2
+
+       int size;
+
+       u8 *bytes;
+       dma_addr_t dma;
+};
 
 /**
  * struct xhci_slot_ctx
@@ -458,7 +506,7 @@ struct xhci_slot_ctx {
        u32     dev_state;
        /* offset 0x10 to 0x1f reserved for HC internal use */
        u32     reserved[4];
-} __attribute__ ((packed));
+};
 
 /* dev_info bitmasks */
 /* Route String - 0:19 */
@@ -471,14 +519,20 @@ struct xhci_slot_ctx {
 /* Set if the device is a hub - bit 26 */
 #define DEV_HUB                (0x1 << 26)
 /* Index of the last valid endpoint context in this device context - 27:31 */
-#define LAST_EP_MASK   (0x1f << 27)
-#define LAST_EP(p)     ((p) << 27)
+#define LAST_CTX_MASK  (0x1f << 27)
+#define LAST_CTX(p)    ((p) << 27)
+#define LAST_CTX_TO_EP_NUM(p)  (((p) >> 27) - 1)
+#define SLOT_FLAG      (1 << 0)
+#define EP0_FLAG       (1 << 1)
 
 /* dev_info2 bitmasks */
 /* Max Exit Latency (ms) - worst case time to wake up all links in dev path */
 #define MAX_EXIT       (0xffff)
 /* Root hub port number that is needed to access the USB device */
-#define ROOT_HUB_PORT  (0xff << 16)
+#define ROOT_HUB_PORT(p)       (((p) & 0xff) << 16)
+#define DEVINFO_TO_ROOT_HUB_PORT(p)    (((p) >> 16) & 0xff)
+/* Maximum number of ports under a hub device */
+#define XHCI_MAX_PORTS(p)      (((p) & 0xff) << 24)
 
 /* tt_info bitmasks */
 /*
@@ -492,14 +546,21 @@ struct xhci_slot_ctx {
  * '0' if the device is not low or full speed.
  */
 #define TT_PORT                (0xff << 8)
+#define TT_THINK_TIME(p)       (((p) & 0x3) << 16)
 
 /* dev_state bitmasks */
 /* USB device address - assigned by the HC */
-#define DEV_ADDR       (0xff)
+#define DEV_ADDR_MASK  (0xff)
 /* bits 8:26 reserved */
 /* Slot state */
 #define SLOT_STATE     (0x1f << 27)
+#define GET_SLOT_STATE(p)      (((p) & (0x1f << 27)) >> 27)
 
+#define SLOT_STATE_DISABLED    0
+#define SLOT_STATE_ENABLED     SLOT_STATE_DISABLED
+#define SLOT_STATE_DEFAULT     1
+#define SLOT_STATE_ADDRESSED   2
+#define SLOT_STATE_CONFIGURED  3
 
 /**
  * struct xhci_ep_ctx
@@ -507,12 +568,13 @@ struct xhci_slot_ctx {
  * @ep_info2:  information on endpoint type, max packet size, max burst size,
  *             error count, and whether the HC will force an event for all
  *             transactions.
- * @ep_ring:   64-bit ring address.  If the endpoint only defines one flow,
- *             this points to the endpoint transfer ring.  Otherwise, it points
- *             to a flow context array, which has a ring pointer for each flow.
- * @intr_target:
- *             64-bit address of the Interrupter Target that will receive
- *             events from this endpoint.
+ * @deq:       64-bit ring dequeue pointer address.  If the endpoint only
+ *             defines one stream, this points to the endpoint transfer ring.
+ *             Otherwise, it points to a stream context array, which has a
+ *             ring pointer for each flow.
+ * @tx_info:
+ *             Average TRB lengths for the endpoint ring and
+ *             max payload within an Endpoint Service Interval Time (ESIT).
  *
  * Endpoint Context - section 6.2.1.2.  This assumes the HC uses 32-byte context
  * structures.  If the HC uses 64-byte contexts, there is an additional 32 bytes
@@ -521,13 +583,11 @@ struct xhci_slot_ctx {
 struct xhci_ep_ctx {
        u32     ep_info;
        u32     ep_info2;
-       /* 64-bit endpoint ring address */
-       u32     ep_ring[2];
-       /* 64-bit address of the interrupter target */
-       u32     intr_target[2];
+       u64     deq;
+       u32     tx_info;
        /* offset 0x14 - 0x1f reserved for HC internal use */
-       u32     reserved[2];
-} __attribute__ ((packed));
+       u32     reserved[3];
+};
 
 /* ep_info bitmasks */
 /*
@@ -539,13 +599,23 @@ struct xhci_ep_ctx {
  * 4 - TRB error
  * 5-7 - reserved
  */
-#define EP_STATE       (0xf)
+#define EP_STATE_MASK          (0xf)
+#define EP_STATE_DISABLED      0
+#define EP_STATE_RUNNING       1
+#define EP_STATE_HALTED                2
+#define EP_STATE_STOPPED       3
+#define EP_STATE_ERROR         4
 /* Mult - Max number of burtst within an interval, in EP companion desc. */
 #define EP_MULT(p)             ((p & 0x3) << 8)
 /* bits 10:14 are Max Primary Streams */
 /* bit 15 is Linear Stream Array */
 /* Interval - period between requests to an endpoint - 125u increments. */
-#define EP_INTERVAL    (0xff << 16)
+#define EP_INTERVAL(p)         ((p & 0xff) << 16)
+#define EP_INTERVAL_TO_UFRAMES(p)              (1 << (((p) >> 16) & 0xff))
+#define EP_MAXPSTREAMS_MASK    (0x1f << 10)
+#define EP_MAXPSTREAMS(p)      (((p) << 10) & EP_MAXPSTREAMS_MASK)
+/* Endpoint is set up with a Linear Stream Array (vs. Secondary Stream Array) */
+#define        EP_HAS_LSA              (1 << 15)
 
 /* ep_info2 bitmasks */
 /*
@@ -554,6 +624,7 @@ struct xhci_ep_ctx {
  */
 #define        FORCE_EVENT     (0x1)
 #define ERROR_COUNT(p) (((p) & 0x3) << 1)
+#define CTX_TO_EP_TYPE(p)      (((p) >> 3) & 0x7)
 #define EP_TYPE(p)     ((p) << 3)
 #define ISOC_OUT_EP    1
 #define BULK_OUT_EP    2
@@ -566,28 +637,166 @@ struct xhci_ep_ctx {
 /* bit 7 is Host Initiate Disable - for disabling stream selection */
 #define MAX_BURST(p)   (((p)&0xff) << 8)
 #define MAX_PACKET(p)  (((p)&0xffff) << 16)
+#define MAX_PACKET_MASK                (0xffff << 16)
+#define MAX_PACKET_DECODED(p)  (((p) >> 16) & 0xffff)
+
+/* Get max packet size from ep desc. Bit 10..0 specify the max packet size.
+ * USB2.0 spec 9.6.6.
+ */
+#define GET_MAX_PACKET(p)      ((p) & 0x7ff)
+
+/* tx_info bitmasks */
+#define AVG_TRB_LENGTH_FOR_EP(p)       ((p) & 0xffff)
+#define MAX_ESIT_PAYLOAD_FOR_EP(p)     (((p) & 0xffff) << 16)
+
+/* deq bitmasks */
+#define EP_CTX_CYCLE_MASK              (1 << 0)
 
 
 /**
- * struct xhci_device_control
- * Input/Output context; see section 6.2.5.
+ * struct xhci_input_control_context
+ * Input control context; see section 6.2.5.
  *
  * @drop_context:      set the bit of the endpoint context you want to disable
  * @add_context:       set the bit of the endpoint context you want to enable
  */
-struct xhci_device_control {
+struct xhci_input_control_ctx {
        u32     drop_flags;
        u32     add_flags;
-       u32     rsvd[6];
-       struct xhci_slot_ctx    slot;
-       struct xhci_ep_ctx      ep[31];
-} __attribute__ ((packed));
+       u32     rsvd2[6];
+};
+
+/* Represents everything that is needed to issue a command on the command ring.
+ * It's useful to pre-allocate these for commands that cannot fail due to
+ * out-of-memory errors, like freeing streams.
+ */
+struct xhci_command {
+       /* Input context for changing device state */
+       struct xhci_container_ctx       *in_ctx;
+       u32                             status;
+       /* If completion is null, no one is waiting on this command
+        * and the structure can be freed after the command completes.
+        */
+       struct completion               *completion;
+       union xhci_trb                  *command_trb;
+       struct list_head                cmd_list;
+};
 
 /* drop context bitmasks */
 #define        DROP_EP(x)      (0x1 << x)
 /* add context bitmasks */
 #define        ADD_EP(x)       (0x1 << x)
 
+struct xhci_stream_ctx {
+       /* 64-bit stream ring address, cycle state, and stream type */
+       u64     stream_ring;
+       /* offset 0x14 - 0x1f reserved for HC internal use */
+       u32     reserved[2];
+};
+
+/* Stream Context Types (section 6.4.1) - bits 3:1 of stream ctx deq ptr */
+#define        SCT_FOR_CTX(p)          (((p) << 1) & 0x7)
+/* Secondary stream array type, dequeue pointer is to a transfer ring */
+#define        SCT_SEC_TR              0
+/* Primary stream array type, dequeue pointer is to a transfer ring */
+#define        SCT_PRI_TR              1
+/* Dequeue pointer is for a secondary stream array (SSA) with 8 entries */
+#define SCT_SSA_8              2
+#define SCT_SSA_16             3
+#define SCT_SSA_32             4
+#define SCT_SSA_64             5
+#define SCT_SSA_128            6
+#define SCT_SSA_256            7
+
+/* Assume no secondary streams for now */
+struct xhci_stream_info {
+       struct xhci_ring                **stream_rings;
+       /* Number of streams, including stream 0 (which drivers can't use) */
+       unsigned int                    num_streams;
+       /* The stream context array may be bigger than
+        * the number of streams the driver asked for
+        */
+       struct xhci_stream_ctx          *stream_ctx_array;
+       unsigned int                    num_stream_ctxs;
+       dma_addr_t                      ctx_array_dma;
+       /* For mapping physical TRB addresses to segments in stream rings */
+       struct radix_tree_root          trb_address_map;
+       struct xhci_command             *free_streams_command;
+};
+
+#define        SMALL_STREAM_ARRAY_SIZE         256
+#define        MEDIUM_STREAM_ARRAY_SIZE        1024
+
+struct xhci_virt_ep {
+       struct xhci_ring                *ring;
+       /* Related to endpoints that are configured to use stream IDs only */
+       struct xhci_stream_info         *stream_info;
+       /* Temporary storage in case the configure endpoint command fails and we
+        * have to restore the device state to the previous state
+        */
+       struct xhci_ring                *new_ring;
+       unsigned int                    ep_state;
+#define SET_DEQ_PENDING                (1 << 0)
+#define EP_HALTED              (1 << 1)        /* For stall handling */
+#define EP_HALT_PENDING                (1 << 2)        /* For URB cancellation */
+/* Transitioning the endpoint to using streams, don't enqueue URBs */
+#define EP_GETTING_STREAMS     (1 << 3)
+#define EP_HAS_STREAMS         (1 << 4)
+/* Transitioning the endpoint to not using streams, don't enqueue URBs */
+#define EP_GETTING_NO_STREAMS  (1 << 5)
+       /* ----  Related to URB cancellation ---- */
+       struct list_head        cancelled_td_list;
+       /* The TRB that was last reported in a stopped endpoint ring */
+       union xhci_trb          *stopped_trb;
+       struct xhci_td          *stopped_td;
+       unsigned int            stopped_stream;
+       /* Watchdog timer for stop endpoint command to cancel URBs */
+       struct timer_list       stop_cmd_timer;
+       int                     stop_cmds_pending;
+       struct xhci_hcd         *xhci;
+       /* Dequeue pointer and dequeue segment for a submitted Set TR Dequeue
+        * command.  We'll need to update the ring's dequeue segment and dequeue
+        * pointer after the command completes.
+        */
+       struct xhci_segment     *queued_deq_seg;
+       union xhci_trb          *queued_deq_ptr;
+       /*
+        * Sometimes the xHC can not process isochronous endpoint ring quickly
+        * enough, and it will miss some isoc tds on the ring and generate
+        * a Missed Service Error Event.
+        * Set skip flag when receive a Missed Service Error Event and
+        * process the missed tds on the endpoint ring.
+        */
+       bool                    skip;
+};
+
+struct xhci_virt_device {
+       struct usb_device               *udev;
+       /*
+        * Commands to the hardware are passed an "input context" that
+        * tells the hardware what to change in its data structures.
+        * The hardware will return changes in an "output context" that
+        * software must allocate for the hardware.  We need to keep
+        * track of input and output contexts separately because
+        * these commands might fail and we don't trust the hardware.
+        */
+       struct xhci_container_ctx       *out_ctx;
+       /* Used for addressing devices and configuration changes */
+       struct xhci_container_ctx       *in_ctx;
+       /* Rings saved to ensure old alt settings can be re-instated */
+       struct xhci_ring                **ring_cache;
+       int                             num_rings_cached;
+       /* Store xHC assigned device address */
+       int                             address;
+#define        XHCI_MAX_RINGS_CACHED   31
+       struct xhci_virt_ep             eps[31];
+       struct completion               cmd_completion;
+       /* Status of the last command issued for this device */
+       u32                             cmd_status;
+       struct list_head                cmd_list;
+       u8                              port;
+};
+
 
 /**
  * struct xhci_device_context_array
@@ -595,10 +804,10 @@ struct xhci_device_control {
  */
 struct xhci_device_context_array {
        /* 64-bit device addresses; we only write 32-bit addresses */
-       u32                     dev_context_ptrs[2*MAX_HC_SLOTS];
+       u64                     dev_context_ptrs[MAX_HC_SLOTS];
        /* private xHCD pointers */
        dma_addr_t      dma;
-} __attribute__ ((packed));
+};
 /* TODO: write function to set the 64-bit device DMA address */
 /*
  * TODO: change this to be dynamically sized at HC mem init time since the HC
@@ -606,21 +815,16 @@ struct xhci_device_context_array {
  */
 
 
-struct xhci_stream_ctx {
-       /* 64-bit stream ring address, cycle state, and stream type */
-       u32     stream_ring[2];
-       /* offset 0x14 - 0x1f reserved for HC internal use */
-       u32     reserved[2];
-} __attribute__ ((packed));
-
-
 struct xhci_transfer_event {
        /* 64-bit buffer address, or immediate data */
-       u32     buffer[2];
+       u64     buffer;
        u32     transfer_len;
        /* This field is interpreted differently based on the type of TRB */
        u32     flags;
-} __attribute__ ((packed));
+};
+
+/** Transfer Event bit fields **/
+#define        TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f)
 
 /* Completion Code - only applicable for some types of TRBs */
 #define        COMP_CODE_MASK          (0xff << 24)
@@ -695,10 +899,10 @@ struct xhci_transfer_event {
 
 struct xhci_link_trb {
        /* 64-bit segment pointer*/
-       u32 segment_ptr[2];
+       u64 segment_ptr;
        u32 intr_target;
        u32 control;
-} __attribute__ ((packed));
+};
 
 /* control bitfields */
 #define LINK_TOGGLE    (0x1<<1)
@@ -706,10 +910,28 @@ struct xhci_link_trb {
 /* Command completion event TRB */
 struct xhci_event_cmd {
        /* Pointer to command TRB, or the value passed by the event data trb */
-       u32 cmd_trb[2];
+       u64 cmd_trb;
        u32 status;
        u32 flags;
-} __attribute__ ((packed));
+};
+
+/* flags bitmasks */
+/* bits 16:23 are the virtual function ID */
+/* bits 24:31 are the slot ID */
+#define TRB_TO_SLOT_ID(p)      (((p) & (0xff<<24)) >> 24)
+#define SLOT_ID_FOR_TRB(p)     (((p) & 0xff) << 24)
+
+/* Stop Endpoint TRB - ep_index to endpoint ID for this TRB */
+#define TRB_TO_EP_INDEX(p)             ((((p) & (0x1f << 16)) >> 16) - 1)
+#define        EP_ID_FOR_TRB(p)                ((((p) + 1) & 0x1f) << 16)
+
+#define SUSPEND_PORT_FOR_TRB(p)                (((p) & 1) << 23)
+#define TRB_TO_SUSPEND_PORT(p)         (((p) & (1 << 23)) >> 23)
+#define LAST_EP_INDEX                  30
+
+/* Set TR Dequeue Pointer command TRB fields */
+#define TRB_TO_STREAM_ID(p)            ((((p) & (0xffff << 16)) >> 16))
+#define STREAM_ID_FOR_TRB(p)           ((((p)) & 0xffff) << 16)
 
 
 /* Port Status Change Event TRB fields */
@@ -719,9 +941,6 @@ struct xhci_event_cmd {
 /* Normal TRB fields */
 /* transfer_len bitmasks - bits 0:16 */
 #define        TRB_LEN(p)              ((p) & 0x1ffff)
-/* TD size - number of bytes remaining in the TD (including this TRB):
- * bits 17 - 21.  Shift the number of bytes by 10. */
-#define TD_REMAINDER(p)                ((((p) >> 10) & 0x1f) << 17)
 /* Interrupter Target - which MSI-X vector to target the completion event at */
 #define TRB_INTR_TARGET(p)     (((p) & 0x3ff) << 22)
 #define GET_INTR_TARGET(p)     (((p) >> 22) & 0x3ff)
@@ -748,9 +967,12 @@ struct xhci_event_cmd {
 /* Control transfer TRB specific fields */
 #define TRB_DIR_IN             (1<<16)
 
+/* Isochronous TRB specific fields */
+#define TRB_SIA                        (1<<31)
+
 struct xhci_generic_trb {
        u32 field[4];
-} __attribute__ ((packed));
+};
 
 union xhci_trb {
        struct xhci_link_trb            link;
@@ -762,6 +984,7 @@ union xhci_trb {
 /* TRB bit mask */
 #define        TRB_TYPE_BITMASK        (0xfc00)
 #define TRB_TYPE(p)            ((p) << 10)
+#define TRB_FIELD_TO_TYPE(p)   (((p) & TRB_TYPE_BITMASK) >> 10)
 /* TRB type IDs */
 /* bulk, interrupt, isoc scatter/gather, and control data stage */
 #define TRB_NORMAL             1
@@ -789,8 +1012,8 @@ union xhci_trb {
 #define TRB_CONFIG_EP          12
 /* Evaluate Context Command */
 #define TRB_EVAL_CONTEXT       13
-/* Reset Transfer Ring Command */
-#define TRB_RESET_RING         14
+/* Reset Endpoint Command */
+#define TRB_RESET_EP           14
 /* Stop Transfer Ring Command */
 #define TRB_STOP_RING          15
 /* Set Transfer Ring Dequeue Pointer Command */
@@ -829,20 +1052,52 @@ union xhci_trb {
 #define TRB_MFINDEX_WRAP       39
 /* TRB IDs 40-47 reserved, 48-63 is vendor-defined */
 
+/* Nec vendor-specific command completion event. */
+#define        TRB_NEC_CMD_COMP        48
+/* Get NEC firmware revision. */
+#define        TRB_NEC_GET_FW          49
+
+#define NEC_FW_MINOR(p)                (((p) >> 0) & 0xff)
+#define NEC_FW_MAJOR(p)                (((p) >> 8) & 0xff)
+
 /*
  * TRBS_PER_SEGMENT must be a multiple of 4,
  * since the command ring is 64-byte aligned.
  * It must also be greater than 16.
  */
 #define TRBS_PER_SEGMENT       64
+/* Allow two commands + a link TRB, along with any reserved command TRBs */
+#define MAX_RSVD_CMD_TRBS      (TRBS_PER_SEGMENT - 3)
 #define SEGMENT_SIZE           (TRBS_PER_SEGMENT*16)
+/* SEGMENT_SHIFT should be log2(SEGMENT_SIZE).
+ * Change this if you change TRBS_PER_SEGMENT!
+ */
+#define SEGMENT_SHIFT          10
+/* TRB buffer pointers can't cross 64KB boundaries */
+#define TRB_MAX_BUFF_SHIFT             16
+#define TRB_MAX_BUFF_SIZE      (1 << TRB_MAX_BUFF_SHIFT)
 
 struct xhci_segment {
        union xhci_trb          *trbs;
        /* private to HCD */
        struct xhci_segment     *next;
        dma_addr_t              dma;
-} __attribute__ ((packed));
+};
+
+struct xhci_td {
+       struct list_head        td_list;
+       struct list_head        cancelled_td_list;
+       struct urb              *urb;
+       struct xhci_segment     *start_seg;
+       union xhci_trb          *first_trb;
+       union xhci_trb          *last_trb;
+};
+
+struct xhci_dequeue_state {
+       struct xhci_segment *new_deq_seg;
+       union xhci_trb *new_deq_ptr;
+       int new_cycle_state;
+};
 
 struct xhci_ring {
        struct xhci_segment     *first_seg;
@@ -852,21 +1107,23 @@ struct xhci_ring {
        union  xhci_trb         *dequeue;
        struct xhci_segment     *deq_seg;
        unsigned int            deq_updates;
+       struct list_head        td_list;
        /*
         * Write the cycle state into the TRB cycle field to give ownership of
         * the TRB to the host controller (if we are the producer), or to check
         * if we own the TRB (if we are the consumer).  See section 4.9.1.
         */
        u32                     cycle_state;
+       unsigned int            stream_id;
 };
 
 struct xhci_erst_entry {
        /* 64-bit event ring segment address */
-       u32     seg_addr[2];
+       u64     seg_addr;
        u32     seg_size;
        /* Set to zero */
        u32     rsvd;
-} __attribute__ ((packed));
+};
 
 struct xhci_erst {
        struct xhci_erst_entry  *entries;
@@ -877,6 +1134,19 @@ struct xhci_erst {
        unsigned int            erst_size;
 };
 
+struct xhci_scratchpad {
+       u64 *sp_array;
+       dma_addr_t sp_dma;
+       void **sp_buffers;
+       dma_addr_t *sp_dma_buffers;
+};
+
+struct urb_priv {
+       int     length;
+       int     td_cnt;
+       struct  xhci_td *td[0];
+};
+
 /*
  * Each segment table entry is 4*32bits long.  1K seems like an ok size:
  * (1K bytes * 8bytes/bit) / (4*32 bits) = 64 segment entries in the table,
@@ -889,8 +1159,21 @@ struct xhci_erst {
 #define        ERST_ENTRIES    1
 /* Poll every 60 seconds */
 #define        POLL_TIMEOUT    60
+/* Stop endpoint command timeout (secs) for URB cancellation watchdog timer */
+#define XHCI_STOP_EP_CMD_TIMEOUT       5
 /* XXX: Make these module parameters */
 
+struct s3_save {
+       u32     command;
+       u32     dev_nt;
+       u64     dcbaa_ptr;
+       u32     config_reg;
+       u32     irq_pending;
+       u32     irq_control;
+       u32     erst_size;
+       u64     erst_base;
+       u64     erst_dequeue;
+};
 
 /* There is one ehci_hci structure per controller */
 struct xhci_hcd {
@@ -900,7 +1183,7 @@ struct xhci_hcd {
        struct xhci_run_regs __iomem *run_regs;
        struct xhci_doorbell_array __iomem *dba;
        /* Our HCD's current interrupter register set */
-       struct  intr_reg __iomem *ir_set;
+       struct  xhci_intr_reg __iomem *ir_set;
 
        /* Cached register copies of read-only HC data */
        __u32           hcs_params1;
@@ -923,28 +1206,76 @@ struct xhci_hcd {
        int             page_size;
        /* Valid values are 12 to 20, inclusive */
        int             page_shift;
-       /* only one MSI vector for now, but might need more later */
+       /* msi-x vectors */
        int             msix_count;
        struct msix_entry       *msix_entries;
        /* data structures */
        struct xhci_device_context_array *dcbaa;
        struct xhci_ring        *cmd_ring;
+       unsigned int            cmd_ring_reserved_trbs;
        struct xhci_ring        *event_ring;
        struct xhci_erst        erst;
+       /* Scratchpad */
+       struct xhci_scratchpad  *scratchpad;
+
+       /* slot enabling and address device helpers */
+       struct completion       addr_dev;
+       int slot_id;
+       /* Internal mirror of the HW's dcbaa */
+       struct xhci_virt_device *devs[MAX_HC_SLOTS];
 
        /* DMA pools */
        struct dma_pool *device_pool;
        struct dma_pool *segment_pool;
+       struct dma_pool *small_streams_pool;
+       struct dma_pool *medium_streams_pool;
 
 #ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
        /* Poll the rings - for debugging */
        struct timer_list       event_ring_timer;
        int                     zombie;
 #endif
+       /* Host controller watchdog timer structures */
+       unsigned int            xhc_state;
+
+       unsigned long           bus_suspended;
+       unsigned long           next_statechange;
+
+       u32                     command;
+       struct s3_save          s3;
+/* Host controller is dying - not responding to commands. "I'm not dead yet!"
+ *
+ * xHC interrupts have been disabled and a watchdog timer will (or has already)
+ * halt the xHCI host, and complete all URBs with an -ESHUTDOWN code.  Any code
+ * that sees this status (other than the timer that set it) should stop touching
+ * hardware immediately.  Interrupt handlers should return immediately when
+ * they see this status (any time they drop and re-acquire xhci->lock).
+ * xhci_urb_dequeue() should call usb_hcd_check_unlink_urb() and return without
+ * putting the TD on the canceled list, etc.
+ *
+ * There are no reports of xHCI host controllers that display this issue.
+ */
+#define XHCI_STATE_DYING       (1 << 0)
        /* Statistics */
        int                     noops_submitted;
        int                     noops_handled;
        int                     error_bitmask;
+       unsigned int            quirks;
+#define        XHCI_LINK_TRB_QUIRK     (1 << 0)
+#define XHCI_RESET_EP_QUIRK    (1 << 1)
+#define XHCI_NEC_HOST          (1 << 2)
+       u32                     port_c_suspend[8];      /* port suspend change*/
+       u32                     suspended_ports[8];     /* which ports are
+                                                          suspended */
+       unsigned long           resume_done[MAX_HC_PORTS];
+       /* Is each xHCI roothub port a USB 3.0, USB 2.0, or USB 1.1 port? */
+       u8                      *port_array;
+       /* Array of pointers to USB 3.0 PORTSC registers */
+       u32 __iomem             **usb3_ports;
+       unsigned int            num_usb3_ports;
+       /* Array of pointers to USB 2.0 PORTSC registers */
+       u32 __iomem             **usb2_ports;
+       unsigned int            num_usb2_ports;
 };
 
 /* For testing purposes */
@@ -983,29 +1314,123 @@ static inline unsigned int xhci_readl(const struct xhci_hcd *xhci,
 {
        return readl(regs);
 }
-static inline void xhci_writel(const struct xhci_hcd *xhci,
+static inline void xhci_writel(struct xhci_hcd *xhci,
                const unsigned int val, __u32 __iomem *regs)
 {
-       if (!in_interrupt())
-               xhci_dbg(xhci, "`MEM_WRITE_DWORD(3'b000, 32'h%0x, 32'h%0x, 4'hf);\n",
-                               (unsigned int) regs, val);
+       xhci_dbg(xhci,
+                       "`MEM_WRITE_DWORD(3'b000, 32'h%p, 32'h%0x, 4'hf);\n",
+                       regs, val);
        writel(val, regs);
 }
 
+/*
+ * Registers should always be accessed with double word or quad word accesses.
+ *
+ * Some xHCI implementations may support 64-bit address pointers.  Registers
+ * with 64-bit address pointers should be written to with dword accesses by
+ * writing the low dword first (ptr[0]), then the high dword (ptr[1]) second.
+ * xHCI implementations that do not support 64-bit address pointers will ignore
+ * the high dword, and write order is irrelevant.
+ */
+static inline u64 xhci_read_64(const struct xhci_hcd *xhci,
+               __u64 __iomem *regs)
+{
+       __u32 __iomem *ptr = (__u32 __iomem *) regs;
+       u64 val_lo = readl(ptr);
+       u64 val_hi = readl(ptr + 1);
+       return val_lo + (val_hi << 32);
+}
+static inline void xhci_write_64(struct xhci_hcd *xhci,
+               const u64 val, __u64 __iomem *regs)
+{
+       __u32 __iomem *ptr = (__u32 __iomem *) regs;
+       u32 val_lo = lower_32_bits(val);
+       u32 val_hi = upper_32_bits(val);
+
+       xhci_dbg(xhci,
+                       "`MEM_WRITE_DWORD(3'b000, 64'h%p, 64'h%0lx, 4'hf);\n",
+                       regs, (long unsigned int) val);
+       writel(val_lo, ptr);
+       writel(val_hi, ptr + 1);
+}
+
+static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci)
+{
+       u32 temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase);
+       return ((HC_VERSION(temp) == 0x95) &&
+                       (xhci->quirks & XHCI_LINK_TRB_QUIRK));
+}
+
 /* xHCI debugging */
-void xhci_print_ir_set(struct xhci_hcd *xhci, struct intr_reg *ir_set, int set_num);
+void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num);
 void xhci_print_registers(struct xhci_hcd *xhci);
 void xhci_dbg_regs(struct xhci_hcd *xhci);
 void xhci_print_run_regs(struct xhci_hcd *xhci);
+void xhci_print_trb_offsets(struct xhci_hcd *xhci, union xhci_trb *trb);
+void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb);
 void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg);
 void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring);
 void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
 void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci);
 void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring);
-
-/* xHCI memory managment */
+void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int last_ep);
+char *xhci_get_slot_state(struct xhci_hcd *xhci,
+               struct xhci_container_ctx *ctx);
+void xhci_dbg_ep_rings(struct xhci_hcd *xhci,
+               unsigned int slot_id, unsigned int ep_index,
+               struct xhci_virt_ep *ep);
+
+/* xHCI memory management */
 void xhci_mem_cleanup(struct xhci_hcd *xhci);
 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags);
+void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id);
+int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device *udev, gfp_t flags);
+int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev);
+void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci,
+               struct usb_device *udev);
+unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc);
+unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc);
+unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index);
+unsigned int xhci_last_valid_endpoint(u32 added_ctxs);
+void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep);
+void xhci_endpoint_copy(struct xhci_hcd *xhci,
+               struct xhci_container_ctx *in_ctx,
+               struct xhci_container_ctx *out_ctx,
+               unsigned int ep_index);
+void xhci_slot_copy(struct xhci_hcd *xhci,
+               struct xhci_container_ctx *in_ctx,
+               struct xhci_container_ctx *out_ctx);
+int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev,
+               struct usb_device *udev, struct usb_host_endpoint *ep,
+               gfp_t mem_flags);
+void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring);
+void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci,
+               struct xhci_virt_device *virt_dev,
+               unsigned int ep_index);
+struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
+               unsigned int num_stream_ctxs,
+               unsigned int num_streams, gfp_t flags);
+void xhci_free_stream_info(struct xhci_hcd *xhci,
+               struct xhci_stream_info *stream_info);
+void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci,
+               struct xhci_ep_ctx *ep_ctx,
+               struct xhci_stream_info *stream_info);
+void xhci_setup_no_streams_ep_input_ctx(struct xhci_hcd *xhci,
+               struct xhci_ep_ctx *ep_ctx,
+               struct xhci_virt_ep *ep);
+struct xhci_ring *xhci_dma_to_transfer_ring(
+               struct xhci_virt_ep *ep,
+               u64 address);
+struct xhci_ring *xhci_stream_id_to_ring(
+               struct xhci_virt_device *dev,
+               unsigned int ep_index,
+               unsigned int stream_id);
+struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
+               bool allocate_in_ctx, bool allocate_completion,
+               gfp_t mem_flags);
+void xhci_urb_free_priv(struct xhci_hcd *xhci, struct urb_priv *urb_priv);
+void xhci_free_command(struct xhci_hcd *xhci,
+               struct xhci_command *command);
 
 #ifdef CONFIG_PCI
 /* xHCI PCI glue */
@@ -1014,25 +1439,112 @@ void xhci_unregister_pci(void);
 #endif
 
 /* xHCI host controller glue */
+void xhci_quiesce(struct xhci_hcd *xhci);
 int xhci_halt(struct xhci_hcd *xhci);
 int xhci_reset(struct xhci_hcd *xhci);
 int xhci_init(struct usb_hcd *hcd);
 int xhci_run(struct usb_hcd *hcd);
 void xhci_stop(struct usb_hcd *hcd);
 void xhci_shutdown(struct usb_hcd *hcd);
+
+#ifdef CONFIG_PM
+int xhci_suspend(struct xhci_hcd *xhci);
+int xhci_resume(struct xhci_hcd *xhci, bool hibernated);
+#else
+#define        xhci_suspend    NULL
+#define        xhci_resume     NULL
+#endif
+
 int xhci_get_frame(struct usb_hcd *hcd);
 irqreturn_t xhci_irq(struct usb_hcd *hcd);
+irqreturn_t xhci_msi_irq(int irq, struct usb_hcd *hcd);
+int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
+void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
+int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
+               struct usb_host_endpoint **eps, unsigned int num_eps,
+               unsigned int num_streams, gfp_t mem_flags);
+int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
+               struct usb_host_endpoint **eps, unsigned int num_eps,
+               gfp_t mem_flags);
+int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
+int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
+                       struct usb_tt *tt, gfp_t mem_flags);
+int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
+int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
+int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
+int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
+void xhci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
+int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev);
+int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
+void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
 
 /* xHCI ring, segment, TRB, and TD functions */
-dma_addr_t trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
-void ring_cmd_db(struct xhci_hcd *xhci);
-void *setup_one_noop(struct xhci_hcd *xhci);
-void handle_event(struct xhci_hcd *xhci);
-void set_hc_event_deq(struct xhci_hcd *xhci);
+dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
+struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
+               union xhci_trb *start_trb, union xhci_trb *end_trb,
+               dma_addr_t suspect_dma);
+int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
+void xhci_ring_cmd_db(struct xhci_hcd *xhci);
+void *xhci_setup_one_noop(struct xhci_hcd *xhci);
+int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id);
+int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
+               u32 slot_id);
+int xhci_queue_vendor_command(struct xhci_hcd *xhci,
+               u32 field1, u32 field2, u32 field3, u32 field4);
+int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
+               unsigned int ep_index, int suspend);
+int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
+               int slot_id, unsigned int ep_index);
+int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
+               int slot_id, unsigned int ep_index);
+int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
+               int slot_id, unsigned int ep_index);
+int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
+               struct urb *urb, int slot_id, unsigned int ep_index);
+int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
+               u32 slot_id, bool command_must_succeed);
+int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
+               u32 slot_id);
+int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
+               unsigned int ep_index);
+int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id);
+void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
+               unsigned int slot_id, unsigned int ep_index,
+               unsigned int stream_id, struct xhci_td *cur_td,
+               struct xhci_dequeue_state *state);
+void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
+               unsigned int slot_id, unsigned int ep_index,
+               unsigned int stream_id,
+               struct xhci_dequeue_state *deq_state);
+void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
+               struct usb_device *udev, unsigned int ep_index);
+void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci,
+               unsigned int slot_id, unsigned int ep_index,
+               struct xhci_dequeue_state *deq_state);
+void xhci_stop_endpoint_command_watchdog(unsigned long arg);
+void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
+               unsigned int ep_index, unsigned int stream_id);
 
 /* xHCI roothub code */
 int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
                char *buf, u16 wLength);
 int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);
 
+#ifdef CONFIG_PM
+int xhci_bus_suspend(struct usb_hcd *hcd);
+int xhci_bus_resume(struct usb_hcd *hcd);
+#else
+#define        xhci_bus_suspend        NULL
+#define        xhci_bus_resume         NULL
+#endif /* CONFIG_PM */
+
+u32 xhci_port_state_to_neutral(u32 state);
+int xhci_find_slot_id_by_port(struct xhci_hcd *xhci, u16 port);
+void xhci_ring_device(struct xhci_hcd *xhci, int slot_id);
+
+/* xHCI contexts */
+struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
+struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
+struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int ep_index);
+
 #endif /* __LINUX_XHCI_HCD_H */