~ubuntu-branches/ubuntu/trusty/slof/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/libusb/usb-xhci.h

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2015-01-23 12:18:53 UTC
  • mfrom: (6.1.1 utopic-proposed)
  • Revision ID: package-import@ubuntu.com-20150123121853-or6a6rkrzor2peku
Tags: 20140630+dfsg-1ubuntu1~14.04
Backport wholesale to trusty to fix network boot issues (LP: #1374568)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 * Copyright (c) 2013 IBM Corporation
 
3
 * All rights reserved.
 
4
 * This program and the accompanying materials
 
5
 * are made available under the terms of the BSD License
 
6
 * which accompanies this distribution, and is available at
 
7
 * http://www.opensource.org/licenses/bsd-license.php
 
8
 *
 
9
 * Contributors:
 
10
 *     IBM Corporation - initial implementation
 
11
 *****************************************************************************/
 
12
/*
 
13
 * Definitions for XHCI Controller - Revision 1.0 (5/21/10)
 
14
 *
 
15
 */
 
16
 
 
17
#ifndef USB_XHCI_H
 
18
#define USB_XHCI_H
 
19
 
 
20
#include <stdint.h>
 
21
#include "usb-core.h"
 
22
 
 
23
#define BIT(x) (1 << x)
 
24
 
 
25
/* 5.3 Host Controller Capability Registers
 
26
 * Table 19
 
27
 */
 
28
struct xhci_cap_regs {
 
29
        uint8_t caplength;
 
30
        uint8_t reserved;
 
31
        uint16_t hciversion;
 
32
        uint32_t hcsparams1;
 
33
        uint32_t hcsparams2;
 
34
        uint32_t hcsparams3;
 
35
        uint32_t hccparams;
 
36
#define XHCI_HCCPARAMS_CSZ   BIT(2)
 
37
        uint32_t dboff;
 
38
        uint32_t rtsoff;
 
39
} __attribute__ ((packed));
 
40
 
 
41
/* Table 27: Host Controller USB Port Register Set */
 
42
struct xhci_port_regs {
 
43
        uint32_t portsc;
 
44
#define PORTSC_CCS        BIT(0)
 
45
#define PORTSC_PED        BIT(1)
 
46
#define PORTSC_OCA        BIT(3)
 
47
#define PORTSC_PR         BIT(4)
 
48
#define PORTSC_PLS_MASK   (0xF << 5)
 
49
#define PORTSC_PLS_U0         0
 
50
#define PORTSC_PLS_U1         1
 
51
#define PORTSC_PLS_U2         2
 
52
#define PORTSC_PLS_U3         3
 
53
#define PORTSC_PLS_DISABLED   4
 
54
#define PORTSC_PLS_RXDETECT   5
 
55
#define PORTSC_PLS_INACTIVE   6
 
56
#define PORTSC_PLS_POLLING    7
 
57
#define PORTSC_PLS_RECOVERY   8
 
58
#define PORTSC_PLS_HOTRESET   9
 
59
#define PORTSC_PLS_COMP_MODE  10
 
60
#define PORTSC_PLS_TEST_MODE  11
 
61
#define PORTSC_PLS_RESUME     15
 
62
#define PORTSC_PP         BIT(9)
 
63
#define PORTSC_PS_MASK    (0xF << 10)
 
64
#define PORTSC_PIC_MASK   (0x3 << 14)
 
65
#define PORTSC_LWS        BIT(16)
 
66
#define PORTSC_CSC        BIT(17)
 
67
#define PORTSC_PEC        BIT(18)
 
68
#define PORTSC_WRC        BIT(19)
 
69
#define PORTSC_OCC        BIT(20)
 
70
#define PORTSC_PRC        BIT(21)
 
71
#define PORTSC_PLC        BIT(22)
 
72
#define PORTSC_CEC        BIT(23)
 
73
#define PORTSC_CAS        BIT(24)
 
74
#define PORTSC_WCE        BIT(25)
 
75
#define PORTSC_WDE        BIT(26)
 
76
#define PORTSC_WOE        BIT(27)
 
77
#define PORTSC_DR         BIT(30)
 
78
#define PORTSC_WPR        BIT(31)
 
79
 
 
80
        uint32_t portpmsc;
 
81
        uint32_t portli;
 
82
        uint32_t reserved;
 
83
} __attribute__ ((packed));
 
84
 
 
85
struct port_state {
 
86
        bool    PP;
 
87
        bool    CCS;
 
88
        bool    PED;
 
89
        bool    PR;
 
90
        uint8_t PLS;
 
91
        char *state;
 
92
};
 
93
 
 
94
 
 
95
struct port_state ps_array_usb2[] = {
 
96
        {1, 0, 0, 0, PORTSC_PLS_U0, "ERROR"}
 
97
};
 
98
 
 
99
struct port_state ps_array_usb3[] = {
 
100
        {0, 0, 0, 0, PORTSC_PLS_DISABLED, "Powered-OFF"},
 
101
        {1, 0, 0, 0, PORTSC_PLS_POLLING,  "Polling"},
 
102
        {1, 0, 0, 0, PORTSC_PLS_U0,       "Polling"},
 
103
        {1, 0, 0, 0, PORTSC_PLS_RXDETECT, "***  Disconnected ***"},
 
104
        {1, 0, 0, 0, PORTSC_PLS_DISABLED, "Disabled"},
 
105
        {1, 0, 0, 0, PORTSC_PLS_INACTIVE, "Error"},
 
106
        {1, 0, 0, 0, PORTSC_PLS_TEST_MODE,"Loopback"},
 
107
        {1, 0, 0, 0, PORTSC_PLS_COMP_MODE,"Compliancek"},
 
108
        {1, 1, 0, 1, PORTSC_PLS_U0,       "******  Reset  ******"},
 
109
        {1, 1, 1, 0, PORTSC_PLS_U0,       "****** Enabled ******"},
 
110
};
 
111
 
 
112
/* 5.4 Host Controller Operational Registers
 
113
 * Table 26
 
114
 */
 
115
struct xhci_op_regs {
 
116
        uint32_t usbcmd;
 
117
#define XHCI_USBCMD_RS            BIT(0)
 
118
#define XHCI_USBCMD_HCRST         BIT(1)
 
119
 
 
120
        uint32_t usbsts;
 
121
#define XHCI_USBSTS_HCH           BIT(0)
 
122
#define XHCI_USBSTS_CNR           BIT(11)
 
123
 
 
124
        uint32_t pagesize;
 
125
        uint8_t reserved[8];    /* 0C - 13 */
 
126
        uint32_t dnctrl;        /* Device notification control */
 
127
        uint64_t crcr;          /* Command ring control */
 
128
#define XHCI_CRCR_CRP_MASK        0xFFFFFFFFFFFFFFC0
 
129
#define XHCI_CRCR_CRR             BIT(3)
 
130
#define XHCI_CRCR_CRP_SIZE        4096
 
131
 
 
132
        uint8_t reserved1[16];  /* 20 - 2F */
 
133
        uint64_t dcbaap;        /* Device Context Base Address Array Pointer */
 
134
#define XHCI_DCBAAP_MAX_SIZE      2048
 
135
 
 
136
        uint32_t config;         /* Configure */
 
137
#define XHCI_CONFIG_MAX_SLOT      4
 
138
 
 
139
        uint8_t reserved2[964]; /* 3C - 3FF */
 
140
        /* USB Port register set */
 
141
#define XHCI_PORT_MAX 256
 
142
        struct xhci_port_regs prs[XHCI_PORT_MAX];
 
143
} __attribute__ ((packed));
 
144
 
 
145
/*
 
146
 * 5.5.2  Interrupter Register Set
 
147
 * Table 42: Interrupter Registers
 
148
 */
 
149
struct xhci_int_regs {
 
150
        uint32_t iman;
 
151
        uint32_t imod;
 
152
        uint32_t erstsz;
 
153
#define XHCI_ERST_SIZE_MASK 0xFFFF
 
154
        uint32_t reserved;
 
155
        uint64_t erstba;
 
156
#define XHCI_ERST_ADDR_MASK (~(0x3FUL))
 
157
        uint64_t erdp;
 
158
#define XHCI_ERDP_MASK      (~(0xFUL))
 
159
} __attribute__ ((packed));
 
160
 
 
161
/* 5.5 Host Controller Runtime Registers */
 
162
struct xhci_run_regs {
 
163
        uint32_t mfindex;       /* microframe index */
 
164
        uint8_t reserved[28];
 
165
#define XHCI_IRS_MAX 1024
 
166
        struct xhci_int_regs irs[XHCI_IRS_MAX];
 
167
} __attribute__ ((packed));
 
168
 
 
169
/* 5.6 Doorbell Registers*/
 
170
struct xhci_db_regs {
 
171
        uint32_t db[256];
 
172
}  __attribute__ ((packed));
 
173
 
 
174
#define COMP_SUCCESS         1
 
175
 
 
176
#define TRB_SLOT_ID(x)       (((x) & (0xFF << 24)) >> 24)
 
177
#define TRB_CMD_SLOT_ID(x)   ((x & 0xFF) << 24)
 
178
#define TRB_TYPE(x)          (((x) & (0x3F << 10)) >> 10)
 
179
#define TRB_CMD_TYPE(x)      ((x & 0x3F)  << 10)
 
180
#define TRB_STATUS(x)        (((x) & (0xFF << 24)) >> 24)
 
181
#define TRB_ADDR_LOW(x)      ((uint32_t)((uint64_t)(x)))
 
182
#define TRB_ADDR_HIGH(x)     ((uint32_t)((uint64_t)(x) >> 32))
 
183
#define TRB_TRT(x)           (((x) & 0x3) << 16 )
 
184
#define TRB_DIR_IN           BIT(16)
 
185
#define TRB_IOC              BIT(5)
 
186
#define TRB_IDT              BIT(6)
 
187
 
 
188
#define TRB_CYCLE_STATE      BIT(0)
 
189
 
 
190
struct xhci_transfer_trb {
 
191
        uint64_t addr;
 
192
        uint32_t len;
 
193
        uint32_t flags;
 
194
} __attribute__ ((packed));
 
195
 
 
196
struct xhci_link_trb {
 
197
        uint64_t addr;
 
198
        uint32_t field2;
 
199
        uint32_t field3;
 
200
} __attribute__ ((packed));
 
201
 
 
202
/* Event TRB */
 
203
struct xhci_event_trb {
 
204
        uint64_t addr;
 
205
        uint32_t status;
 
206
        uint32_t flags;
 
207
} __attribute__ ((packed));
 
208
 
 
209
#define TRB_NORMAL           1
 
210
#define TRB_SETUP_STAGE      2
 
211
#define TRB_DATA_STAGE       3
 
212
#define TRB_STATUS_STAGE     4
 
213
#define TRB_ISOCH            5
 
214
#define TRB_LINK             6
 
215
#define TRB_EVENT_DATA       7
 
216
#define TRB_NOOP             8
 
217
#define TRB_ENABLE_SLOT      9
 
218
#define TRB_DISABLE_SLOT    10
 
219
#define TRB_ADDRESS_DEV     11
 
220
#define TRB_CONFIG_EP       12
 
221
#define TRB_EVAL_CNTX       13
 
222
#define TRB_TRANSFER_EVENT  32
 
223
#define TRB_CMD_COMPLETION  33
 
224
#define TRB_PORT_STATUS     34
 
225
 
 
226
struct xhci_command_trb {
 
227
        uint32_t field[4];
 
228
}__attribute__ ((packed));
 
229
 
 
230
union xhci_trb {
 
231
        struct xhci_event_trb event;
 
232
        struct xhci_transfer_trb xfer;
 
233
        struct xhci_command_trb cmd;
 
234
        struct xhci_link_trb link;
 
235
};
 
236
 
 
237
enum xhci_seg_type {
 
238
        TYPE_CTRL = 0,
 
239
        TYPE_BULK,
 
240
        TYPE_COMMAND,
 
241
        TYPE_EVENT,
 
242
};
 
243
 
 
244
struct xhci_seg {
 
245
        union xhci_trb *trbs;
 
246
        struct xhci_seg *next;
 
247
        uint64_t enq;
 
248
        uint64_t deq;
 
249
        uint64_t trbs_dma;
 
250
        uint32_t size;
 
251
        uint32_t cycle_state;
 
252
        enum xhci_seg_type type;
 
253
};
 
254
 
 
255
#define XHCI_TRB_SIZE          16
 
256
#define XHCI_EVENT_TRBS_SIZE   4096
 
257
#define XHCI_CONTROL_TRBS_SIZE 4096
 
258
#define XHCI_DATA_TRBS_SIZE    4096
 
259
#define XHCI_ERST_NUM_SEGS     1
 
260
 
 
261
#define XHCI_MAX_BULK_SIZE    0xF000
 
262
 
 
263
struct xhci_erst_entry {
 
264
        uint64_t addr;
 
265
        uint32_t size;
 
266
        uint32_t reserved;
 
267
} __attribute__ ((packed));
 
268
 
 
269
struct xhci_erst {
 
270
        struct xhci_erst_entry *entries;
 
271
        uint64_t dma;
 
272
        uint32_t num_segs; /* number of segments */
 
273
};
 
274
 
 
275
struct xhci_control_ctx {
 
276
        uint32_t d_flags;
 
277
        uint32_t a_flags;
 
278
        uint32_t reserved[6];
 
279
} __attribute__ ((packed));
 
280
 
 
281
struct xhci_slot_ctx {
 
282
        uint32_t field1;
 
283
#define SLOT_SPEED_FS           BIT(20)
 
284
#define SLOT_SPEED_LS           BIT(21)
 
285
#define SLOT_SPEED_HS           BIT(22)
 
286
#define SLOT_SPEED_SS           BIT(23)
 
287
#define LAST_CONTEXT(x)         (x << 27)
 
288
 
 
289
        uint32_t field2;
 
290
#define ROOT_HUB_PORT(x)        ((x & 0xff) << 16)
 
291
 
 
292
        uint32_t field3;
 
293
        uint32_t field4;
 
294
#define USB_DEV_ADDRESS(x)     (x & 0xFFU)
 
295
#define SLOT_STATE(x)          ((x >> 27) & 0x1FU)
 
296
#define SLOT_STATE_DIS_ENA     0
 
297
#define SLOT_STATE_DEFAULT     1
 
298
#define SLOT_STATE_ADDRESSED   2
 
299
#define SLOT_STATE_CONFIGURED  3
 
300
 
 
301
 
 
302
        uint32_t reserved[4];
 
303
} __attribute__ ((packed));
 
304
 
 
305
struct xhci_ep_ctx {
 
306
        uint32_t field1;
 
307
        uint32_t field2;
 
308
#define MAX_PACKET_SIZE(x)      (((x) & 0xFFFF) << 16)
 
309
#define MAX_BURST(x)            (((x) & 0xFF) << 8)
 
310
#define EP_TYPE(x)              (((x) & 0x07) << 3)
 
311
#define EP_ISOC_OUT     1
 
312
#define EP_BULK_OUT     2
 
313
#define EP_INT_OUT      3
 
314
#define EP_CTRL         4
 
315
#define EP_ISOC_IN      5
 
316
#define EP_BULK_IN      6
 
317
#define EP_INT_IN       7
 
318
 
 
319
#define ERROR_COUNT(x)          (((x) & 0x03) << 1)
 
320
 
 
321
        uint64_t deq_addr;
 
322
        uint32_t field4;
 
323
        uint32_t reserved[3];
 
324
} __attribute__ ((packed));
 
325
 
 
326
struct xhci_ctx {
 
327
        uint8_t type;
 
328
#define XHCI_CTX_TYPE_DEVICE  0x1
 
329
#define XHCI_CTX_TYPE_INPUT   0x2
 
330
        uint32_t size;
 
331
        uint8_t  *addr;
 
332
#define XHCI_CTX_BUF_SIZE 4096
 
333
        uint64_t dma_addr;
 
334
};
 
335
 
 
336
struct xhci_dev {
 
337
        struct usb_dev *dev;
 
338
        uint32_t slot_id;
 
339
        struct xhci_ctx in_ctx;
 
340
        struct xhci_ctx out_ctx;
 
341
        struct xhci_seg control;
 
342
        struct xhci_seg bulk_in;
 
343
        struct xhci_seg bulk_out;
 
344
        uint32_t ctx_size;
 
345
};
 
346
 
 
347
struct xhci_hcd {
 
348
        struct xhci_cap_regs *cap_regs;
 
349
        struct xhci_op_regs  *op_regs;
 
350
        struct xhci_run_regs *run_regs;
 
351
        struct xhci_db_regs *db_regs;
 
352
        struct usb_hcd_dev *hcidev;
 
353
        struct xhci_dev xdevs[XHCI_CONFIG_MAX_SLOT + 1];
 
354
        struct usb_pipe *freelist;
 
355
        struct usb_pipe *end;
 
356
        uint64_t *dcbaap;
 
357
        uint64_t dcbaap_dma;
 
358
        struct xhci_seg ering;
 
359
        struct xhci_seg crseg;
 
360
        struct xhci_erst erst;
 
361
        uint64_t erds_dma;
 
362
        uint32_t erds_size;
 
363
        uint32_t slot_id;
 
364
        uint32_t hcc_csz_64;
 
365
        void *pool;
 
366
#define XHCI_PIPE_POOL_SIZE     4096
 
367
 
 
368
        long pool_phys;
 
369
};
 
370
 
 
371
struct xhci_pipe {
 
372
        struct usb_pipe pipe;
 
373
        struct xhci_seg *seg;
 
374
};
 
375
 
 
376
#endif  /* USB_XHCI_H */