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