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