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
30#include "../core/hcd.h"
31
32#include "xhci-ext-caps.h"
33
34
35#define XHCI_SBRN_OFFSET (0x60)
36
37
38#define MAX_HC_SLOTS 256
39
40#define MAX_HC_PORTS 127
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58struct xhci_cap_regs {
59 u32 hc_capbase;
60 u32 hcs_params1;
61 u32 hcs_params2;
62 u32 hcs_params3;
63 u32 hcc_params;
64 u32 db_off;
65 u32 run_regs_off;
66
67};
68
69
70
71#define HC_LENGTH(p) XHCI_HC_LENGTH(p)
72
73#define HC_VERSION(p) (((p) >> 16) & 0xffff)
74
75
76
77#define HCS_MAX_SLOTS(p) (((p) >> 0) & 0xff)
78#define HCS_SLOTS_MASK 0xff
79
80#define HCS_MAX_INTRS(p) (((p) >> 8) & 0x7ff)
81
82#define HCS_MAX_PORTS(p) (((p) >> 24) & 0x7f)
83
84
85
86
87#define HCS_IST(p) (((p) >> 0) & 0xf)
88
89#define HCS_ERST_MAX(p) (((p) >> 4) & 0xf)
90
91
92#define HCS_MAX_SCRATCHPAD(p) (((p) >> 27) & 0x1f)
93
94
95
96#define HCS_U1_LATENCY(p) (((p) >> 0) & 0xff)
97
98#define HCS_U2_LATENCY(p) (((p) >> 16) & 0xffff)
99
100
101
102#define HCC_64BIT_ADDR(p) ((p) & (1 << 0))
103
104#define HCC_BANDWIDTH_NEG(p) ((p) & (1 << 1))
105
106
107
108#define HCC_64BYTE_CONTEXT(p) ((p) & (1 << 2))
109
110#define HCC_PPC(p) ((p) & (1 << 3))
111
112#define HCS_INDICATOR(p) ((p) & (1 << 4))
113
114#define HCC_LIGHT_RESET(p) ((p) & (1 << 5))
115
116#define HCC_LTC(p) ((p) & (1 << 6))
117
118#define HCC_NSS(p) ((p) & (1 << 7))
119
120#define HCC_MAX_PSA (1 << ((((p) >> 12) & 0xf) + 1))
121
122#define HCC_EXT_CAPS(p) XHCI_HCC_EXT_CAPS(p)
123
124
125#define DBOFF_MASK (~0x3)
126
127
128#define RTSOFF_MASK (~0x1f)
129
130
131
132#define NUM_PORT_REGS 4
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156struct xhci_op_regs {
157 u32 command;
158 u32 status;
159 u32 page_size;
160 u32 reserved1;
161 u32 reserved2;
162 u32 dev_notification;
163 u64 cmd_ring;
164
165 u32 reserved3[4];
166 u64 dcbaa_ptr;
167 u32 config_reg;
168
169 u32 reserved4[241];
170
171 u32 port_status_base;
172 u32 port_power_base;
173 u32 port_link_base;
174 u32 reserved5;
175
176 u32 reserved6[NUM_PORT_REGS*254];
177};
178
179
180
181#define CMD_RUN XHCI_CMD_RUN
182
183
184
185
186#define CMD_RESET (1 << 1)
187
188#define CMD_EIE XHCI_CMD_EIE
189
190#define CMD_HSEIE XHCI_CMD_HSEIE
191
192
193#define CMD_LRESET (1 << 7)
194
195#define CMD_CSS (1 << 8)
196#define CMD_CRS (1 << 9)
197
198#define CMD_EWE XHCI_CMD_EWE
199
200
201
202
203
204#define CMD_PM_INDEX (1 << 11)
205
206
207
208
209#define STS_HALT XHCI_STS_HALT
210
211#define STS_FATAL (1 << 2)
212
213#define STS_EINT (1 << 3)
214
215#define STS_PORT (1 << 4)
216
217
218#define STS_SAVE (1 << 8)
219
220#define STS_RESTORE (1 << 9)
221
222#define STS_SRE (1 << 10)
223
224#define STS_CNR XHCI_STS_CNR
225
226#define STS_HCE (1 << 12)
227
228
229
230
231
232
233
234#define DEV_NOTE_MASK (0xffff)
235#define ENABLE_DEV_NOTE(x) (1 << x)
236
237
238
239#define DEV_NOTE_FWAKE ENABLE_DEV_NOTE(1)
240
241
242
243
244#define CMD_RING_PAUSE (1 << 1)
245
246#define CMD_RING_ABORT (1 << 2)
247
248#define CMD_RING_RUNNING (1 << 3)
249
250
251#define CMD_RING_RSVD_BITS (0x3f)
252
253
254
255#define MAX_DEVS(p) ((p) & 0xff)
256
257
258
259
260#define PORT_CONNECT (1 << 0)
261
262#define PORT_PE (1 << 1)
263
264
265#define PORT_OC (1 << 3)
266
267#define PORT_RESET (1 << 4)
268
269
270
271
272
273#define PORT_POWER (1 << 9)
274
275
276
277
278
279
280
281
282#define DEV_SPEED_MASK (0xf << 10)
283#define XDEV_FS (0x1 << 10)
284#define XDEV_LS (0x2 << 10)
285#define XDEV_HS (0x3 << 10)
286#define XDEV_SS (0x4 << 10)
287#define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10))
288#define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS)
289#define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS)
290#define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS)
291#define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS)
292
293#define SLOT_SPEED_FS (XDEV_FS << 10)
294#define SLOT_SPEED_LS (XDEV_LS << 10)
295#define SLOT_SPEED_HS (XDEV_HS << 10)
296#define SLOT_SPEED_SS (XDEV_SS << 10)
297
298#define PORT_LED_OFF (0 << 14)
299#define PORT_LED_AMBER (1 << 14)
300#define PORT_LED_GREEN (2 << 14)
301#define PORT_LED_MASK (3 << 14)
302
303#define PORT_LINK_STROBE (1 << 16)
304
305#define PORT_CSC (1 << 17)
306
307#define PORT_PEC (1 << 18)
308
309
310
311
312
313#define PORT_WRC (1 << 19)
314
315#define PORT_OCC (1 << 20)
316
317#define PORT_RC (1 << 21)
318
319
320
321
322
323
324
325
326
327
328
329
330
331#define PORT_PLC (1 << 22)
332
333#define PORT_CEC (1 << 23)
334
335
336#define PORT_WKCONN_E (1 << 25)
337
338#define PORT_WKDISC_E (1 << 26)
339
340#define PORT_WKOC_E (1 << 27)
341
342
343#define PORT_DEV_REMOVE (1 << 30)
344
345#define PORT_WR (1 << 31)
346
347
348
349
350
351#define PORT_U1_TIMEOUT(p) ((p) & 0xff)
352
353#define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374struct xhci_intr_reg {
375 u32 irq_pending;
376 u32 irq_control;
377 u32 erst_size;
378 u32 rsvd;
379 u64 erst_base;
380 u64 erst_dequeue;
381};
382
383
384#define ER_IRQ_PENDING(p) ((p) & 0x1)
385
386
387#define ER_IRQ_CLEAR(p) ((p) & 0xfffffffe)
388#define ER_IRQ_ENABLE(p) ((ER_IRQ_CLEAR(p)) | 0x2)
389#define ER_IRQ_DISABLE(p) ((ER_IRQ_CLEAR(p)) & ~(0x2))
390
391
392
393
394
395
396#define ER_IRQ_INTERVAL_MASK (0xffff)
397
398#define ER_IRQ_COUNTER_MASK (0xffff << 16)
399
400
401
402#define ERST_SIZE_MASK (0xffff << 16)
403
404
405
406
407
408#define ERST_DESI_MASK (0x7)
409
410
411
412#define ERST_EHB (1 << 3)
413#define ERST_PTR_MASK (0xf)
414
415
416
417
418
419
420
421
422
423
424struct xhci_run_regs {
425 u32 microframe_index;
426 u32 rsvd[7];
427 struct xhci_intr_reg ir_set[128];
428};
429
430
431
432
433
434
435struct xhci_doorbell_array {
436 u32 doorbell[256];
437};
438
439#define DB_TARGET_MASK 0xFFFFFF00
440#define DB_STREAM_ID_MASK 0x0000FFFF
441#define DB_TARGET_HOST 0x0
442#define DB_STREAM_ID_HOST 0x0
443#define DB_MASK (0xff << 8)
444
445
446#define EPI_TO_DB(p) (((p) + 1) & 0xff)
447
448
449
450
451
452
453
454
455
456
457
458
459struct xhci_container_ctx {
460 unsigned type;
461#define XHCI_CTX_TYPE_DEVICE 0x1
462#define XHCI_CTX_TYPE_INPUT 0x2
463
464 int size;
465
466 u8 *bytes;
467 dma_addr_t dma;
468};
469
470
471
472
473
474
475
476
477
478
479
480
481struct xhci_slot_ctx {
482 u32 dev_info;
483 u32 dev_info2;
484 u32 tt_info;
485 u32 dev_state;
486
487 u32 reserved[4];
488};
489
490
491
492#define ROUTE_STRING_MASK (0xfffff)
493
494#define DEV_SPEED (0xf << 20)
495
496
497#define DEV_MTT (0x1 << 25)
498
499#define DEV_HUB (0x1 << 26)
500
501#define LAST_CTX_MASK (0x1f << 27)
502#define LAST_CTX(p) ((p) << 27)
503#define LAST_CTX_TO_EP_NUM(p) (((p) >> 27) - 1)
504#define SLOT_FLAG (1 << 0)
505#define EP0_FLAG (1 << 1)
506
507
508
509#define MAX_EXIT (0xffff)
510
511#define ROOT_HUB_PORT(p) (((p) & 0xff) << 16)
512
513#define XHCI_MAX_PORTS(p) (((p) & 0xff) << 24)
514
515
516
517
518
519
520
521#define TT_SLOT (0xff)
522
523
524
525
526#define TT_PORT (0xff << 8)
527#define TT_THINK_TIME(p) (((p) & 0x3) << 16)
528
529
530
531#define DEV_ADDR_MASK (0xff)
532
533
534#define SLOT_STATE (0x1f << 27)
535#define GET_SLOT_STATE(p) (((p) & (0x1f << 27)) >> 27)
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556struct xhci_ep_ctx {
557 u32 ep_info;
558 u32 ep_info2;
559 u64 deq;
560 u32 tx_info;
561
562 u32 reserved[3];
563};
564
565
566
567
568
569
570
571
572
573
574
575#define EP_STATE_MASK (0xf)
576#define EP_STATE_DISABLED 0
577#define EP_STATE_RUNNING 1
578#define EP_STATE_HALTED 2
579#define EP_STATE_STOPPED 3
580#define EP_STATE_ERROR 4
581
582#define EP_MULT(p) ((p & 0x3) << 8)
583
584
585
586#define EP_INTERVAL(p) ((p & 0xff) << 16)
587#define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff))
588
589
590
591
592
593
594#define FORCE_EVENT (0x1)
595#define ERROR_COUNT(p) (((p) & 0x3) << 1)
596#define CTX_TO_EP_TYPE(p) (((p) >> 3) & 0x7)
597#define EP_TYPE(p) ((p) << 3)
598#define ISOC_OUT_EP 1
599#define BULK_OUT_EP 2
600#define INT_OUT_EP 3
601#define CTRL_EP 4
602#define ISOC_IN_EP 5
603#define BULK_IN_EP 6
604#define INT_IN_EP 7
605
606
607#define MAX_BURST(p) (((p)&0xff) << 8)
608#define MAX_PACKET(p) (((p)&0xffff) << 16)
609#define MAX_PACKET_MASK (0xffff << 16)
610#define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff)
611
612
613#define AVG_TRB_LENGTH_FOR_EP(p) ((p) & 0xffff)
614#define MAX_ESIT_PAYLOAD_FOR_EP(p) (((p) & 0xffff) << 16)
615
616
617
618
619
620
621
622
623
624struct xhci_input_control_ctx {
625 u32 drop_flags;
626 u32 add_flags;
627 u32 rsvd2[6];
628};
629
630
631
632
633
634struct xhci_command {
635
636 struct xhci_container_ctx *in_ctx;
637 u32 status;
638
639
640
641 struct completion *completion;
642 union xhci_trb *command_trb;
643 struct list_head cmd_list;
644};
645
646
647#define DROP_EP(x) (0x1 << x)
648
649#define ADD_EP(x) (0x1 << x)
650
651struct xhci_virt_ep {
652 struct xhci_ring *ring;
653
654
655
656 struct xhci_ring *new_ring;
657 unsigned int ep_state;
658#define SET_DEQ_PENDING (1 << 0)
659#define EP_HALTED (1 << 1)
660#define EP_HALT_PENDING (1 << 2)
661
662 struct list_head cancelled_td_list;
663
664 union xhci_trb *stopped_trb;
665 struct xhci_td *stopped_td;
666
667 struct timer_list stop_cmd_timer;
668 int stop_cmds_pending;
669 struct xhci_hcd *xhci;
670};
671
672struct xhci_virt_device {
673
674
675
676
677
678
679
680
681 struct xhci_container_ctx *out_ctx;
682
683 struct xhci_container_ctx *in_ctx;
684
685 struct xhci_ring **ring_cache;
686 int num_rings_cached;
687#define XHCI_MAX_RINGS_CACHED 31
688 struct xhci_virt_ep eps[31];
689 struct completion cmd_completion;
690
691 u32 cmd_status;
692 struct list_head cmd_list;
693};
694
695
696
697
698
699
700struct xhci_device_context_array {
701
702 u64 dev_context_ptrs[MAX_HC_SLOTS];
703
704 dma_addr_t dma;
705};
706
707
708
709
710
711
712
713struct xhci_stream_ctx {
714
715 u64 stream_ring;
716
717 u32 reserved[2];
718};
719
720
721struct xhci_transfer_event {
722
723 u64 buffer;
724 u32 transfer_len;
725
726 u32 flags;
727};
728
729
730#define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f)
731
732
733#define COMP_CODE_MASK (0xff << 24)
734#define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24)
735#define COMP_SUCCESS 1
736
737#define COMP_DB_ERR 2
738
739#define COMP_BABBLE 3
740
741#define COMP_TX_ERR 4
742
743#define COMP_TRB_ERR 5
744
745#define COMP_STALL 6
746
747#define COMP_ENOMEM 7
748
749#define COMP_BW_ERR 8
750
751#define COMP_ENOSLOTS 9
752
753#define COMP_STREAM_ERR 10
754
755#define COMP_EBADSLT 11
756
757#define COMP_EBADEP 12
758
759#define COMP_SHORT_TX 13
760
761#define COMP_UNDERRUN 14
762
763#define COMP_OVERRUN 15
764
765#define COMP_VF_FULL 16
766
767#define COMP_EINVAL 17
768
769#define COMP_BW_OVER 18
770
771#define COMP_CTX_STATE 19
772
773#define COMP_PING_ERR 20
774
775#define COMP_ER_FULL 21
776
777#define COMP_MISSED_INT 23
778
779#define COMP_CMD_STOP 24
780
781#define COMP_CMD_ABORT 25
782
783#define COMP_STOP 26
784
785#define COMP_STOP_INVAL 27
786
787#define COMP_DBG_ABORT 28
788
789
790#define COMP_BUFF_OVER 31
791
792#define COMP_ISSUES 32
793
794#define COMP_UNKNOWN 33
795
796#define COMP_STRID_ERR 34
797
798
799#define COMP_2ND_BW_ERR 35
800
801#define COMP_SPLIT_ERR 36
802
803struct xhci_link_trb {
804
805 u64 segment_ptr;
806 u32 intr_target;
807 u32 control;
808};
809
810
811#define LINK_TOGGLE (0x1<<1)
812
813
814struct xhci_event_cmd {
815
816 u64 cmd_trb;
817 u32 status;
818 u32 flags;
819};
820
821
822
823
824#define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24)
825#define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24)
826
827
828#define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1)
829#define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16)
830
831
832
833
834#define GET_PORT_ID(p) (((p) & (0xff << 24)) >> 24)
835
836
837
838#define TRB_LEN(p) ((p) & 0x1ffff)
839
840#define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
841#define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
842
843
844#define TRB_CYCLE (1<<0)
845
846
847
848
849#define TRB_ENT (1<<1)
850
851#define TRB_ISP (1<<2)
852
853#define TRB_NO_SNOOP (1<<3)
854
855#define TRB_CHAIN (1<<4)
856
857#define TRB_IOC (1<<5)
858
859#define TRB_IDT (1<<6)
860
861
862
863#define TRB_DIR_IN (1<<16)
864
865struct xhci_generic_trb {
866 u32 field[4];
867};
868
869union xhci_trb {
870 struct xhci_link_trb link;
871 struct xhci_transfer_event trans_event;
872 struct xhci_event_cmd event_cmd;
873 struct xhci_generic_trb generic;
874};
875
876
877#define TRB_TYPE_BITMASK (0xfc00)
878#define TRB_TYPE(p) ((p) << 10)
879
880
881#define TRB_NORMAL 1
882
883#define TRB_SETUP 2
884
885#define TRB_DATA 3
886
887#define TRB_STATUS 4
888
889#define TRB_ISOC 5
890
891#define TRB_LINK 6
892#define TRB_EVENT_DATA 7
893
894#define TRB_TR_NOOP 8
895
896
897#define TRB_ENABLE_SLOT 9
898
899#define TRB_DISABLE_SLOT 10
900
901#define TRB_ADDR_DEV 11
902
903#define TRB_CONFIG_EP 12
904
905#define TRB_EVAL_CONTEXT 13
906
907#define TRB_RESET_EP 14
908
909#define TRB_STOP_RING 15
910
911#define TRB_SET_DEQ 16
912
913#define TRB_RESET_DEV 17
914
915#define TRB_FORCE_EVENT 18
916
917#define TRB_NEG_BANDWIDTH 19
918
919#define TRB_SET_LT 20
920
921#define TRB_GET_BW 21
922
923#define TRB_FORCE_HEADER 22
924
925#define TRB_CMD_NOOP 23
926
927
928
929#define TRB_TRANSFER 32
930
931#define TRB_COMPLETION 33
932
933#define TRB_PORT_STATUS 34
934
935#define TRB_BANDWIDTH_EVENT 35
936
937#define TRB_DOORBELL 36
938
939#define TRB_HC_EVENT 37
940
941#define TRB_DEV_NOTE 38
942
943#define TRB_MFINDEX_WRAP 39
944
945
946
947
948
949
950
951#define TRBS_PER_SEGMENT 64
952
953#define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
954#define SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
955
956#define TRB_MAX_BUFF_SHIFT 16
957#define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT)
958
959struct xhci_segment {
960 union xhci_trb *trbs;
961
962 struct xhci_segment *next;
963 dma_addr_t dma;
964};
965
966struct xhci_td {
967 struct list_head td_list;
968 struct list_head cancelled_td_list;
969 struct urb *urb;
970 struct xhci_segment *start_seg;
971 union xhci_trb *first_trb;
972 union xhci_trb *last_trb;
973};
974
975struct xhci_dequeue_state {
976 struct xhci_segment *new_deq_seg;
977 union xhci_trb *new_deq_ptr;
978 int new_cycle_state;
979};
980
981struct xhci_ring {
982 struct xhci_segment *first_seg;
983 union xhci_trb *enqueue;
984 struct xhci_segment *enq_seg;
985 unsigned int enq_updates;
986 union xhci_trb *dequeue;
987 struct xhci_segment *deq_seg;
988 unsigned int deq_updates;
989 struct list_head td_list;
990
991
992
993
994
995 u32 cycle_state;
996};
997
998struct xhci_erst_entry {
999
1000 u64 seg_addr;
1001 u32 seg_size;
1002
1003 u32 rsvd;
1004};
1005
1006struct xhci_erst {
1007 struct xhci_erst_entry *entries;
1008 unsigned int num_entries;
1009
1010 dma_addr_t erst_dma_addr;
1011
1012 unsigned int erst_size;
1013};
1014
1015struct xhci_scratchpad {
1016 u64 *sp_array;
1017 dma_addr_t sp_dma;
1018 void **sp_buffers;
1019 dma_addr_t *sp_dma_buffers;
1020};
1021
1022
1023
1024
1025
1026
1027#define ERST_NUM_SEGS 1
1028
1029#define ERST_SIZE 64
1030
1031#define ERST_ENTRIES 1
1032
1033#define POLL_TIMEOUT 60
1034
1035#define XHCI_STOP_EP_CMD_TIMEOUT 5
1036
1037
1038
1039
1040struct xhci_hcd {
1041
1042 struct xhci_cap_regs __iomem *cap_regs;
1043 struct xhci_op_regs __iomem *op_regs;
1044 struct xhci_run_regs __iomem *run_regs;
1045 struct xhci_doorbell_array __iomem *dba;
1046
1047 struct xhci_intr_reg __iomem *ir_set;
1048
1049
1050 __u32 hcs_params1;
1051 __u32 hcs_params2;
1052 __u32 hcs_params3;
1053 __u32 hcc_params;
1054
1055 spinlock_t lock;
1056
1057
1058 u8 sbrn;
1059 u16 hci_version;
1060 u8 max_slots;
1061 u8 max_interrupters;
1062 u8 max_ports;
1063 u8 isoc_threshold;
1064 int event_ring_max;
1065 int addr_64;
1066
1067 int page_size;
1068
1069 int page_shift;
1070
1071 int msix_count;
1072 struct msix_entry *msix_entries;
1073
1074 struct xhci_device_context_array *dcbaa;
1075 struct xhci_ring *cmd_ring;
1076 unsigned int cmd_ring_reserved_trbs;
1077 struct xhci_ring *event_ring;
1078 struct xhci_erst erst;
1079
1080 struct xhci_scratchpad *scratchpad;
1081
1082
1083 struct completion addr_dev;
1084 int slot_id;
1085
1086 struct xhci_virt_device *devs[MAX_HC_SLOTS];
1087
1088
1089 struct dma_pool *device_pool;
1090 struct dma_pool *segment_pool;
1091
1092#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
1093
1094 struct timer_list event_ring_timer;
1095 int zombie;
1096#endif
1097
1098 unsigned int xhc_state;
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111#define XHCI_STATE_DYING (1 << 0)
1112
1113 int noops_submitted;
1114 int noops_handled;
1115 int error_bitmask;
1116 unsigned int quirks;
1117#define XHCI_LINK_TRB_QUIRK (1 << 0)
1118#define XHCI_RESET_EP_QUIRK (1 << 1)
1119};
1120
1121
1122#define NUM_TEST_NOOPS 0
1123
1124
1125static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd)
1126{
1127 return (struct xhci_hcd *) (hcd->hcd_priv);
1128}
1129
1130static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
1131{
1132 return container_of((void *) xhci, struct usb_hcd, hcd_priv);
1133}
1134
1135#ifdef CONFIG_USB_XHCI_HCD_DEBUGGING
1136#define XHCI_DEBUG 1
1137#else
1138#define XHCI_DEBUG 0
1139#endif
1140
1141#define xhci_dbg(xhci, fmt, args...) \
1142 do { if (XHCI_DEBUG) dev_dbg(xhci_to_hcd(xhci)->self.controller , fmt , ## args); } while (0)
1143#define xhci_info(xhci, fmt, args...) \
1144 do { if (XHCI_DEBUG) dev_info(xhci_to_hcd(xhci)->self.controller , fmt , ## args); } while (0)
1145#define xhci_err(xhci, fmt, args...) \
1146 dev_err(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1147#define xhci_warn(xhci, fmt, args...) \
1148 dev_warn(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1149
1150
1151
1152static inline unsigned int xhci_readl(const struct xhci_hcd *xhci,
1153 __u32 __iomem *regs)
1154{
1155 return readl(regs);
1156}
1157static inline void xhci_writel(struct xhci_hcd *xhci,
1158 const unsigned int val, __u32 __iomem *regs)
1159{
1160 xhci_dbg(xhci,
1161 "`MEM_WRITE_DWORD(3'b000, 32'h%p, 32'h%0x, 4'hf);\n",
1162 regs, val);
1163 writel(val, regs);
1164}
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175static inline u64 xhci_read_64(const struct xhci_hcd *xhci,
1176 __u64 __iomem *regs)
1177{
1178 __u32 __iomem *ptr = (__u32 __iomem *) regs;
1179 u64 val_lo = readl(ptr);
1180 u64 val_hi = readl(ptr + 1);
1181 return val_lo + (val_hi << 32);
1182}
1183static inline void xhci_write_64(struct xhci_hcd *xhci,
1184 const u64 val, __u64 __iomem *regs)
1185{
1186 __u32 __iomem *ptr = (__u32 __iomem *) regs;
1187 u32 val_lo = lower_32_bits(val);
1188 u32 val_hi = upper_32_bits(val);
1189
1190 xhci_dbg(xhci,
1191 "`MEM_WRITE_DWORD(3'b000, 64'h%p, 64'h%0lx, 4'hf);\n",
1192 regs, (long unsigned int) val);
1193 writel(val_lo, ptr);
1194 writel(val_hi, ptr + 1);
1195}
1196
1197static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci)
1198{
1199 u32 temp = xhci_readl(xhci, &xhci->cap_regs->hc_capbase);
1200 return ((HC_VERSION(temp) == 0x95) &&
1201 (xhci->quirks & XHCI_LINK_TRB_QUIRK));
1202}
1203
1204
1205void xhci_print_ir_set(struct xhci_hcd *xhci, struct xhci_intr_reg *ir_set, int set_num);
1206void xhci_print_registers(struct xhci_hcd *xhci);
1207void xhci_dbg_regs(struct xhci_hcd *xhci);
1208void xhci_print_run_regs(struct xhci_hcd *xhci);
1209void xhci_print_trb_offsets(struct xhci_hcd *xhci, union xhci_trb *trb);
1210void xhci_debug_trb(struct xhci_hcd *xhci, union xhci_trb *trb);
1211void xhci_debug_segment(struct xhci_hcd *xhci, struct xhci_segment *seg);
1212void xhci_debug_ring(struct xhci_hcd *xhci, struct xhci_ring *ring);
1213void xhci_dbg_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
1214void xhci_dbg_cmd_ptrs(struct xhci_hcd *xhci);
1215void xhci_dbg_ring_ptrs(struct xhci_hcd *xhci, struct xhci_ring *ring);
1216void xhci_dbg_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int last_ep);
1217char *xhci_get_slot_state(struct xhci_hcd *xhci,
1218 struct xhci_container_ctx *ctx);
1219
1220
1221void xhci_mem_cleanup(struct xhci_hcd *xhci);
1222int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags);
1223void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id);
1224int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device *udev, gfp_t flags);
1225int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev);
1226unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc);
1227unsigned int xhci_get_endpoint_flag(struct usb_endpoint_descriptor *desc);
1228unsigned int xhci_get_endpoint_flag_from_index(unsigned int ep_index);
1229unsigned int xhci_last_valid_endpoint(u32 added_ctxs);
1230void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep);
1231void xhci_endpoint_copy(struct xhci_hcd *xhci,
1232 struct xhci_container_ctx *in_ctx,
1233 struct xhci_container_ctx *out_ctx,
1234 unsigned int ep_index);
1235void xhci_slot_copy(struct xhci_hcd *xhci,
1236 struct xhci_container_ctx *in_ctx,
1237 struct xhci_container_ctx *out_ctx);
1238int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev,
1239 struct usb_device *udev, struct usb_host_endpoint *ep,
1240 gfp_t mem_flags);
1241void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring);
1242void xhci_free_or_cache_endpoint_ring(struct xhci_hcd *xhci,
1243 struct xhci_virt_device *virt_dev,
1244 unsigned int ep_index);
1245struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
1246 bool allocate_in_ctx, bool allocate_completion,
1247 gfp_t mem_flags);
1248void xhci_free_command(struct xhci_hcd *xhci,
1249 struct xhci_command *command);
1250
1251#ifdef CONFIG_PCI
1252
1253int xhci_register_pci(void);
1254void xhci_unregister_pci(void);
1255#endif
1256
1257
1258void xhci_quiesce(struct xhci_hcd *xhci);
1259int xhci_halt(struct xhci_hcd *xhci);
1260int xhci_reset(struct xhci_hcd *xhci);
1261int xhci_init(struct usb_hcd *hcd);
1262int xhci_run(struct usb_hcd *hcd);
1263void xhci_stop(struct usb_hcd *hcd);
1264void xhci_shutdown(struct usb_hcd *hcd);
1265int xhci_get_frame(struct usb_hcd *hcd);
1266irqreturn_t xhci_irq(struct usb_hcd *hcd);
1267int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
1268void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev);
1269int xhci_address_device(struct usb_hcd *hcd, struct usb_device *udev);
1270int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev,
1271 struct usb_tt *tt, gfp_t mem_flags);
1272int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags);
1273int xhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status);
1274int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
1275int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, struct usb_host_endpoint *ep);
1276void xhci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
1277int xhci_reset_device(struct usb_hcd *hcd, struct usb_device *udev);
1278int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1279void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
1280
1281
1282dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
1283struct xhci_segment *trb_in_td(struct xhci_segment *start_seg,
1284 union xhci_trb *start_trb, union xhci_trb *end_trb,
1285 dma_addr_t suspect_dma);
1286int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
1287void xhci_ring_cmd_db(struct xhci_hcd *xhci);
1288void *xhci_setup_one_noop(struct xhci_hcd *xhci);
1289void xhci_handle_event(struct xhci_hcd *xhci);
1290void xhci_set_hc_event_deq(struct xhci_hcd *xhci);
1291int xhci_queue_slot_control(struct xhci_hcd *xhci, u32 trb_type, u32 slot_id);
1292int xhci_queue_address_device(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1293 u32 slot_id);
1294int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, int slot_id,
1295 unsigned int ep_index);
1296int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1297 int slot_id, unsigned int ep_index);
1298int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1299 int slot_id, unsigned int ep_index);
1300int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
1301 int slot_id, unsigned int ep_index);
1302int xhci_queue_configure_endpoint(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1303 u32 slot_id, bool command_must_succeed);
1304int xhci_queue_evaluate_context(struct xhci_hcd *xhci, dma_addr_t in_ctx_ptr,
1305 u32 slot_id);
1306int xhci_queue_reset_ep(struct xhci_hcd *xhci, int slot_id,
1307 unsigned int ep_index);
1308int xhci_queue_reset_device(struct xhci_hcd *xhci, u32 slot_id);
1309void xhci_find_new_dequeue_state(struct xhci_hcd *xhci,
1310 unsigned int slot_id, unsigned int ep_index,
1311 struct xhci_td *cur_td, struct xhci_dequeue_state *state);
1312void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci,
1313 unsigned int slot_id, unsigned int ep_index,
1314 struct xhci_dequeue_state *deq_state);
1315void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci,
1316 struct usb_device *udev, unsigned int ep_index);
1317void xhci_queue_config_ep_quirk(struct xhci_hcd *xhci,
1318 unsigned int slot_id, unsigned int ep_index,
1319 struct xhci_dequeue_state *deq_state);
1320void xhci_stop_endpoint_command_watchdog(unsigned long arg);
1321
1322
1323int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
1324 char *buf, u16 wLength);
1325int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);
1326
1327
1328struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
1329struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
1330struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int ep_index);
1331
1332#endif
1333