1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#ifndef __LINUX_XHCI_HCD_H
25#define __LINUX_XHCI_HCD_H
26
27#include <linux/usb.h>
28#include <linux/timer.h>
29#include <linux/kernel.h>
30#include <linux/usb/hcd.h>
31#include <linux/io-64-nonatomic-lo-hi.h>
32
33
34#include "xhci-ext-caps.h"
35#include "pci-quirks.h"
36
37
38#define XHCI_SBRN_OFFSET (0x60)
39
40
41#define MAX_HC_SLOTS 256
42
43#define MAX_HC_PORTS 127
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62struct xhci_cap_regs {
63 __le32 hc_capbase;
64 __le32 hcs_params1;
65 __le32 hcs_params2;
66 __le32 hcs_params3;
67 __le32 hcc_params;
68 __le32 db_off;
69 __le32 run_regs_off;
70 __le32 hcc_params2;
71
72};
73
74
75
76#define HC_LENGTH(p) XHCI_HC_LENGTH(p)
77
78#define HC_VERSION(p) (((p) >> 16) & 0xffff)
79
80
81
82#define HCS_MAX_SLOTS(p) (((p) >> 0) & 0xff)
83#define HCS_SLOTS_MASK 0xff
84
85#define HCS_MAX_INTRS(p) (((p) >> 8) & 0x7ff)
86
87#define HCS_MAX_PORTS(p) (((p) >> 24) & 0x7f)
88
89
90
91
92#define HCS_IST(p) (((p) >> 0) & 0xf)
93
94#define HCS_ERST_MAX(p) (((p) >> 4) & 0xf)
95
96
97
98#define HCS_MAX_SCRATCHPAD(p) ((((p) >> 16) & 0x3e0) | (((p) >> 27) & 0x1f))
99
100
101
102#define HCS_U1_LATENCY(p) (((p) >> 0) & 0xff)
103
104#define HCS_U2_LATENCY(p) (((p) >> 16) & 0xffff)
105
106
107
108#define HCC_64BIT_ADDR(p) ((p) & (1 << 0))
109
110#define HCC_BANDWIDTH_NEG(p) ((p) & (1 << 1))
111
112
113
114#define HCC_64BYTE_CONTEXT(p) ((p) & (1 << 2))
115
116#define HCC_PPC(p) ((p) & (1 << 3))
117
118#define HCS_INDICATOR(p) ((p) & (1 << 4))
119
120#define HCC_LIGHT_RESET(p) ((p) & (1 << 5))
121
122#define HCC_LTC(p) ((p) & (1 << 6))
123
124#define HCC_NSS(p) ((p) & (1 << 7))
125
126#define HCC_SPC(p) ((p) & (1 << 9))
127
128#define HCC_CFC(p) ((p) & (1 << 11))
129
130#define HCC_MAX_PSA(p) (1 << ((((p) >> 12) & 0xf) + 1))
131
132#define HCC_EXT_CAPS(p) XHCI_HCC_EXT_CAPS(p)
133
134
135#define DBOFF_MASK (~0x3)
136
137
138#define RTSOFF_MASK (~0x1f)
139
140
141
142#define HCC2_U3C(p) ((p) & (1 << 0))
143
144#define HCC2_CMC(p) ((p) & (1 << 1))
145
146#define HCC2_FSC(p) ((p) & (1 << 2))
147
148#define HCC2_CTC(p) ((p) & (1 << 3))
149
150#define HCC2_LEC(p) ((p) & (1 << 4))
151
152#define HCC2_CIC(p) ((p) & (1 << 5))
153
154#define HCC2_ETC(p) ((p) & (1 << 6))
155
156
157#define NUM_PORT_REGS 4
158
159#define PORTSC 0
160#define PORTPMSC 1
161#define PORTLI 2
162#define PORTHLPMC 3
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186struct xhci_op_regs {
187 __le32 command;
188 __le32 status;
189 __le32 page_size;
190 __le32 reserved1;
191 __le32 reserved2;
192 __le32 dev_notification;
193 __le64 cmd_ring;
194
195 __le32 reserved3[4];
196 __le64 dcbaa_ptr;
197 __le32 config_reg;
198
199 __le32 reserved4[241];
200
201 __le32 port_status_base;
202 __le32 port_power_base;
203 __le32 port_link_base;
204 __le32 reserved5;
205
206 __le32 reserved6[NUM_PORT_REGS*254];
207};
208
209
210
211#define CMD_RUN XHCI_CMD_RUN
212
213
214
215
216#define CMD_RESET (1 << 1)
217
218#define CMD_EIE XHCI_CMD_EIE
219
220#define CMD_HSEIE XHCI_CMD_HSEIE
221
222
223#define CMD_LRESET (1 << 7)
224
225#define CMD_CSS (1 << 8)
226#define CMD_CRS (1 << 9)
227
228#define CMD_EWE XHCI_CMD_EWE
229
230
231
232
233
234#define CMD_PM_INDEX (1 << 11)
235
236#define CMD_ETE (1 << 14)
237
238
239
240#define IMAN_IE (1 << 1)
241#define IMAN_IP (1 << 0)
242
243
244
245#define STS_HALT XHCI_STS_HALT
246
247#define STS_FATAL (1 << 2)
248
249#define STS_EINT (1 << 3)
250
251#define STS_PORT (1 << 4)
252
253
254#define STS_SAVE (1 << 8)
255
256#define STS_RESTORE (1 << 9)
257
258#define STS_SRE (1 << 10)
259
260#define STS_CNR XHCI_STS_CNR
261
262#define STS_HCE (1 << 12)
263
264
265
266
267
268
269
270#define DEV_NOTE_MASK (0xffff)
271#define ENABLE_DEV_NOTE(x) (1 << (x))
272
273
274
275#define DEV_NOTE_FWAKE ENABLE_DEV_NOTE(1)
276
277
278
279
280#define CMD_RING_PAUSE (1 << 1)
281
282#define CMD_RING_ABORT (1 << 2)
283
284#define CMD_RING_RUNNING (1 << 3)
285
286
287#define CMD_RING_RSVD_BITS (0x3f)
288
289
290
291#define MAX_DEVS(p) ((p) & 0xff)
292
293#define CONFIG_U3E (1 << 8)
294
295#define CONFIG_CIE (1 << 9)
296
297
298
299
300#define PORT_CONNECT (1 << 0)
301
302#define PORT_PE (1 << 1)
303
304
305#define PORT_OC (1 << 3)
306
307#define PORT_RESET (1 << 4)
308
309
310
311
312#define PORT_PLS_MASK (0xf << 5)
313#define XDEV_U0 (0x0 << 5)
314#define XDEV_U2 (0x2 << 5)
315#define XDEV_U3 (0x3 << 5)
316#define XDEV_INACTIVE (0x6 << 5)
317#define XDEV_POLLING (0x7 << 5)
318#define XDEV_COMP_MODE (0xa << 5)
319#define XDEV_RESUME (0xf << 5)
320
321#define PORT_POWER (1 << 9)
322
323
324
325
326
327
328
329
330#define DEV_SPEED_MASK (0xf << 10)
331#define XDEV_FS (0x1 << 10)
332#define XDEV_LS (0x2 << 10)
333#define XDEV_HS (0x3 << 10)
334#define XDEV_SS (0x4 << 10)
335#define XDEV_SSP (0x5 << 10)
336#define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10))
337#define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS)
338#define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS)
339#define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS)
340#define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS)
341#define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP)
342#define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS)
343#define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f)
344
345
346#define SLOT_SPEED_FS (XDEV_FS << 10)
347#define SLOT_SPEED_LS (XDEV_LS << 10)
348#define SLOT_SPEED_HS (XDEV_HS << 10)
349#define SLOT_SPEED_SS (XDEV_SS << 10)
350#define SLOT_SPEED_SSP (XDEV_SSP << 10)
351
352#define PORT_LED_OFF (0 << 14)
353#define PORT_LED_AMBER (1 << 14)
354#define PORT_LED_GREEN (2 << 14)
355#define PORT_LED_MASK (3 << 14)
356
357#define PORT_LINK_STROBE (1 << 16)
358
359#define PORT_CSC (1 << 17)
360
361#define PORT_PEC (1 << 18)
362
363
364
365
366
367#define PORT_WRC (1 << 19)
368
369#define PORT_OCC (1 << 20)
370
371#define PORT_RC (1 << 21)
372
373
374
375
376
377
378
379
380
381
382
383
384
385#define PORT_PLC (1 << 22)
386
387#define PORT_CEC (1 << 23)
388
389
390
391
392#define PORT_CAS (1 << 24)
393
394#define PORT_WKCONN_E (1 << 25)
395
396#define PORT_WKDISC_E (1 << 26)
397
398#define PORT_WKOC_E (1 << 27)
399
400
401#define PORT_DEV_REMOVE (1 << 30)
402
403#define PORT_WR (1 << 31)
404
405
406#define DUPLICATE_ENTRY ((u8)(-1))
407
408
409
410
411
412#define PORT_U1_TIMEOUT(p) ((p) & 0xff)
413#define PORT_U1_TIMEOUT_MASK 0xff
414
415#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
416#define PORT_U2_TIMEOUT_MASK (0xff << 8)
417
418
419
420#define PORT_L1S_MASK 7
421#define PORT_L1S_SUCCESS 1
422#define PORT_RWE (1 << 3)
423#define PORT_HIRD(p) (((p) & 0xf) << 4)
424#define PORT_HIRD_MASK (0xf << 4)
425#define PORT_L1DS_MASK (0xff << 8)
426#define PORT_L1DS(p) (((p) & 0xff) << 8)
427#define PORT_HLE (1 << 16)
428
429
430#define PORT_RX_LANES(p) (((p) >> 16) & 0xf)
431#define PORT_TX_LANES(p) (((p) >> 20) & 0xf)
432
433
434#define PORT_HIRDM(p)((p) & 3)
435#define PORT_L1_TIMEOUT(p)(((p) & 0xff) << 2)
436#define PORT_BESLD(p)(((p) & 0xf) << 10)
437
438
439#define XHCI_L1_TIMEOUT 512
440
441
442
443
444
445
446
447
448
449
450
451#define XHCI_DEFAULT_BESL 4
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470struct xhci_intr_reg {
471 __le32 irq_pending;
472 __le32 irq_control;
473 __le32 erst_size;
474 __le32 rsvd;
475 __le64 erst_base;
476 __le64 erst_dequeue;
477};
478
479
480#define ER_IRQ_PENDING(p) ((p) & 0x1)
481
482
483#define ER_IRQ_CLEAR(p) ((p) & 0xfffffffe)
484#define ER_IRQ_ENABLE(p) ((ER_IRQ_CLEAR(p)) | 0x2)
485#define ER_IRQ_DISABLE(p) ((ER_IRQ_CLEAR(p)) & ~(0x2))
486
487
488
489
490
491
492#define ER_IRQ_INTERVAL_MASK (0xffff)
493
494#define ER_IRQ_COUNTER_MASK (0xffff << 16)
495
496
497
498#define ERST_SIZE_MASK (0xffff << 16)
499
500
501
502
503
504#define ERST_DESI_MASK (0x7)
505
506
507
508#define ERST_EHB (1 << 3)
509#define ERST_PTR_MASK (0xf)
510
511
512
513
514
515
516
517
518
519
520struct xhci_run_regs {
521 __le32 microframe_index;
522 __le32 rsvd[7];
523 struct xhci_intr_reg ir_set[128];
524};
525
526
527
528
529
530
531
532
533
534
535struct xhci_doorbell_array {
536 __le32 doorbell[256];
537};
538
539#define DB_VALUE(ep, stream) ((((ep) + 1) & 0xff) | ((stream) << 16))
540#define DB_VALUE_HOST 0x00000000
541
542
543
544
545
546
547
548
549
550struct xhci_protocol_caps {
551 u32 revision;
552 u32 name_string;
553 u32 port_info;
554};
555
556#define XHCI_EXT_PORT_MAJOR(x) (((x) >> 24) & 0xff)
557#define XHCI_EXT_PORT_MINOR(x) (((x) >> 16) & 0xff)
558#define XHCI_EXT_PORT_PSIC(x) (((x) >> 28) & 0x0f)
559#define XHCI_EXT_PORT_OFF(x) ((x) & 0xff)
560#define XHCI_EXT_PORT_COUNT(x) (((x) >> 8) & 0xff)
561
562#define XHCI_EXT_PORT_PSIV(x) (((x) >> 0) & 0x0f)
563#define XHCI_EXT_PORT_PSIE(x) (((x) >> 4) & 0x03)
564#define XHCI_EXT_PORT_PLT(x) (((x) >> 6) & 0x03)
565#define XHCI_EXT_PORT_PFD(x) (((x) >> 8) & 0x01)
566#define XHCI_EXT_PORT_LP(x) (((x) >> 14) & 0x03)
567#define XHCI_EXT_PORT_PSIM(x) (((x) >> 16) & 0xffff)
568
569#define PLT_MASK (0x03 << 6)
570#define PLT_SYM (0x00 << 6)
571#define PLT_ASYM_RX (0x02 << 6)
572#define PLT_ASYM_TX (0x03 << 6)
573
574
575
576
577
578
579
580
581
582
583
584struct xhci_container_ctx {
585 unsigned type;
586#define XHCI_CTX_TYPE_DEVICE 0x1
587#define XHCI_CTX_TYPE_INPUT 0x2
588
589 int size;
590
591 u8 *bytes;
592 dma_addr_t dma;
593};
594
595
596
597
598
599
600
601
602
603
604
605
606struct xhci_slot_ctx {
607 __le32 dev_info;
608 __le32 dev_info2;
609 __le32 tt_info;
610 __le32 dev_state;
611
612 __le32 reserved[4];
613};
614
615
616
617#define ROUTE_STRING_MASK (0xfffff)
618
619#define DEV_SPEED (0xf << 20)
620
621
622#define DEV_MTT (0x1 << 25)
623
624#define DEV_HUB (0x1 << 26)
625
626#define LAST_CTX_MASK (0x1f << 27)
627#define LAST_CTX(p) ((p) << 27)
628#define LAST_CTX_TO_EP_NUM(p) (((p) >> 27) - 1)
629#define SLOT_FLAG (1 << 0)
630#define EP0_FLAG (1 << 1)
631
632
633
634#define MAX_EXIT (0xffff)
635
636#define ROOT_HUB_PORT(p) (((p) & 0xff) << 16)
637#define DEVINFO_TO_ROOT_HUB_PORT(p) (((p) >> 16) & 0xff)
638
639#define XHCI_MAX_PORTS(p) (((p) & 0xff) << 24)
640
641
642
643
644
645
646
647#define TT_SLOT (0xff)
648
649
650
651
652#define TT_PORT (0xff << 8)
653#define TT_THINK_TIME(p) (((p) & 0x3) << 16)
654
655
656
657#define DEV_ADDR_MASK (0xff)
658
659
660#define SLOT_STATE (0x1f << 27)
661#define GET_SLOT_STATE(p) (((p) & (0x1f << 27)) >> 27)
662
663#define SLOT_STATE_DISABLED 0
664#define SLOT_STATE_ENABLED SLOT_STATE_DISABLED
665#define SLOT_STATE_DEFAULT 1
666#define SLOT_STATE_ADDRESSED 2
667#define SLOT_STATE_CONFIGURED 3
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687struct xhci_ep_ctx {
688 __le32 ep_info;
689 __le32 ep_info2;
690 __le64 deq;
691 __le32 tx_info;
692
693 __le32 reserved[3];
694};
695
696
697
698
699
700
701
702
703
704
705
706#define EP_STATE_MASK (0xf)
707#define EP_STATE_DISABLED 0
708#define EP_STATE_RUNNING 1
709#define EP_STATE_HALTED 2
710#define EP_STATE_STOPPED 3
711#define EP_STATE_ERROR 4
712
713#define EP_MULT(p) (((p) & 0x3) << 8)
714#define CTX_TO_EP_MULT(p) (((p) >> 8) & 0x3)
715
716
717
718#define EP_INTERVAL(p) (((p) & 0xff) << 16)
719#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff))
720#define CTX_TO_EP_INTERVAL(p) (((p) >> 16) & 0xff)
721#define EP_MAXPSTREAMS_MASK (0x1f << 10)
722#define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK)
723
724#define EP_HAS_LSA (1 << 15)
725
726
727
728
729
730
731#define FORCE_EVENT (0x1)
732#define ERROR_COUNT(p) (((p) & 0x3) << 1)
733#define CTX_TO_EP_TYPE(p) (((p) >> 3) & 0x7)
734#define EP_TYPE(p) ((p) << 3)
735#define ISOC_OUT_EP 1
736#define BULK_OUT_EP 2
737#define INT_OUT_EP 3
738#define CTRL_EP 4
739#define ISOC_IN_EP 5
740#define BULK_IN_EP 6
741#define INT_IN_EP 7
742
743
744#define MAX_BURST(p) (((p)&0xff) << 8)
745#define CTX_TO_MAX_BURST(p) (((p) >> 8) & 0xff)
746#define MAX_PACKET(p) (((p)&0xffff) << 16)
747#define MAX_PACKET_MASK (0xffff << 16)
748#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff)
749
750
751
752
753#define GET_MAX_PACKET(p) ((p) & 0x7ff)
754
755
756#define EP_AVG_TRB_LENGTH(p) ((p) & 0xffff)
757#define EP_MAX_ESIT_PAYLOAD_LO(p) (((p) & 0xffff) << 16)
758#define EP_MAX_ESIT_PAYLOAD_HI(p) ((((p) >> 16) & 0xff) << 24)
759#define CTX_TO_MAX_ESIT_PAYLOAD(p) (((p) >> 16) & 0xffff)
760
761
762#define EP_CTX_CYCLE_MASK (1 << 0)
763#define SCTX_DEQ_MASK (~0xfL)
764
765
766
767
768
769
770
771
772
773struct xhci_input_control_ctx {
774 __le32 drop_flags;
775 __le32 add_flags;
776 __le32 rsvd2[6];
777};
778
779#define EP_IS_ADDED(ctrl_ctx, i) \
780 (le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1)))
781#define EP_IS_DROPPED(ctrl_ctx, i) \
782 (le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1)))
783
784
785
786
787
788struct xhci_command {
789
790 struct xhci_container_ctx *in_ctx;
791 u32 status;
792
793
794
795 struct completion *completion;
796 union xhci_trb *command_trb;
797 struct list_head cmd_list;
798};
799
800
801#define DROP_EP(x) (0x1 << x)
802
803#define ADD_EP(x) (0x1 << x)
804
805struct xhci_stream_ctx {
806
807 __le64 stream_ring;
808
809 __le32 reserved[2];
810};
811
812
813#define SCT_FOR_CTX(p) (((p) & 0x7) << 1)
814
815#define SCT_SEC_TR 0
816
817#define SCT_PRI_TR 1
818
819#define SCT_SSA_8 2
820#define SCT_SSA_16 3
821#define SCT_SSA_32 4
822#define SCT_SSA_64 5
823#define SCT_SSA_128 6
824#define SCT_SSA_256 7
825
826
827struct xhci_stream_info {
828 struct xhci_ring **stream_rings;
829
830 unsigned int num_streams;
831
832
833
834 struct xhci_stream_ctx *stream_ctx_array;
835 unsigned int num_stream_ctxs;
836 dma_addr_t ctx_array_dma;
837
838 struct radix_tree_root trb_address_map;
839 struct xhci_command *free_streams_command;
840};
841
842#define SMALL_STREAM_ARRAY_SIZE 256
843#define MEDIUM_STREAM_ARRAY_SIZE 1024
844
845
846
847
848
849
850
851struct xhci_bw_info {
852
853 unsigned int ep_interval;
854
855 unsigned int mult;
856 unsigned int num_packets;
857 unsigned int max_packet_size;
858 unsigned int max_esit_payload;
859 unsigned int type;
860};
861
862
863
864
865
866
867#define FS_BLOCK 1
868#define HS_BLOCK 4
869#define SS_BLOCK 16
870#define DMI_BLOCK 32
871
872
873
874
875
876
877#define DMI_OVERHEAD 8
878#define DMI_OVERHEAD_BURST 4
879#define SS_OVERHEAD 8
880#define SS_OVERHEAD_BURST 32
881#define HS_OVERHEAD 26
882#define FS_OVERHEAD 20
883#define LS_OVERHEAD 128
884
885
886
887
888
889#define TT_HS_OVERHEAD (31 + 94)
890#define TT_DMI_OVERHEAD (25 + 12)
891
892
893#define FS_BW_LIMIT 1285
894#define TT_BW_LIMIT 1320
895#define HS_BW_LIMIT 1607
896#define SS_BW_LIMIT_IN 3906
897#define DMI_BW_LIMIT_IN 3906
898#define SS_BW_LIMIT_OUT 3906
899#define DMI_BW_LIMIT_OUT 3906
900
901
902#define FS_BW_RESERVED 10
903#define HS_BW_RESERVED 20
904#define SS_BW_RESERVED 10
905
906struct xhci_virt_ep {
907 struct xhci_ring *ring;
908
909 struct xhci_stream_info *stream_info;
910
911
912
913 struct xhci_ring *new_ring;
914 unsigned int ep_state;
915#define SET_DEQ_PENDING (1 << 0)
916#define EP_HALTED (1 << 1)
917#define EP_HALT_PENDING (1 << 2)
918
919#define EP_GETTING_STREAMS (1 << 3)
920#define EP_HAS_STREAMS (1 << 4)
921
922#define EP_GETTING_NO_STREAMS (1 << 5)
923
924 struct list_head cancelled_td_list;
925 struct xhci_td *stopped_td;
926 unsigned int stopped_stream;
927
928 struct timer_list stop_cmd_timer;
929 int stop_cmds_pending;
930 struct xhci_hcd *xhci;
931
932
933
934
935 struct xhci_segment *queued_deq_seg;
936 union xhci_trb *queued_deq_ptr;
937
938
939
940
941
942
943
944 bool skip;
945
946 struct xhci_bw_info bw_info;
947 struct list_head bw_endpoint_list;
948
949 int next_frame_id;
950
951 bool use_extended_tbc;
952};
953
954enum xhci_overhead_type {
955 LS_OVERHEAD_TYPE = 0,
956 FS_OVERHEAD_TYPE,
957 HS_OVERHEAD_TYPE,
958};
959
960struct xhci_interval_bw {
961 unsigned int num_packets;
962
963
964
965 struct list_head endpoints;
966
967 unsigned int overhead[3];
968};
969
970#define XHCI_MAX_INTERVAL 16
971
972struct xhci_interval_bw_table {
973 unsigned int interval0_esit_payload;
974 struct xhci_interval_bw interval_bw[XHCI_MAX_INTERVAL];
975
976 unsigned int bw_used;
977 unsigned int ss_bw_in;
978 unsigned int ss_bw_out;
979};
980
981
982struct xhci_virt_device {
983 struct usb_device *udev;
984
985
986
987
988
989
990
991
992 struct xhci_container_ctx *out_ctx;
993
994 struct xhci_container_ctx *in_ctx;
995
996 struct xhci_ring **ring_cache;
997 int num_rings_cached;
998#define XHCI_MAX_RINGS_CACHED 31
999 struct xhci_virt_ep eps[31];
1000 struct completion cmd_completion;
1001 u8 fake_port;
1002 u8 real_port;
1003 struct xhci_interval_bw_table *bw_table;
1004 struct xhci_tt_bw_info *tt_info;
1005
1006 u16 current_mel;
1007};
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017struct xhci_root_port_bw_info {
1018 struct list_head tts;
1019 unsigned int num_active_tts;
1020 struct xhci_interval_bw_table bw_table;
1021};
1022
1023struct xhci_tt_bw_info {
1024 struct list_head tt_list;
1025 int slot_id;
1026 int ttport;
1027 struct xhci_interval_bw_table bw_table;
1028 int active_eps;
1029};
1030
1031
1032
1033
1034
1035
1036struct xhci_device_context_array {
1037
1038 __le64 dev_context_ptrs[MAX_HC_SLOTS];
1039
1040 dma_addr_t dma;
1041};
1042
1043
1044
1045
1046
1047
1048
1049struct xhci_transfer_event {
1050
1051 __le64 buffer;
1052 __le32 transfer_len;
1053
1054 __le32 flags;
1055};
1056
1057
1058
1059#define EVENT_TRB_LEN(p) ((p) & 0xffffff)
1060
1061
1062#define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f)
1063
1064
1065#define COMP_CODE_MASK (0xff << 24)
1066#define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24)
1067#define COMP_SUCCESS 1
1068
1069#define COMP_DB_ERR 2
1070
1071#define COMP_BABBLE 3
1072
1073#define COMP_TX_ERR 4
1074
1075#define COMP_TRB_ERR 5
1076
1077#define COMP_STALL 6
1078
1079#define COMP_ENOMEM 7
1080
1081#define COMP_BW_ERR 8
1082
1083#define COMP_ENOSLOTS 9
1084
1085#define COMP_STREAM_ERR 10
1086
1087#define COMP_EBADSLT 11
1088
1089#define COMP_EBADEP 12
1090
1091#define COMP_SHORT_TX 13
1092
1093#define COMP_UNDERRUN 14
1094
1095#define COMP_OVERRUN 15
1096
1097#define COMP_VF_FULL 16
1098
1099#define COMP_EINVAL 17
1100
1101#define COMP_BW_OVER 18
1102
1103#define COMP_CTX_STATE 19
1104
1105#define COMP_PING_ERR 20
1106
1107#define COMP_ER_FULL 21
1108
1109#define COMP_DEV_ERR 22
1110
1111#define COMP_MISSED_INT 23
1112
1113#define COMP_CMD_STOP 24
1114
1115#define COMP_CMD_ABORT 25
1116
1117#define COMP_STOP 26
1118
1119#define COMP_STOP_INVAL 27
1120
1121#define COMP_STOP_SHORT 28
1122
1123#define COMP_MEL_ERR 29
1124
1125
1126#define COMP_BUFF_OVER 31
1127
1128#define COMP_ISSUES 32
1129
1130#define COMP_UNKNOWN 33
1131
1132#define COMP_STRID_ERR 34
1133
1134#define COMP_2ND_BW_ERR 35
1135
1136#define COMP_SPLIT_ERR 36
1137
1138struct xhci_link_trb {
1139
1140 __le64 segment_ptr;
1141 __le32 intr_target;
1142 __le32 control;
1143};
1144
1145
1146#define LINK_TOGGLE (0x1<<1)
1147
1148
1149struct xhci_event_cmd {
1150
1151 __le64 cmd_trb;
1152 __le32 status;
1153 __le32 flags;
1154};
1155
1156
1157
1158
1159#define TRB_BSR (1<<9)
1160enum xhci_setup_dev {
1161 SETUP_CONTEXT_ONLY,
1162 SETUP_CONTEXT_ADDRESS,
1163};
1164
1165
1166
1167#define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24)
1168#define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24)
1169
1170
1171#define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1)
1172#define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16)
1173
1174#define SUSPEND_PORT_FOR_TRB(p) (((p) & 1) << 23)
1175#define TRB_TO_SUSPEND_PORT(p) (((p) & (1 << 23)) >> 23)
1176#define LAST_EP_INDEX 30
1177
1178
1179#define TRB_TO_STREAM_ID(p) ((((p) & (0xffff << 16)) >> 16))
1180#define STREAM_ID_FOR_TRB(p) ((((p)) & 0xffff) << 16)
1181#define SCT_FOR_TRB(p) (((p) << 1) & 0x7)
1182
1183
1184
1185
1186#define GET_PORT_ID(p) (((p) & (0xff << 24)) >> 24)
1187
1188
1189
1190#define TRB_LEN(p) ((p) & 0x1ffff)
1191
1192#define TRB_TD_SIZE(p) (min((p), (u32)31) << 17)
1193
1194#define TRB_TD_SIZE_TBC(p) (min((p), (u32)31) << 17)
1195
1196#define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
1197#define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
1198
1199#define TRB_TBC(p) (((p) & 0x3) << 7)
1200#define TRB_TLBPC(p) (((p) & 0xf) << 16)
1201
1202
1203#define TRB_CYCLE (1<<0)
1204
1205
1206
1207
1208#define TRB_ENT (1<<1)
1209
1210#define TRB_ISP (1<<2)
1211
1212#define TRB_NO_SNOOP (1<<3)
1213
1214#define TRB_CHAIN (1<<4)
1215
1216#define TRB_IOC (1<<5)
1217
1218#define TRB_IDT (1<<6)
1219
1220
1221#define TRB_BEI (1<<9)
1222
1223
1224#define TRB_DIR_IN (1<<16)
1225#define TRB_TX_TYPE(p) ((p) << 16)
1226#define TRB_DATA_OUT 2
1227#define TRB_DATA_IN 3
1228
1229
1230#define TRB_SIA (1<<31)
1231#define TRB_FRAME_ID(p) (((p) & 0x7ff) << 20)
1232
1233struct xhci_generic_trb {
1234 __le32 field[4];
1235};
1236
1237union xhci_trb {
1238 struct xhci_link_trb link;
1239 struct xhci_transfer_event trans_event;
1240 struct xhci_event_cmd event_cmd;
1241 struct xhci_generic_trb generic;
1242};
1243
1244
1245#define TRB_TYPE_BITMASK (0xfc00)
1246#define TRB_TYPE(p) ((p) << 10)
1247#define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10)
1248
1249
1250#define TRB_NORMAL 1
1251
1252#define TRB_SETUP 2
1253
1254#define TRB_DATA 3
1255
1256#define TRB_STATUS 4
1257
1258#define TRB_ISOC 5
1259
1260#define TRB_LINK 6
1261#define TRB_EVENT_DATA 7
1262
1263#define TRB_TR_NOOP 8
1264
1265
1266#define TRB_ENABLE_SLOT 9
1267
1268#define TRB_DISABLE_SLOT 10
1269
1270#define TRB_ADDR_DEV 11
1271
1272#define TRB_CONFIG_EP 12
1273
1274#define TRB_EVAL_CONTEXT 13
1275
1276#define TRB_RESET_EP 14
1277
1278#define TRB_STOP_RING 15
1279
1280#define TRB_SET_DEQ 16
1281
1282#define TRB_RESET_DEV 17
1283
1284#define TRB_FORCE_EVENT 18
1285
1286#define TRB_NEG_BANDWIDTH 19
1287
1288#define TRB_SET_LT 20
1289
1290#define TRB_GET_BW 21
1291
1292#define TRB_FORCE_HEADER 22
1293
1294#define TRB_CMD_NOOP 23
1295
1296
1297
1298#define TRB_TRANSFER 32
1299
1300#define TRB_COMPLETION 33
1301
1302#define TRB_PORT_STATUS 34
1303
1304#define TRB_BANDWIDTH_EVENT 35
1305
1306#define TRB_DOORBELL 36
1307
1308#define TRB_HC_EVENT 37
1309
1310#define TRB_DEV_NOTE 38
1311
1312#define TRB_MFINDEX_WRAP 39
1313
1314
1315
1316#define TRB_NEC_CMD_COMP 48
1317
1318#define TRB_NEC_GET_FW 49
1319
1320#define TRB_TYPE_LINK(x) (((x) & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
1321
1322#define TRB_TYPE_LINK_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
1323 cpu_to_le32(TRB_TYPE(TRB_LINK)))
1324#define TRB_TYPE_NOOP_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
1325 cpu_to_le32(TRB_TYPE(TRB_TR_NOOP)))
1326
1327#define NEC_FW_MINOR(p) (((p) >> 0) & 0xff)
1328#define NEC_FW_MAJOR(p) (((p) >> 8) & 0xff)
1329
1330
1331
1332
1333
1334
1335#define TRBS_PER_SEGMENT 256
1336
1337#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
1338#define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
1339#define TRB_SEGMENT_SHIFT (ilog2(TRB_SEGMENT_SIZE))
1340
1341#define TRB_MAX_BUFF_SHIFT 16
1342#define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT)
1343
1344#define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr) (TRB_MAX_BUFF_SIZE - \
1345 (addr & (TRB_MAX_BUFF_SIZE - 1)))
1346
1347struct xhci_segment {
1348 union xhci_trb *trbs;
1349
1350 struct xhci_segment *next;
1351 dma_addr_t dma;
1352
1353 dma_addr_t bounce_dma;
1354 void *bounce_buf;
1355 unsigned int bounce_offs;
1356 unsigned int bounce_len;
1357};
1358
1359struct xhci_td {
1360 struct list_head td_list;
1361 struct list_head cancelled_td_list;
1362 struct urb *urb;
1363 struct xhci_segment *start_seg;
1364 union xhci_trb *first_trb;
1365 union xhci_trb *last_trb;
1366 struct xhci_segment *bounce_seg;
1367
1368 bool urb_length_set;
1369};
1370
1371
1372#define XHCI_CMD_DEFAULT_TIMEOUT (5 * HZ)
1373
1374
1375struct xhci_cd {
1376 struct xhci_command *command;
1377 union xhci_trb *cmd_trb;
1378};
1379
1380struct xhci_dequeue_state {
1381 struct xhci_segment *new_deq_seg;
1382 union xhci_trb *new_deq_ptr;
1383 int new_cycle_state;
1384};
1385
1386enum xhci_ring_type {
1387 TYPE_CTRL = 0,
1388 TYPE_ISOC,
1389 TYPE_BULK,
1390 TYPE_INTR,
1391 TYPE_STREAM,
1392 TYPE_COMMAND,
1393 TYPE_EVENT,
1394};
1395
1396struct xhci_ring {
1397 struct xhci_segment *first_seg;
1398 struct xhci_segment *last_seg;
1399 union xhci_trb *enqueue;
1400 struct xhci_segment *enq_seg;
1401 unsigned int enq_updates;
1402 union xhci_trb *dequeue;
1403 struct xhci_segment *deq_seg;
1404 unsigned int deq_updates;
1405 struct list_head td_list;
1406
1407
1408
1409
1410
1411 u32 cycle_state;
1412 unsigned int stream_id;
1413 unsigned int num_segs;
1414 unsigned int num_trbs_free;
1415 unsigned int num_trbs_free_temp;
1416 unsigned int bounce_buf_len;
1417 enum xhci_ring_type type;
1418 bool last_td_was_short;
1419 struct radix_tree_root *trb_address_map;
1420};
1421
1422struct xhci_erst_entry {
1423
1424 __le64 seg_addr;
1425 __le32 seg_size;
1426
1427 __le32 rsvd;
1428};
1429
1430struct xhci_erst {
1431 struct xhci_erst_entry *entries;
1432 unsigned int num_entries;
1433
1434 dma_addr_t erst_dma_addr;
1435
1436 unsigned int erst_size;
1437};
1438
1439struct xhci_scratchpad {
1440 u64 *sp_array;
1441 dma_addr_t sp_dma;
1442 void **sp_buffers;
1443 dma_addr_t *sp_dma_buffers;
1444};
1445
1446struct urb_priv {
1447 int length;
1448 int td_cnt;
1449 struct xhci_td *td[0];
1450};
1451
1452
1453
1454
1455
1456
1457#define ERST_NUM_SEGS 1
1458
1459#define ERST_SIZE 64
1460
1461#define ERST_ENTRIES 1
1462
1463#define POLL_TIMEOUT 60
1464
1465#define XHCI_STOP_EP_CMD_TIMEOUT 5
1466
1467
1468struct s3_save {
1469 u32 command;
1470 u32 dev_nt;
1471 u64 dcbaa_ptr;
1472 u32 config_reg;
1473 u32 irq_pending;
1474 u32 irq_control;
1475 u32 erst_size;
1476 u64 erst_base;
1477 u64 erst_dequeue;
1478};
1479
1480
1481struct dev_info {
1482 u32 dev_id;
1483 struct list_head list;
1484};
1485
1486struct xhci_bus_state {
1487 unsigned long bus_suspended;
1488 unsigned long next_statechange;
1489
1490
1491
1492 u32 port_c_suspend;
1493 u32 suspended_ports;
1494 u32 port_remote_wakeup;
1495 unsigned long resume_done[USB_MAXCHILDREN];
1496
1497 unsigned long resuming_ports;
1498
1499 unsigned long rexit_ports;
1500 struct completion rexit_done[USB_MAXCHILDREN];
1501};
1502
1503
1504
1505
1506
1507
1508#define XHCI_MAX_REXIT_TIMEOUT (20 * 1000)
1509
1510static inline unsigned int hcd_index(struct usb_hcd *hcd)
1511{
1512 if (hcd->speed == HCD_USB3)
1513 return 0;
1514 else
1515 return 1;
1516}
1517
1518struct xhci_hub {
1519 u8 maj_rev;
1520 u8 min_rev;
1521 u32 *psi;
1522 u8 psi_count;
1523 u8 psi_uid_count;
1524};
1525
1526
1527struct xhci_hcd {
1528 struct usb_hcd *main_hcd;
1529 struct usb_hcd *shared_hcd;
1530
1531 struct xhci_cap_regs __iomem *cap_regs;
1532 struct xhci_op_regs __iomem *op_regs;
1533 struct xhci_run_regs __iomem *run_regs;
1534 struct xhci_doorbell_array __iomem *dba;
1535
1536 struct xhci_intr_reg __iomem *ir_set;
1537
1538
1539 __u32 hcs_params1;
1540 __u32 hcs_params2;
1541 __u32 hcs_params3;
1542 __u32 hcc_params;
1543 __u32 hcc_params2;
1544
1545 spinlock_t lock;
1546
1547
1548 u8 sbrn;
1549 u16 hci_version;
1550 u8 max_slots;
1551 u8 max_interrupters;
1552 u8 max_ports;
1553 u8 isoc_threshold;
1554 int event_ring_max;
1555 int addr_64;
1556
1557 int page_size;
1558
1559 int page_shift;
1560
1561 int msix_count;
1562 struct msix_entry *msix_entries;
1563
1564 struct clk *clk;
1565
1566 struct xhci_device_context_array *dcbaa;
1567 struct xhci_ring *cmd_ring;
1568 unsigned int cmd_ring_state;
1569#define CMD_RING_STATE_RUNNING (1 << 0)
1570#define CMD_RING_STATE_ABORTED (1 << 1)
1571#define CMD_RING_STATE_STOPPED (1 << 2)
1572 struct list_head cmd_list;
1573 unsigned int cmd_ring_reserved_trbs;
1574 struct timer_list cmd_timer;
1575 struct xhci_command *current_cmd;
1576 struct xhci_ring *event_ring;
1577 struct xhci_erst erst;
1578
1579 struct xhci_scratchpad *scratchpad;
1580
1581 struct list_head lpm_failed_devs;
1582
1583
1584
1585 struct mutex mutex;
1586 struct completion addr_dev;
1587 int slot_id;
1588
1589 struct xhci_command *lpm_command;
1590
1591 struct xhci_virt_device *devs[MAX_HC_SLOTS];
1592
1593 struct xhci_root_port_bw_info *rh_bw;
1594
1595
1596 struct dma_pool *device_pool;
1597 struct dma_pool *segment_pool;
1598 struct dma_pool *small_streams_pool;
1599 struct dma_pool *medium_streams_pool;
1600
1601
1602 unsigned int xhc_state;
1603
1604 u32 command;
1605 struct s3_save s3;
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618#define XHCI_STATE_DYING (1 << 0)
1619#define XHCI_STATE_HALTED (1 << 1)
1620#define XHCI_STATE_REMOVING (1 << 2)
1621
1622 int error_bitmask;
1623 unsigned int quirks;
1624#define XHCI_LINK_TRB_QUIRK (1 << 0)
1625#define XHCI_RESET_EP_QUIRK (1 << 1)
1626#define XHCI_NEC_HOST (1 << 2)
1627#define XHCI_AMD_PLL_FIX (1 << 3)
1628#define XHCI_SPURIOUS_SUCCESS (1 << 4)
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638#define XHCI_EP_LIMIT_QUIRK (1 << 5)
1639#define XHCI_BROKEN_MSI (1 << 6)
1640#define XHCI_RESET_ON_RESUME (1 << 7)
1641#define XHCI_SW_BW_CHECKING (1 << 8)
1642#define XHCI_AMD_0x96_HOST (1 << 9)
1643#define XHCI_TRUST_TX_LENGTH (1 << 10)
1644#define XHCI_LPM_SUPPORT (1 << 11)
1645#define XHCI_INTEL_HOST (1 << 12)
1646#define XHCI_SPURIOUS_REBOOT (1 << 13)
1647#define XHCI_COMP_MODE_QUIRK (1 << 14)
1648#define XHCI_AVOID_BEI (1 << 15)
1649#define XHCI_PLAT (1 << 16)
1650#define XHCI_SLOW_SUSPEND (1 << 17)
1651#define XHCI_SPURIOUS_WAKEUP (1 << 18)
1652
1653#define XHCI_BROKEN_STREAMS (1 << 19)
1654#define XHCI_PME_STUCK_QUIRK (1 << 20)
1655#define XHCI_MTK_HOST (1 << 21)
1656#define XHCI_SSIC_PORT_UNUSED (1 << 22)
1657#define XHCI_NO_64BIT_SUPPORT (1 << 23)
1658#define XHCI_MISSING_CAS (1 << 24)
1659 unsigned int num_active_eps;
1660 unsigned int limit_active_eps;
1661
1662 struct xhci_bus_state bus_state[2];
1663
1664 u8 *port_array;
1665
1666 __le32 __iomem **usb3_ports;
1667 unsigned int num_usb3_ports;
1668
1669 __le32 __iomem **usb2_ports;
1670 struct xhci_hub usb2_rhub;
1671 struct xhci_hub usb3_rhub;
1672 unsigned int num_usb2_ports;
1673
1674 unsigned sw_lpm_support:1;
1675
1676 unsigned hw_lpm_support:1;
1677
1678 u32 *ext_caps;
1679 unsigned int num_ext_caps;
1680
1681 struct timer_list comp_mode_recovery_timer;
1682 u32 port_status_u0;
1683
1684#define COMP_MODE_RCVRY_MSECS 2000
1685
1686
1687 unsigned long priv[0] __aligned(sizeof(s64));
1688};
1689
1690
1691struct xhci_driver_overrides {
1692 size_t extra_priv_size;
1693 int (*reset)(struct usb_hcd *hcd);
1694 int (*start)(struct usb_hcd *hcd);
1695};
1696
1697#define XHCI_CFC_DELAY 10
1698
1699
1700static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd)
1701{
1702 struct usb_hcd *primary_hcd;
1703
1704 if (usb_hcd_is_primary_hcd(hcd))
1705 primary_hcd = hcd;
1706 else
1707 primary_hcd = hcd->primary_hcd;
1708
1709 return (struct xhci_hcd *) (primary_hcd->hcd_priv);
1710}
1711
1712static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
1713{
1714 return xhci->main_hcd;
1715}
1716
1717#define xhci_dbg(xhci, fmt, args...) \
1718 dev_dbg(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1719#define xhci_err(xhci, fmt, args...) \
1720 dev_err(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1721#define xhci_warn(xhci, fmt, args...) \
1722 dev_warn(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1723#define xhci_warn_ratelimited(xhci, fmt, args...) \
1724 dev_warn_ratelimited(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1725#define xhci_info(xhci, fmt, args...) \
1726 dev_info(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737static inline u64 xhci_read_64(const struct xhci_hcd *xhci,
1738 __le64 __iomem *regs)
1739{
1740 return lo_hi_readq(regs);
1741}
1742static inline void xhci_write_64(struct xhci_hcd *xhci,
1743 const u64 val, __le64 __iomem *regs)
1744{
1745 lo_hi_writeq(val, regs);
1746}
1747
1748static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci)
1749{
1750 return xhci->quirks & XHCI_LINK_TRB_QUIRK;
1751}
1752
1753
1754void xhci_print_ir_set(struct xhci_hcd *xhci, int set_num);
1755void xhci_print_registers(struct xhci_hcd *xhci);
1756void xhci_dbg_regs(struct xhci_hcd *xhci);
1757void xhci_print_run_regs(struct xhci_hcd *xhci);
1758void xhci_print_trb_offsets(struct xhci_hcd *xhci, union xhci_trb *trb);
1759void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb);
1760void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg);
1761void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring);
1762void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
1763void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci);
1764void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring);
1765void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int last_ep);
1766char *xhci_get_slot_state(struct xhci_hcd *xhci,
1767 struct xhci_container_ctx *ctx);
1768void xhci_dbg_ep_rings(struct xhci_hcd *xhci,
1769 unsigned int slot_id, unsigned int ep_index,
1770 struct xhci_virt_ep *ep);
1771void xhci_dbg_trace(struct xhci_hcd *xhci, void (*trace)(struct va_format *),
1772 const char *fmt, ...);
1773
1774
1775void xhci_mem_cleanup(struct xhci_hcd *xhci);
1776int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags);
1777void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id);
1778int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device *udev, gfp_t flags);
1779int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev);
1780void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci,
1781 struct usb_device *udev);
1782unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc);
1783unsigned int xhci_get_endpoint_address(unsigned int ep_index);
1784unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc);
1785unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index);
1786unsigned int xhci_last_valid_endpoint(u32 added_ctxs);
1787void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep);
1788void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci,
1789 struct xhci_bw_info *ep_bw,
1790 struct xhci_interval_bw_table *bw_table,
1791 struct usb_device *udev,
1792 struct xhci_virt_ep *virt_ep,
1793 struct xhci_tt_bw_info *tt_info);
1794void xhci_update_tt_active_eps(struct xhci_hcd *xhci,
1795 struct xhci_virt_device *virt_dev,
1796 int old_active_eps);
1797void xhci_clear_endpoint_bw_info(struct xhci_bw_info *bw_info);
1798void xhci_update_bw_info(struct xhci_hcd *xhci,
1799 struct xhci_container_ctx *in_ctx,
1800 struct xhci_input_control_ctx *ctrl_ctx,
1801 struct xhci_virt_device *virt_dev);
1802void xhci_endpoint_copy(struct xhci_hcd *xhci,
1803 struct xhci_container_ctx *in_ctx,
1804 struct xhci_container_ctx *out_ctx,
1805 unsigned int ep_index);
1806void xhci_slot_copy(struct xhci_hcd *xhci,
1807 struct xhci_container_ctx *in_ctx,
1808 struct xhci_container_ctx *out_ctx);
1809int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev,
1810 struct usb_device *udev, struct usb_host_endpoint *ep,
1811 gfp_t mem_flags);
1812void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring);
1813int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
1814 unsigned int num_trbs, gfp_t flags);
1815void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci,
1816 struct xhci_virt_device *virt_dev,
1817 unsigned int ep_index);
1818struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
1819 unsigned int num_stream_ctxs,
1820 unsigned int num_streams,
1821 unsigned int max_packet, gfp_t flags);
1822void xhci_free_stream_info(struct xhci_hcd *xhci,
1823 struct xhci_stream_info *stream_info);
1824void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci,
1825 struct xhci_ep_ctx *ep_ctx,
1826 struct xhci_stream_info *stream_info);
1827void xhci_setup_no_streams_ep_input_ctx(struct xhci_ep_ctx *ep_ctx,
1828 struct xhci_virt_ep *ep);
1829void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci,
1830 struct xhci_virt_device *virt_dev, bool drop_control_ep);
1831struct xhci_ring *xhci_dma_to_transfer_ring(
1832 struct xhci_virt_ep *ep,
1833 u64 address);
1834struct xhci_ring *xhci_stream_id_to_ring(
1835 struct xhci_virt_device *dev,
1836 unsigned int ep_index,
1837 unsigned int stream_id);
1838struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1839 bool allocate_in_ctx, bool allocate_completion,
1840 gfp_t mem_flags);
1841void xhci_urb_free_priv(struct urb_priv *urb_priv);
1842void xhci_free_command(struct xhci_hcd *xhci,
1843 struct xhci_command *command);
1844
1845
1846typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *);
1847int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, int usec);
1848void xhci_quiesce(struct xhci_hcd *xhci);
1849int xhci_halt(struct xhci_hcd *xhci);
1850int xhci_reset(struct xhci_hcd *xhci);
1851int xhci_init(struct usb_hcd *hcd);
1852int xhci_run(struct usb_hcd *hcd);
1853void xhci_stop(struct usb_hcd *hcd);
1854void xhci_shutdown(struct usb_hcd *hcd);
1855int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
1856void xhci_init_driver(struct hc_driver *drv,
1857 const struct xhci_driver_overrides *over);
1858
1859#ifdef CONFIG_PM
1860int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup);
1861int xhci_resume(struct xhci_hcd *xhci, bool hibernated);
1862#else
1863#define xhci_suspend NULL
1864#define xhci_resume NULL
1865#endif
1866
1867int xhci_get_frame(struct usb_hcd *hcd);
1868irqreturn_t xhci_irq(struct usb_hcd *hcd);
1869irqreturn_t xhci_msi_irq(int irq, void *hcd);
1870int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
1871void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
1872int xhci_alloc_tt_info(struct xhci_hcd *xhci,
1873 struct xhci_virt_device *virt_dev,
1874 struct usb_device *hdev,
1875 struct usb_tt *tt, gfp_t mem_flags);
1876int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev,
1877 struct usb_host_endpoint **eps, unsigned int num_eps,
1878 unsigned int num_streams, gfp_t mem_flags);
1879int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
1880 struct usb_host_endpoint **eps, unsigned int num_eps,
1881 gfp_t mem_flags);
1882int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
1883int xhci_enable_device(struct usb_hcd *hcd, struct usb_device *udev);
1884int xhci_update_device(struct usb_hcd *hcd, struct usb_device *udev);
1885int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
1886 struct usb_device *udev, int enable);
1887int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
1888 struct usb_tt *tt, gfp_t mem_flags);
1889int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
1890int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
1891int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
1892int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
1893void xhci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
1894int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev);
1895int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1896void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1897
1898
1899dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
1900struct xhci_segment *trb_in_td(struct xhci_hcd *xhci,
1901 struct xhci_segment *start_seg, union xhci_trb *start_trb,
1902 union xhci_trb *end_trb, dma_addr_t suspect_dma, bool debug);
1903int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
1904void xhci_ring_cmd_db(struct xhci_hcd *xhci);
1905int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd,
1906 u32 trb_type, u32 slot_id);
1907int xhci_queue_address_device(struct xhci_hcd *xhci, struct xhci_command *cmd,
1908 dma_addr_t in_ctx_ptr, u32 slot_id, enum xhci_setup_dev);
1909int xhci_queue_vendor_command(struct xhci_hcd *xhci, struct xhci_command *cmd,
1910 u32 field1, u32 field2, u32 field3, u32 field4);
1911int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd,
1912 int slot_id, unsigned int ep_index, int suspend);
1913int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1914 int slot_id, unsigned int ep_index);
1915int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1916 int slot_id, unsigned int ep_index);
1917int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1918 int slot_id, unsigned int ep_index);
1919int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
1920 struct urb *urb, int slot_id, unsigned int ep_index);
1921int xhci_queue_configure_endpoint(struct xhci_hcd *xhci,
1922 struct xhci_command *cmd, dma_addr_t in_ctx_ptr, u32 slot_id,
1923 bool command_must_succeed);
1924int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd,
1925 dma_addr_t in_ctx_ptr, u32 slot_id, bool command_must_succeed);
1926int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd,
1927 int slot_id, unsigned int ep_index);
1928int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd,
1929 u32 slot_id);
1930void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
1931 unsigned int slot_id, unsigned int ep_index,
1932 unsigned int stream_id, struct xhci_td *cur_td,
1933 struct xhci_dequeue_state *state);
1934void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
1935 unsigned int slot_id, unsigned int ep_index,
1936 unsigned int stream_id,
1937 struct xhci_dequeue_state *deq_state);
1938void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1939 unsigned int ep_index, struct xhci_td *td);
1940void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci,
1941 unsigned int slot_id, unsigned int ep_index,
1942 struct xhci_dequeue_state *deq_state);
1943void xhci_stop_endpoint_command_watchdog(unsigned long arg);
1944void xhci_handle_command_timeout(unsigned long data);
1945
1946void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
1947 unsigned int ep_index, unsigned int stream_id);
1948void xhci_cleanup_command_queue(struct xhci_hcd *xhci);
1949
1950
1951void xhci_set_link_state(struct xhci_hcd *xhci, __le32 __iomem **port_array,
1952 int port_id, u32 link_state);
1953int xhci_enable_usb3_lpm_timeout(struct usb_hcd *hcd,
1954 struct usb_device *udev, enum usb3_link_state state);
1955int xhci_disable_usb3_lpm_timeout(struct usb_hcd *hcd,
1956 struct usb_device *udev, enum usb3_link_state state);
1957void xhci_test_and_clear_bit(struct xhci_hcd *xhci, __le32 __iomem **port_array,
1958 int port_id, u32 port_bit);
1959int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
1960 char *buf, u16 wLength);
1961int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);
1962int xhci_find_raw_port_number(struct usb_hcd *hcd, int port1);
1963
1964#ifdef CONFIG_PM
1965int xhci_bus_suspend(struct usb_hcd *hcd);
1966int xhci_bus_resume(struct usb_hcd *hcd);
1967#else
1968#define xhci_bus_suspend NULL
1969#define xhci_bus_resume NULL
1970#endif
1971
1972u32 xhci_port_state_to_neutral(u32 state);
1973int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
1974 u16 port);
1975void xhci_ring_device(struct xhci_hcd *xhci, int slot_id);
1976
1977
1978struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_container_ctx *ctx);
1979struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
1980struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int ep_index);
1981
1982struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
1983 unsigned int slot_id, unsigned int ep_index,
1984 unsigned int stream_id);
1985static inline struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
1986 struct urb *urb)
1987{
1988 return xhci_triad_to_transfer_ring(xhci, urb->dev->slot_id,
1989 xhci_get_endpoint_index(&urb->ep->desc),
1990 urb->stream_id);
1991}
1992
1993#endif
1994