This commit was manufactured by cvs2svn to create branch
[linux-2.6.git] / drivers / xen / usbfront / xhci.h
1 /******************************************************************************
2  * xhci.h
3  *
4  * Private definitions for the Xen Virtual USB Controller.  Based on
5  * drivers/usb/host/uhci.h from Linux.  Copyright for the imported content is
6  * retained by the original authors.
7  *
8  * Modifications are:
9  * Copyright (C) 2004 Intel Research Cambridge
10  * Copyright (C) 2004, 2005 Mark Williamson
11  */
12
13 #ifndef __LINUX_XHCI_H
14 #define __LINUX_XHCI_H
15
16 #include <linux/list.h>
17 #include <linux/usb.h>
18 #include <asm-xen/xen-public/io/usbif.h>
19 #include <linux/spinlock.h>
20
21 /* xhci_port_t - current known state of a virtual hub ports */
22 typedef struct {
23         unsigned int cs     :1; /* Connection status.         */
24         unsigned int cs_chg :1; /* Connection status change.  */
25         unsigned int pe     :1; /* Port enable.               */
26         unsigned int pe_chg :1; /* Port enable change.        */
27         unsigned int susp   :1; /* Suspended.                 */
28         unsigned int lsda   :1; /* Low speed device attached. */
29         unsigned int pr     :1; /* Port reset.                */
30 } xhci_port_t;
31
32 /* struct virt_root_hub - state related to the virtual root hub */
33 struct virt_root_hub {
34         struct usb_device *dev;
35         int devnum;             /* Address of Root Hub endpoint */
36         struct urb *urb;
37         void *int_addr;
38         int send;
39         int interval;
40         int numports;
41         int c_p_r[8];
42         struct timer_list rh_int_timer;
43         spinlock_t port_state_lock;
44         xhci_port_t *ports;
45 };
46
47 /* struct xhci - contains the state associated with a single USB interface */
48 struct xhci {
49
50 #ifdef CONFIG_PROC_FS
51         /* procfs */
52         int num;
53         struct proc_dir_entry *proc_entry;
54 #endif
55
56         int evtchn;                        /* Interdom channel to backend */
57         int irq;                           /* Bound to evtchn */
58         enum { 
59                 USBIF_STATE_CONNECTED    = 2,
60                 USBIF_STATE_DISCONNECTED = 1,
61                 USBIF_STATE_CLOSED       = 0
62         } state; /* State of this USB interface */
63         unsigned long recovery; /* boolean recovery in progress flag */
64         
65         unsigned long bandwidth;
66
67         struct usb_bus *bus;
68
69         /* Main list of URB's currently controlled by this HC */
70         spinlock_t urb_list_lock;
71         struct list_head urb_list;              /* P: xhci->urb_list_lock */
72
73         /* List of URB's awaiting completion callback */
74         spinlock_t complete_list_lock;
75         struct list_head complete_list;         /* P: xhci->complete_list_lock */
76
77         struct virt_root_hub rh;        /* private data of the virtual root hub */
78
79         spinlock_t ring_lock;
80         usbif_front_ring_t usb_ring;
81
82         int awaiting_reset;
83 };
84
85 /* per-URB private data structure for the host controller */
86 struct urb_priv {
87         struct urb *urb;
88         usbif_iso_t *schedule;
89         struct usb_device *dev;
90
91         int in_progress : 1;            /* QH was queued (not linked in) */
92         int short_control_packet : 1;   /* If we get a short packet during */
93                                         /*  a control transfer, retrigger */
94                                         /*  the status phase */
95
96         int status;                     /* Final status */
97
98         unsigned long inserttime;       /* In jiffies */
99
100         struct list_head complete_list; /* P: xhci->complete_list_lock */
101 };
102
103 /*
104  * Locking in xhci.c
105  *
106  * spinlocks are used extensively to protect the many lists and data
107  * structures we have. It's not that pretty, but it's necessary. We
108  * need to be done with all of the locks (except complete_list_lock) when
109  * we call urb->complete. I've tried to make it simple enough so I don't
110  * have to spend hours racking my brain trying to figure out if the
111  * locking is safe.
112  *
113  * Here's the safe locking order to prevent deadlocks:
114  *
115  * #1 xhci->urb_list_lock
116  * #2 urb->lock
117  * #3 xhci->urb_remove_list_lock
118  * #4 xhci->complete_list_lock
119  *
120  * If you're going to grab 2 or more locks at once, ALWAYS grab the lock
121  * at the lowest level FIRST and NEVER grab locks at the same level at the
122  * same time.
123  * 
124  * So, if you need xhci->urb_list_lock, grab it before you grab urb->lock
125  */
126
127 /* -------------------------------------------------------------------------
128    Virtual Root HUB
129    ------------------------------------------------------------------------- */
130 /* destination of request */
131 #define RH_DEVICE               0x00
132 #define RH_INTERFACE            0x01
133 #define RH_ENDPOINT             0x02
134 #define RH_OTHER                0x03
135
136 #define RH_CLASS                0x20
137 #define RH_VENDOR               0x40
138
139 /* Requests: bRequest << 8 | bmRequestType */
140 #define RH_GET_STATUS           0x0080
141 #define RH_CLEAR_FEATURE        0x0100
142 #define RH_SET_FEATURE          0x0300
143 #define RH_SET_ADDRESS          0x0500
144 #define RH_GET_DESCRIPTOR       0x0680
145 #define RH_SET_DESCRIPTOR       0x0700
146 #define RH_GET_CONFIGURATION    0x0880
147 #define RH_SET_CONFIGURATION    0x0900
148 #define RH_GET_STATE            0x0280
149 #define RH_GET_INTERFACE        0x0A80
150 #define RH_SET_INTERFACE        0x0B00
151 #define RH_SYNC_FRAME           0x0C80
152 /* Our Vendor Specific Request */
153 #define RH_SET_EP               0x2000
154
155 /* Hub port features */
156 #define RH_PORT_CONNECTION      0x00
157 #define RH_PORT_ENABLE          0x01
158 #define RH_PORT_SUSPEND         0x02
159 #define RH_PORT_OVER_CURRENT    0x03
160 #define RH_PORT_RESET           0x04
161 #define RH_PORT_POWER           0x08
162 #define RH_PORT_LOW_SPEED       0x09
163 #define RH_C_PORT_CONNECTION    0x10
164 #define RH_C_PORT_ENABLE        0x11
165 #define RH_C_PORT_SUSPEND       0x12
166 #define RH_C_PORT_OVER_CURRENT  0x13
167 #define RH_C_PORT_RESET         0x14
168
169 /* Hub features */
170 #define RH_C_HUB_LOCAL_POWER    0x00
171 #define RH_C_HUB_OVER_CURRENT   0x01
172 #define RH_DEVICE_REMOTE_WAKEUP 0x00
173 #define RH_ENDPOINT_STALL       0x01
174
175 /* Our Vendor Specific feature */
176 #define RH_REMOVE_EP            0x00
177
178 #define RH_ACK                  0x01
179 #define RH_REQ_ERR              -1
180 #define RH_NACK                 0x00
181
182 #endif
183