0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef __LINUX_XHCI_HCD_H
0013 #define __LINUX_XHCI_HCD_H
0014
0015 #include <linux/usb.h>
0016 #include <linux/timer.h>
0017 #include <linux/kernel.h>
0018 #include <linux/usb/hcd.h>
0019 #include <linux/io-64-nonatomic-lo-hi.h>
0020
0021
0022 #include "xhci-ext-caps.h"
0023 #include "pci-quirks.h"
0024
0025
0026 #define XHCI_MSG_MAX 500
0027
0028
0029 #define XHCI_SBRN_OFFSET (0x60)
0030
0031
0032 #define MAX_HC_SLOTS 256
0033
0034 #define MAX_HC_PORTS 127
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 struct xhci_cap_regs {
0054 __le32 hc_capbase;
0055 __le32 hcs_params1;
0056 __le32 hcs_params2;
0057 __le32 hcs_params3;
0058 __le32 hcc_params;
0059 __le32 db_off;
0060 __le32 run_regs_off;
0061 __le32 hcc_params2;
0062
0063 };
0064
0065
0066
0067 #define HC_LENGTH(p) XHCI_HC_LENGTH(p)
0068
0069 #define HC_VERSION(p) (((p) >> 16) & 0xffff)
0070
0071
0072
0073 #define HCS_MAX_SLOTS(p) (((p) >> 0) & 0xff)
0074 #define HCS_SLOTS_MASK 0xff
0075
0076 #define HCS_MAX_INTRS(p) (((p) >> 8) & 0x7ff)
0077
0078 #define HCS_MAX_PORTS(p) (((p) >> 24) & 0x7f)
0079
0080
0081
0082
0083 #define HCS_IST(p) (((p) >> 0) & 0xf)
0084
0085 #define HCS_ERST_MAX(p) (((p) >> 4) & 0xf)
0086
0087
0088
0089 #define HCS_MAX_SCRATCHPAD(p) ((((p) >> 16) & 0x3e0) | (((p) >> 27) & 0x1f))
0090
0091
0092
0093 #define HCS_U1_LATENCY(p) (((p) >> 0) & 0xff)
0094
0095 #define HCS_U2_LATENCY(p) (((p) >> 16) & 0xffff)
0096
0097
0098
0099 #define HCC_64BIT_ADDR(p) ((p) & (1 << 0))
0100
0101 #define HCC_BANDWIDTH_NEG(p) ((p) & (1 << 1))
0102
0103
0104
0105 #define HCC_64BYTE_CONTEXT(p) ((p) & (1 << 2))
0106
0107 #define HCC_PPC(p) ((p) & (1 << 3))
0108
0109 #define HCS_INDICATOR(p) ((p) & (1 << 4))
0110
0111 #define HCC_LIGHT_RESET(p) ((p) & (1 << 5))
0112
0113 #define HCC_LTC(p) ((p) & (1 << 6))
0114
0115 #define HCC_NSS(p) ((p) & (1 << 7))
0116
0117 #define HCC_SPC(p) ((p) & (1 << 9))
0118
0119 #define HCC_CFC(p) ((p) & (1 << 11))
0120
0121 #define HCC_MAX_PSA(p) (1 << ((((p) >> 12) & 0xf) + 1))
0122
0123 #define HCC_EXT_CAPS(p) XHCI_HCC_EXT_CAPS(p)
0124
0125 #define CTX_SIZE(_hcc) (HCC_64BYTE_CONTEXT(_hcc) ? 64 : 32)
0126
0127
0128 #define DBOFF_MASK (~0x3)
0129
0130
0131 #define RTSOFF_MASK (~0x1f)
0132
0133
0134
0135 #define HCC2_U3C(p) ((p) & (1 << 0))
0136
0137 #define HCC2_CMC(p) ((p) & (1 << 1))
0138
0139 #define HCC2_FSC(p) ((p) & (1 << 2))
0140
0141 #define HCC2_CTC(p) ((p) & (1 << 3))
0142
0143 #define HCC2_LEC(p) ((p) & (1 << 4))
0144
0145 #define HCC2_CIC(p) ((p) & (1 << 5))
0146
0147 #define HCC2_ETC(p) ((p) & (1 << 6))
0148
0149
0150 #define NUM_PORT_REGS 4
0151
0152 #define PORTSC 0
0153 #define PORTPMSC 1
0154 #define PORTLI 2
0155 #define PORTHLPMC 3
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179 struct xhci_op_regs {
0180 __le32 command;
0181 __le32 status;
0182 __le32 page_size;
0183 __le32 reserved1;
0184 __le32 reserved2;
0185 __le32 dev_notification;
0186 __le64 cmd_ring;
0187
0188 __le32 reserved3[4];
0189 __le64 dcbaa_ptr;
0190 __le32 config_reg;
0191
0192 __le32 reserved4[241];
0193
0194 __le32 port_status_base;
0195 __le32 port_power_base;
0196 __le32 port_link_base;
0197 __le32 reserved5;
0198
0199 __le32 reserved6[NUM_PORT_REGS*254];
0200 };
0201
0202
0203
0204 #define CMD_RUN XHCI_CMD_RUN
0205
0206
0207
0208
0209 #define CMD_RESET (1 << 1)
0210
0211 #define CMD_EIE XHCI_CMD_EIE
0212
0213 #define CMD_HSEIE XHCI_CMD_HSEIE
0214
0215
0216 #define CMD_LRESET (1 << 7)
0217
0218 #define CMD_CSS (1 << 8)
0219 #define CMD_CRS (1 << 9)
0220
0221 #define CMD_EWE XHCI_CMD_EWE
0222
0223
0224
0225
0226
0227 #define CMD_PM_INDEX (1 << 11)
0228
0229 #define CMD_ETE (1 << 14)
0230
0231
0232 #define XHCI_RESET_LONG_USEC (10 * 1000 * 1000)
0233 #define XHCI_RESET_SHORT_USEC (250 * 1000)
0234
0235
0236 #define IMAN_IE (1 << 1)
0237 #define IMAN_IP (1 << 0)
0238
0239
0240
0241 #define STS_HALT XHCI_STS_HALT
0242
0243 #define STS_FATAL (1 << 2)
0244
0245 #define STS_EINT (1 << 3)
0246
0247 #define STS_PORT (1 << 4)
0248
0249
0250 #define STS_SAVE (1 << 8)
0251
0252 #define STS_RESTORE (1 << 9)
0253
0254 #define STS_SRE (1 << 10)
0255
0256 #define STS_CNR XHCI_STS_CNR
0257
0258 #define STS_HCE (1 << 12)
0259
0260
0261
0262
0263
0264
0265
0266 #define DEV_NOTE_MASK (0xffff)
0267 #define ENABLE_DEV_NOTE(x) (1 << (x))
0268
0269
0270
0271 #define DEV_NOTE_FWAKE ENABLE_DEV_NOTE(1)
0272
0273
0274
0275
0276 #define CMD_RING_PAUSE (1 << 1)
0277
0278 #define CMD_RING_ABORT (1 << 2)
0279
0280 #define CMD_RING_RUNNING (1 << 3)
0281
0282
0283 #define CMD_RING_RSVD_BITS (0x3f)
0284
0285
0286
0287 #define MAX_DEVS(p) ((p) & 0xff)
0288
0289 #define CONFIG_U3E (1 << 8)
0290
0291 #define CONFIG_CIE (1 << 9)
0292
0293
0294
0295
0296 #define PORT_CONNECT (1 << 0)
0297
0298 #define PORT_PE (1 << 1)
0299
0300
0301 #define PORT_OC (1 << 3)
0302
0303 #define PORT_RESET (1 << 4)
0304
0305
0306
0307
0308 #define PORT_PLS_MASK (0xf << 5)
0309 #define XDEV_U0 (0x0 << 5)
0310 #define XDEV_U1 (0x1 << 5)
0311 #define XDEV_U2 (0x2 << 5)
0312 #define XDEV_U3 (0x3 << 5)
0313 #define XDEV_DISABLED (0x4 << 5)
0314 #define XDEV_RXDETECT (0x5 << 5)
0315 #define XDEV_INACTIVE (0x6 << 5)
0316 #define XDEV_POLLING (0x7 << 5)
0317 #define XDEV_RECOVERY (0x8 << 5)
0318 #define XDEV_HOT_RESET (0x9 << 5)
0319 #define XDEV_COMP_MODE (0xa << 5)
0320 #define XDEV_TEST_MODE (0xb << 5)
0321 #define XDEV_RESUME (0xf << 5)
0322
0323
0324 #define PORT_POWER (1 << 9)
0325
0326
0327
0328
0329
0330
0331
0332
0333 #define DEV_SPEED_MASK (0xf << 10)
0334 #define XDEV_FS (0x1 << 10)
0335 #define XDEV_LS (0x2 << 10)
0336 #define XDEV_HS (0x3 << 10)
0337 #define XDEV_SS (0x4 << 10)
0338 #define XDEV_SSP (0x5 << 10)
0339 #define DEV_UNDEFSPEED(p) (((p) & DEV_SPEED_MASK) == (0x0<<10))
0340 #define DEV_FULLSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_FS)
0341 #define DEV_LOWSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_LS)
0342 #define DEV_HIGHSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_HS)
0343 #define DEV_SUPERSPEED(p) (((p) & DEV_SPEED_MASK) == XDEV_SS)
0344 #define DEV_SUPERSPEEDPLUS(p) (((p) & DEV_SPEED_MASK) == XDEV_SSP)
0345 #define DEV_SUPERSPEED_ANY(p) (((p) & DEV_SPEED_MASK) >= XDEV_SS)
0346 #define DEV_PORT_SPEED(p) (((p) >> 10) & 0x0f)
0347
0348
0349 #define SLOT_SPEED_FS (XDEV_FS << 10)
0350 #define SLOT_SPEED_LS (XDEV_LS << 10)
0351 #define SLOT_SPEED_HS (XDEV_HS << 10)
0352 #define SLOT_SPEED_SS (XDEV_SS << 10)
0353 #define SLOT_SPEED_SSP (XDEV_SSP << 10)
0354
0355 #define PORT_LED_OFF (0 << 14)
0356 #define PORT_LED_AMBER (1 << 14)
0357 #define PORT_LED_GREEN (2 << 14)
0358 #define PORT_LED_MASK (3 << 14)
0359
0360 #define PORT_LINK_STROBE (1 << 16)
0361
0362 #define PORT_CSC (1 << 17)
0363
0364 #define PORT_PEC (1 << 18)
0365
0366
0367
0368
0369
0370 #define PORT_WRC (1 << 19)
0371
0372 #define PORT_OCC (1 << 20)
0373
0374 #define PORT_RC (1 << 21)
0375
0376
0377
0378
0379
0380
0381
0382
0383
0384
0385
0386
0387
0388 #define PORT_PLC (1 << 22)
0389
0390 #define PORT_CEC (1 << 23)
0391 #define PORT_CHANGE_MASK (PORT_CSC | PORT_PEC | PORT_WRC | PORT_OCC | \
0392 PORT_RC | PORT_PLC | PORT_CEC)
0393
0394
0395
0396
0397
0398
0399 #define PORT_CAS (1 << 24)
0400
0401 #define PORT_WKCONN_E (1 << 25)
0402
0403 #define PORT_WKDISC_E (1 << 26)
0404
0405 #define PORT_WKOC_E (1 << 27)
0406
0407
0408 #define PORT_DEV_REMOVE (1 << 30)
0409
0410 #define PORT_WR (1 << 31)
0411
0412
0413 #define DUPLICATE_ENTRY ((u8)(-1))
0414
0415
0416
0417
0418
0419 #define PORT_U1_TIMEOUT(p) ((p) & 0xff)
0420 #define PORT_U1_TIMEOUT_MASK 0xff
0421
0422 #define PORT_U2_TIMEOUT(p) (((p) & 0xff) << 8)
0423 #define PORT_U2_TIMEOUT_MASK (0xff << 8)
0424
0425
0426
0427 #define PORT_L1S_MASK 7
0428 #define PORT_L1S_SUCCESS 1
0429 #define PORT_RWE (1 << 3)
0430 #define PORT_HIRD(p) (((p) & 0xf) << 4)
0431 #define PORT_HIRD_MASK (0xf << 4)
0432 #define PORT_L1DS_MASK (0xff << 8)
0433 #define PORT_L1DS(p) (((p) & 0xff) << 8)
0434 #define PORT_HLE (1 << 16)
0435 #define PORT_TEST_MODE_SHIFT 28
0436
0437
0438 #define PORT_RX_LANES(p) (((p) >> 16) & 0xf)
0439 #define PORT_TX_LANES(p) (((p) >> 20) & 0xf)
0440
0441
0442 #define PORT_HIRDM(p)((p) & 3)
0443 #define PORT_L1_TIMEOUT(p)(((p) & 0xff) << 2)
0444 #define PORT_BESLD(p)(((p) & 0xf) << 10)
0445
0446
0447 #define XHCI_L1_TIMEOUT 512
0448
0449
0450
0451
0452
0453
0454
0455
0456
0457
0458
0459 #define XHCI_DEFAULT_BESL 4
0460
0461
0462
0463
0464
0465
0466
0467 #define XHCI_PORT_POLLING_LFPS_TIME 36
0468
0469
0470
0471
0472
0473
0474
0475
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486 struct xhci_intr_reg {
0487 __le32 irq_pending;
0488 __le32 irq_control;
0489 __le32 erst_size;
0490 __le32 rsvd;
0491 __le64 erst_base;
0492 __le64 erst_dequeue;
0493 };
0494
0495
0496 #define ER_IRQ_PENDING(p) ((p) & 0x1)
0497
0498
0499 #define ER_IRQ_CLEAR(p) ((p) & 0xfffffffe)
0500 #define ER_IRQ_ENABLE(p) ((ER_IRQ_CLEAR(p)) | 0x2)
0501 #define ER_IRQ_DISABLE(p) ((ER_IRQ_CLEAR(p)) & ~(0x2))
0502
0503
0504
0505
0506
0507
0508 #define ER_IRQ_INTERVAL_MASK (0xffff)
0509
0510 #define ER_IRQ_COUNTER_MASK (0xffff << 16)
0511
0512
0513
0514 #define ERST_SIZE_MASK (0xffff << 16)
0515
0516
0517
0518
0519
0520 #define ERST_DESI_MASK (0x7)
0521
0522
0523
0524 #define ERST_EHB (1 << 3)
0525 #define ERST_PTR_MASK (0xf)
0526
0527
0528
0529
0530
0531
0532
0533
0534
0535
0536 struct xhci_run_regs {
0537 __le32 microframe_index;
0538 __le32 rsvd[7];
0539 struct xhci_intr_reg ir_set[128];
0540 };
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551 struct xhci_doorbell_array {
0552 __le32 doorbell[256];
0553 };
0554
0555 #define DB_VALUE(ep, stream) ((((ep) + 1) & 0xff) | ((stream) << 16))
0556 #define DB_VALUE_HOST 0x00000000
0557
0558
0559
0560
0561
0562
0563
0564
0565
0566 struct xhci_protocol_caps {
0567 u32 revision;
0568 u32 name_string;
0569 u32 port_info;
0570 };
0571
0572 #define XHCI_EXT_PORT_MAJOR(x) (((x) >> 24) & 0xff)
0573 #define XHCI_EXT_PORT_MINOR(x) (((x) >> 16) & 0xff)
0574 #define XHCI_EXT_PORT_PSIC(x) (((x) >> 28) & 0x0f)
0575 #define XHCI_EXT_PORT_OFF(x) ((x) & 0xff)
0576 #define XHCI_EXT_PORT_COUNT(x) (((x) >> 8) & 0xff)
0577
0578 #define XHCI_EXT_PORT_PSIV(x) (((x) >> 0) & 0x0f)
0579 #define XHCI_EXT_PORT_PSIE(x) (((x) >> 4) & 0x03)
0580 #define XHCI_EXT_PORT_PLT(x) (((x) >> 6) & 0x03)
0581 #define XHCI_EXT_PORT_PFD(x) (((x) >> 8) & 0x01)
0582 #define XHCI_EXT_PORT_LP(x) (((x) >> 14) & 0x03)
0583 #define XHCI_EXT_PORT_PSIM(x) (((x) >> 16) & 0xffff)
0584
0585 #define PLT_MASK (0x03 << 6)
0586 #define PLT_SYM (0x00 << 6)
0587 #define PLT_ASYM_RX (0x02 << 6)
0588 #define PLT_ASYM_TX (0x03 << 6)
0589
0590
0591
0592
0593
0594
0595
0596
0597
0598
0599
0600 struct xhci_container_ctx {
0601 unsigned type;
0602 #define XHCI_CTX_TYPE_DEVICE 0x1
0603 #define XHCI_CTX_TYPE_INPUT 0x2
0604
0605 int size;
0606
0607 u8 *bytes;
0608 dma_addr_t dma;
0609 };
0610
0611
0612
0613
0614
0615
0616
0617
0618
0619
0620
0621
0622 struct xhci_slot_ctx {
0623 __le32 dev_info;
0624 __le32 dev_info2;
0625 __le32 tt_info;
0626 __le32 dev_state;
0627
0628 __le32 reserved[4];
0629 };
0630
0631
0632
0633 #define ROUTE_STRING_MASK (0xfffff)
0634
0635 #define DEV_SPEED (0xf << 20)
0636 #define GET_DEV_SPEED(n) (((n) & DEV_SPEED) >> 20)
0637
0638
0639 #define DEV_MTT (0x1 << 25)
0640
0641 #define DEV_HUB (0x1 << 26)
0642
0643 #define LAST_CTX_MASK (0x1f << 27)
0644 #define LAST_CTX(p) ((p) << 27)
0645 #define LAST_CTX_TO_EP_NUM(p) (((p) >> 27) - 1)
0646 #define SLOT_FLAG (1 << 0)
0647 #define EP0_FLAG (1 << 1)
0648
0649
0650
0651 #define MAX_EXIT (0xffff)
0652
0653 #define ROOT_HUB_PORT(p) (((p) & 0xff) << 16)
0654 #define DEVINFO_TO_ROOT_HUB_PORT(p) (((p) >> 16) & 0xff)
0655
0656 #define XHCI_MAX_PORTS(p) (((p) & 0xff) << 24)
0657 #define DEVINFO_TO_MAX_PORTS(p) (((p) & (0xff << 24)) >> 24)
0658
0659
0660
0661
0662
0663
0664
0665 #define TT_SLOT (0xff)
0666
0667
0668
0669
0670 #define TT_PORT (0xff << 8)
0671 #define TT_THINK_TIME(p) (((p) & 0x3) << 16)
0672 #define GET_TT_THINK_TIME(p) (((p) & (0x3 << 16)) >> 16)
0673
0674
0675
0676 #define DEV_ADDR_MASK (0xff)
0677
0678
0679 #define SLOT_STATE (0x1f << 27)
0680 #define GET_SLOT_STATE(p) (((p) & (0x1f << 27)) >> 27)
0681
0682 #define SLOT_STATE_DISABLED 0
0683 #define SLOT_STATE_ENABLED SLOT_STATE_DISABLED
0684 #define SLOT_STATE_DEFAULT 1
0685 #define SLOT_STATE_ADDRESSED 2
0686 #define SLOT_STATE_CONFIGURED 3
0687
0688
0689
0690
0691
0692
0693
0694
0695
0696
0697
0698
0699
0700
0701
0702
0703
0704
0705
0706 struct xhci_ep_ctx {
0707 __le32 ep_info;
0708 __le32 ep_info2;
0709 __le64 deq;
0710 __le32 tx_info;
0711
0712 __le32 reserved[3];
0713 };
0714
0715
0716
0717
0718
0719
0720
0721
0722
0723
0724
0725 #define EP_STATE_MASK (0x7)
0726 #define EP_STATE_DISABLED 0
0727 #define EP_STATE_RUNNING 1
0728 #define EP_STATE_HALTED 2
0729 #define EP_STATE_STOPPED 3
0730 #define EP_STATE_ERROR 4
0731 #define GET_EP_CTX_STATE(ctx) (le32_to_cpu((ctx)->ep_info) & EP_STATE_MASK)
0732
0733
0734 #define EP_MULT(p) (((p) & 0x3) << 8)
0735 #define CTX_TO_EP_MULT(p) (((p) >> 8) & 0x3)
0736
0737
0738
0739 #define EP_INTERVAL(p) (((p) & 0xff) << 16)
0740 #define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff))
0741 #define CTX_TO_EP_INTERVAL(p) (((p) >> 16) & 0xff)
0742 #define EP_MAXPSTREAMS_MASK (0x1f << 10)
0743 #define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK)
0744 #define CTX_TO_EP_MAXPSTREAMS(p) (((p) & EP_MAXPSTREAMS_MASK) >> 10)
0745
0746 #define EP_HAS_LSA (1 << 15)
0747
0748 #define CTX_TO_MAX_ESIT_PAYLOAD_HI(p) (((p) >> 24) & 0xff)
0749
0750
0751
0752
0753
0754
0755 #define FORCE_EVENT (0x1)
0756 #define ERROR_COUNT(p) (((p) & 0x3) << 1)
0757 #define CTX_TO_EP_TYPE(p) (((p) >> 3) & 0x7)
0758 #define EP_TYPE(p) ((p) << 3)
0759 #define ISOC_OUT_EP 1
0760 #define BULK_OUT_EP 2
0761 #define INT_OUT_EP 3
0762 #define CTRL_EP 4
0763 #define ISOC_IN_EP 5
0764 #define BULK_IN_EP 6
0765 #define INT_IN_EP 7
0766
0767
0768 #define MAX_BURST(p) (((p)&0xff) << 8)
0769 #define CTX_TO_MAX_BURST(p) (((p) >> 8) & 0xff)
0770 #define MAX_PACKET(p) (((p)&0xffff) << 16)
0771 #define MAX_PACKET_MASK (0xffff << 16)
0772 #define MAX_PACKET_DECODED(p) (((p) >> 16) & 0xffff)
0773
0774
0775 #define EP_AVG_TRB_LENGTH(p) ((p) & 0xffff)
0776 #define EP_MAX_ESIT_PAYLOAD_LO(p) (((p) & 0xffff) << 16)
0777 #define EP_MAX_ESIT_PAYLOAD_HI(p) ((((p) >> 16) & 0xff) << 24)
0778 #define CTX_TO_MAX_ESIT_PAYLOAD(p) (((p) >> 16) & 0xffff)
0779
0780
0781 #define EP_CTX_CYCLE_MASK (1 << 0)
0782 #define SCTX_DEQ_MASK (~0xfL)
0783
0784
0785
0786
0787
0788
0789
0790
0791
0792 struct xhci_input_control_ctx {
0793 __le32 drop_flags;
0794 __le32 add_flags;
0795 __le32 rsvd2[6];
0796 };
0797
0798 #define EP_IS_ADDED(ctrl_ctx, i) \
0799 (le32_to_cpu(ctrl_ctx->add_flags) & (1 << (i + 1)))
0800 #define EP_IS_DROPPED(ctrl_ctx, i) \
0801 (le32_to_cpu(ctrl_ctx->drop_flags) & (1 << (i + 1)))
0802
0803
0804
0805
0806
0807 struct xhci_command {
0808
0809 struct xhci_container_ctx *in_ctx;
0810 u32 status;
0811 int slot_id;
0812
0813
0814
0815 struct completion *completion;
0816 union xhci_trb *command_trb;
0817 struct list_head cmd_list;
0818 };
0819
0820
0821 #define DROP_EP(x) (0x1 << x)
0822
0823 #define ADD_EP(x) (0x1 << x)
0824
0825 struct xhci_stream_ctx {
0826
0827 __le64 stream_ring;
0828
0829 __le32 reserved[2];
0830 };
0831
0832
0833 #define SCT_FOR_CTX(p) (((p) & 0x7) << 1)
0834
0835 #define SCT_SEC_TR 0
0836
0837 #define SCT_PRI_TR 1
0838
0839 #define SCT_SSA_8 2
0840 #define SCT_SSA_16 3
0841 #define SCT_SSA_32 4
0842 #define SCT_SSA_64 5
0843 #define SCT_SSA_128 6
0844 #define SCT_SSA_256 7
0845
0846
0847 struct xhci_stream_info {
0848 struct xhci_ring **stream_rings;
0849
0850 unsigned int num_streams;
0851
0852
0853
0854 struct xhci_stream_ctx *stream_ctx_array;
0855 unsigned int num_stream_ctxs;
0856 dma_addr_t ctx_array_dma;
0857
0858 struct radix_tree_root trb_address_map;
0859 struct xhci_command *free_streams_command;
0860 };
0861
0862 #define SMALL_STREAM_ARRAY_SIZE 256
0863 #define MEDIUM_STREAM_ARRAY_SIZE 1024
0864
0865
0866
0867
0868
0869
0870
0871 struct xhci_bw_info {
0872
0873 unsigned int ep_interval;
0874
0875 unsigned int mult;
0876 unsigned int num_packets;
0877 unsigned int max_packet_size;
0878 unsigned int max_esit_payload;
0879 unsigned int type;
0880 };
0881
0882
0883
0884
0885
0886
0887 #define FS_BLOCK 1
0888 #define HS_BLOCK 4
0889 #define SS_BLOCK 16
0890 #define DMI_BLOCK 32
0891
0892
0893
0894
0895
0896
0897 #define DMI_OVERHEAD 8
0898 #define DMI_OVERHEAD_BURST 4
0899 #define SS_OVERHEAD 8
0900 #define SS_OVERHEAD_BURST 32
0901 #define HS_OVERHEAD 26
0902 #define FS_OVERHEAD 20
0903 #define LS_OVERHEAD 128
0904
0905
0906
0907
0908
0909 #define TT_HS_OVERHEAD (31 + 94)
0910 #define TT_DMI_OVERHEAD (25 + 12)
0911
0912
0913 #define FS_BW_LIMIT 1285
0914 #define TT_BW_LIMIT 1320
0915 #define HS_BW_LIMIT 1607
0916 #define SS_BW_LIMIT_IN 3906
0917 #define DMI_BW_LIMIT_IN 3906
0918 #define SS_BW_LIMIT_OUT 3906
0919 #define DMI_BW_LIMIT_OUT 3906
0920
0921
0922 #define FS_BW_RESERVED 10
0923 #define HS_BW_RESERVED 20
0924 #define SS_BW_RESERVED 10
0925
0926 struct xhci_virt_ep {
0927 struct xhci_virt_device *vdev;
0928 unsigned int ep_index;
0929 struct xhci_ring *ring;
0930
0931 struct xhci_stream_info *stream_info;
0932
0933
0934
0935 struct xhci_ring *new_ring;
0936 unsigned int ep_state;
0937 #define SET_DEQ_PENDING (1 << 0)
0938 #define EP_HALTED (1 << 1)
0939 #define EP_STOP_CMD_PENDING (1 << 2)
0940
0941 #define EP_GETTING_STREAMS (1 << 3)
0942 #define EP_HAS_STREAMS (1 << 4)
0943
0944 #define EP_GETTING_NO_STREAMS (1 << 5)
0945 #define EP_HARD_CLEAR_TOGGLE (1 << 6)
0946 #define EP_SOFT_CLEAR_TOGGLE (1 << 7)
0947
0948 #define EP_CLEARING_TT (1 << 8)
0949
0950 struct list_head cancelled_td_list;
0951 struct xhci_hcd *xhci;
0952
0953
0954
0955
0956 struct xhci_segment *queued_deq_seg;
0957 union xhci_trb *queued_deq_ptr;
0958
0959
0960
0961
0962
0963
0964
0965 bool skip;
0966
0967 struct xhci_bw_info bw_info;
0968 struct list_head bw_endpoint_list;
0969
0970 int next_frame_id;
0971
0972 bool use_extended_tbc;
0973 };
0974
0975 enum xhci_overhead_type {
0976 LS_OVERHEAD_TYPE = 0,
0977 FS_OVERHEAD_TYPE,
0978 HS_OVERHEAD_TYPE,
0979 };
0980
0981 struct xhci_interval_bw {
0982 unsigned int num_packets;
0983
0984
0985
0986 struct list_head endpoints;
0987
0988 unsigned int overhead[3];
0989 };
0990
0991 #define XHCI_MAX_INTERVAL 16
0992
0993 struct xhci_interval_bw_table {
0994 unsigned int interval0_esit_payload;
0995 struct xhci_interval_bw interval_bw[XHCI_MAX_INTERVAL];
0996
0997 unsigned int bw_used;
0998 unsigned int ss_bw_in;
0999 unsigned int ss_bw_out;
1000 };
1001
1002 #define EP_CTX_PER_DEV 31
1003
1004 struct xhci_virt_device {
1005 int slot_id;
1006 struct usb_device *udev;
1007
1008
1009
1010
1011
1012
1013
1014
1015 struct xhci_container_ctx *out_ctx;
1016
1017 struct xhci_container_ctx *in_ctx;
1018 struct xhci_virt_ep eps[EP_CTX_PER_DEV];
1019 u8 fake_port;
1020 u8 real_port;
1021 struct xhci_interval_bw_table *bw_table;
1022 struct xhci_tt_bw_info *tt_info;
1023
1024
1025
1026
1027
1028
1029 unsigned long flags;
1030 #define VDEV_PORT_ERROR BIT(0)
1031
1032
1033 u16 current_mel;
1034
1035 void *debugfs_private;
1036 };
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046 struct xhci_root_port_bw_info {
1047 struct list_head tts;
1048 unsigned int num_active_tts;
1049 struct xhci_interval_bw_table bw_table;
1050 };
1051
1052 struct xhci_tt_bw_info {
1053 struct list_head tt_list;
1054 int slot_id;
1055 int ttport;
1056 struct xhci_interval_bw_table bw_table;
1057 int active_eps;
1058 };
1059
1060
1061
1062
1063
1064
1065 struct xhci_device_context_array {
1066
1067 __le64 dev_context_ptrs[MAX_HC_SLOTS];
1068
1069 dma_addr_t dma;
1070 };
1071
1072
1073
1074
1075
1076
1077
1078 struct xhci_transfer_event {
1079
1080 __le64 buffer;
1081 __le32 transfer_len;
1082
1083 __le32 flags;
1084 };
1085
1086
1087
1088 #define EVENT_TRB_LEN(p) ((p) & 0xffffff)
1089
1090
1091 #define TRB_TO_EP_ID(p) (((p) >> 16) & 0x1f)
1092
1093
1094 #define COMP_CODE_MASK (0xff << 24)
1095 #define GET_COMP_CODE(p) (((p) & COMP_CODE_MASK) >> 24)
1096 #define COMP_INVALID 0
1097 #define COMP_SUCCESS 1
1098 #define COMP_DATA_BUFFER_ERROR 2
1099 #define COMP_BABBLE_DETECTED_ERROR 3
1100 #define COMP_USB_TRANSACTION_ERROR 4
1101 #define COMP_TRB_ERROR 5
1102 #define COMP_STALL_ERROR 6
1103 #define COMP_RESOURCE_ERROR 7
1104 #define COMP_BANDWIDTH_ERROR 8
1105 #define COMP_NO_SLOTS_AVAILABLE_ERROR 9
1106 #define COMP_INVALID_STREAM_TYPE_ERROR 10
1107 #define COMP_SLOT_NOT_ENABLED_ERROR 11
1108 #define COMP_ENDPOINT_NOT_ENABLED_ERROR 12
1109 #define COMP_SHORT_PACKET 13
1110 #define COMP_RING_UNDERRUN 14
1111 #define COMP_RING_OVERRUN 15
1112 #define COMP_VF_EVENT_RING_FULL_ERROR 16
1113 #define COMP_PARAMETER_ERROR 17
1114 #define COMP_BANDWIDTH_OVERRUN_ERROR 18
1115 #define COMP_CONTEXT_STATE_ERROR 19
1116 #define COMP_NO_PING_RESPONSE_ERROR 20
1117 #define COMP_EVENT_RING_FULL_ERROR 21
1118 #define COMP_INCOMPATIBLE_DEVICE_ERROR 22
1119 #define COMP_MISSED_SERVICE_ERROR 23
1120 #define COMP_COMMAND_RING_STOPPED 24
1121 #define COMP_COMMAND_ABORTED 25
1122 #define COMP_STOPPED 26
1123 #define COMP_STOPPED_LENGTH_INVALID 27
1124 #define COMP_STOPPED_SHORT_PACKET 28
1125 #define COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR 29
1126 #define COMP_ISOCH_BUFFER_OVERRUN 31
1127 #define COMP_EVENT_LOST_ERROR 32
1128 #define COMP_UNDEFINED_ERROR 33
1129 #define COMP_INVALID_STREAM_ID_ERROR 34
1130 #define COMP_SECONDARY_BANDWIDTH_ERROR 35
1131 #define COMP_SPLIT_TRANSACTION_ERROR 36
1132
1133 static inline const char *xhci_trb_comp_code_string(u8 status)
1134 {
1135 switch (status) {
1136 case COMP_INVALID:
1137 return "Invalid";
1138 case COMP_SUCCESS:
1139 return "Success";
1140 case COMP_DATA_BUFFER_ERROR:
1141 return "Data Buffer Error";
1142 case COMP_BABBLE_DETECTED_ERROR:
1143 return "Babble Detected";
1144 case COMP_USB_TRANSACTION_ERROR:
1145 return "USB Transaction Error";
1146 case COMP_TRB_ERROR:
1147 return "TRB Error";
1148 case COMP_STALL_ERROR:
1149 return "Stall Error";
1150 case COMP_RESOURCE_ERROR:
1151 return "Resource Error";
1152 case COMP_BANDWIDTH_ERROR:
1153 return "Bandwidth Error";
1154 case COMP_NO_SLOTS_AVAILABLE_ERROR:
1155 return "No Slots Available Error";
1156 case COMP_INVALID_STREAM_TYPE_ERROR:
1157 return "Invalid Stream Type Error";
1158 case COMP_SLOT_NOT_ENABLED_ERROR:
1159 return "Slot Not Enabled Error";
1160 case COMP_ENDPOINT_NOT_ENABLED_ERROR:
1161 return "Endpoint Not Enabled Error";
1162 case COMP_SHORT_PACKET:
1163 return "Short Packet";
1164 case COMP_RING_UNDERRUN:
1165 return "Ring Underrun";
1166 case COMP_RING_OVERRUN:
1167 return "Ring Overrun";
1168 case COMP_VF_EVENT_RING_FULL_ERROR:
1169 return "VF Event Ring Full Error";
1170 case COMP_PARAMETER_ERROR:
1171 return "Parameter Error";
1172 case COMP_BANDWIDTH_OVERRUN_ERROR:
1173 return "Bandwidth Overrun Error";
1174 case COMP_CONTEXT_STATE_ERROR:
1175 return "Context State Error";
1176 case COMP_NO_PING_RESPONSE_ERROR:
1177 return "No Ping Response Error";
1178 case COMP_EVENT_RING_FULL_ERROR:
1179 return "Event Ring Full Error";
1180 case COMP_INCOMPATIBLE_DEVICE_ERROR:
1181 return "Incompatible Device Error";
1182 case COMP_MISSED_SERVICE_ERROR:
1183 return "Missed Service Error";
1184 case COMP_COMMAND_RING_STOPPED:
1185 return "Command Ring Stopped";
1186 case COMP_COMMAND_ABORTED:
1187 return "Command Aborted";
1188 case COMP_STOPPED:
1189 return "Stopped";
1190 case COMP_STOPPED_LENGTH_INVALID:
1191 return "Stopped - Length Invalid";
1192 case COMP_STOPPED_SHORT_PACKET:
1193 return "Stopped - Short Packet";
1194 case COMP_MAX_EXIT_LATENCY_TOO_LARGE_ERROR:
1195 return "Max Exit Latency Too Large Error";
1196 case COMP_ISOCH_BUFFER_OVERRUN:
1197 return "Isoch Buffer Overrun";
1198 case COMP_EVENT_LOST_ERROR:
1199 return "Event Lost Error";
1200 case COMP_UNDEFINED_ERROR:
1201 return "Undefined Error";
1202 case COMP_INVALID_STREAM_ID_ERROR:
1203 return "Invalid Stream ID Error";
1204 case COMP_SECONDARY_BANDWIDTH_ERROR:
1205 return "Secondary Bandwidth Error";
1206 case COMP_SPLIT_TRANSACTION_ERROR:
1207 return "Split Transaction Error";
1208 default:
1209 return "Unknown!!";
1210 }
1211 }
1212
1213 struct xhci_link_trb {
1214
1215 __le64 segment_ptr;
1216 __le32 intr_target;
1217 __le32 control;
1218 };
1219
1220
1221 #define LINK_TOGGLE (0x1<<1)
1222
1223
1224 struct xhci_event_cmd {
1225
1226 __le64 cmd_trb;
1227 __le32 status;
1228 __le32 flags;
1229 };
1230
1231
1232
1233
1234 #define TRB_BSR (1<<9)
1235
1236
1237 #define TRB_DC (1<<9)
1238
1239
1240 #define TRB_TSP (1<<9)
1241
1242 enum xhci_ep_reset_type {
1243 EP_HARD_RESET,
1244 EP_SOFT_RESET,
1245 };
1246
1247
1248 #define TRB_TO_VF_INTR_TARGET(p) (((p) & (0x3ff << 22)) >> 22)
1249 #define TRB_TO_VF_ID(p) (((p) & (0xff << 16)) >> 16)
1250
1251
1252 #define TRB_TO_BELT(p) (((p) & (0xfff << 16)) >> 16)
1253
1254
1255 #define TRB_TO_DEV_SPEED(p) (((p) & (0xf << 16)) >> 16)
1256
1257
1258 #define TRB_TO_PACKET_TYPE(p) ((p) & 0x1f)
1259 #define TRB_TO_ROOTHUB_PORT(p) (((p) & (0xff << 24)) >> 24)
1260
1261 enum xhci_setup_dev {
1262 SETUP_CONTEXT_ONLY,
1263 SETUP_CONTEXT_ADDRESS,
1264 };
1265
1266
1267
1268 #define TRB_TO_SLOT_ID(p) (((p) & (0xff<<24)) >> 24)
1269 #define SLOT_ID_FOR_TRB(p) (((p) & 0xff) << 24)
1270
1271
1272 #define TRB_TO_EP_INDEX(p) ((((p) & (0x1f << 16)) >> 16) - 1)
1273 #define EP_ID_FOR_TRB(p) ((((p) + 1) & 0x1f) << 16)
1274
1275 #define SUSPEND_PORT_FOR_TRB(p) (((p) & 1) << 23)
1276 #define TRB_TO_SUSPEND_PORT(p) (((p) & (1 << 23)) >> 23)
1277 #define LAST_EP_INDEX 30
1278
1279
1280 #define TRB_TO_STREAM_ID(p) ((((p) & (0xffff << 16)) >> 16))
1281 #define STREAM_ID_FOR_TRB(p) ((((p)) & 0xffff) << 16)
1282 #define SCT_FOR_TRB(p) (((p) << 1) & 0x7)
1283
1284
1285 #define TRB_TC (1<<1)
1286
1287
1288
1289 #define GET_PORT_ID(p) (((p) & (0xff << 24)) >> 24)
1290
1291 #define EVENT_DATA (1 << 2)
1292
1293
1294
1295 #define TRB_LEN(p) ((p) & 0x1ffff)
1296
1297 #define TRB_TD_SIZE(p) (min((p), (u32)31) << 17)
1298 #define GET_TD_SIZE(p) (((p) & 0x3e0000) >> 17)
1299
1300 #define TRB_TD_SIZE_TBC(p) (min((p), (u32)31) << 17)
1301
1302 #define TRB_INTR_TARGET(p) (((p) & 0x3ff) << 22)
1303 #define GET_INTR_TARGET(p) (((p) >> 22) & 0x3ff)
1304
1305 #define TRB_TBC(p) (((p) & 0x3) << 7)
1306 #define TRB_TLBPC(p) (((p) & 0xf) << 16)
1307
1308
1309 #define TRB_CYCLE (1<<0)
1310
1311
1312
1313
1314 #define TRB_ENT (1<<1)
1315
1316 #define TRB_ISP (1<<2)
1317
1318 #define TRB_NO_SNOOP (1<<3)
1319
1320 #define TRB_CHAIN (1<<4)
1321
1322 #define TRB_IOC (1<<5)
1323
1324 #define TRB_IDT (1<<6)
1325
1326 #define TRB_IDT_MAX_SIZE 8
1327
1328
1329 #define TRB_BEI (1<<9)
1330
1331
1332 #define TRB_DIR_IN (1<<16)
1333 #define TRB_TX_TYPE(p) ((p) << 16)
1334 #define TRB_DATA_OUT 2
1335 #define TRB_DATA_IN 3
1336
1337
1338 #define TRB_SIA (1<<31)
1339 #define TRB_FRAME_ID(p) (((p) & 0x7ff) << 20)
1340
1341
1342 #define TRB_CACHE_SIZE_HS 8
1343 #define TRB_CACHE_SIZE_SS 16
1344
1345 struct xhci_generic_trb {
1346 __le32 field[4];
1347 };
1348
1349 union xhci_trb {
1350 struct xhci_link_trb link;
1351 struct xhci_transfer_event trans_event;
1352 struct xhci_event_cmd event_cmd;
1353 struct xhci_generic_trb generic;
1354 };
1355
1356
1357 #define TRB_TYPE_BITMASK (0xfc00)
1358 #define TRB_TYPE(p) ((p) << 10)
1359 #define TRB_FIELD_TO_TYPE(p) (((p) & TRB_TYPE_BITMASK) >> 10)
1360
1361
1362 #define TRB_NORMAL 1
1363
1364 #define TRB_SETUP 2
1365
1366 #define TRB_DATA 3
1367
1368 #define TRB_STATUS 4
1369
1370 #define TRB_ISOC 5
1371
1372 #define TRB_LINK 6
1373 #define TRB_EVENT_DATA 7
1374
1375 #define TRB_TR_NOOP 8
1376
1377
1378 #define TRB_ENABLE_SLOT 9
1379
1380 #define TRB_DISABLE_SLOT 10
1381
1382 #define TRB_ADDR_DEV 11
1383
1384 #define TRB_CONFIG_EP 12
1385
1386 #define TRB_EVAL_CONTEXT 13
1387
1388 #define TRB_RESET_EP 14
1389
1390 #define TRB_STOP_RING 15
1391
1392 #define TRB_SET_DEQ 16
1393
1394 #define TRB_RESET_DEV 17
1395
1396 #define TRB_FORCE_EVENT 18
1397
1398 #define TRB_NEG_BANDWIDTH 19
1399
1400 #define TRB_SET_LT 20
1401
1402 #define TRB_GET_BW 21
1403
1404 #define TRB_FORCE_HEADER 22
1405
1406 #define TRB_CMD_NOOP 23
1407
1408
1409
1410 #define TRB_TRANSFER 32
1411
1412 #define TRB_COMPLETION 33
1413
1414 #define TRB_PORT_STATUS 34
1415
1416 #define TRB_BANDWIDTH_EVENT 35
1417
1418 #define TRB_DOORBELL 36
1419
1420 #define TRB_HC_EVENT 37
1421
1422 #define TRB_DEV_NOTE 38
1423
1424 #define TRB_MFINDEX_WRAP 39
1425
1426 #define TRB_VENDOR_DEFINED_LOW 48
1427
1428 #define TRB_NEC_CMD_COMP 48
1429
1430 #define TRB_NEC_GET_FW 49
1431
1432 static inline const char *xhci_trb_type_string(u8 type)
1433 {
1434 switch (type) {
1435 case TRB_NORMAL:
1436 return "Normal";
1437 case TRB_SETUP:
1438 return "Setup Stage";
1439 case TRB_DATA:
1440 return "Data Stage";
1441 case TRB_STATUS:
1442 return "Status Stage";
1443 case TRB_ISOC:
1444 return "Isoch";
1445 case TRB_LINK:
1446 return "Link";
1447 case TRB_EVENT_DATA:
1448 return "Event Data";
1449 case TRB_TR_NOOP:
1450 return "No-Op";
1451 case TRB_ENABLE_SLOT:
1452 return "Enable Slot Command";
1453 case TRB_DISABLE_SLOT:
1454 return "Disable Slot Command";
1455 case TRB_ADDR_DEV:
1456 return "Address Device Command";
1457 case TRB_CONFIG_EP:
1458 return "Configure Endpoint Command";
1459 case TRB_EVAL_CONTEXT:
1460 return "Evaluate Context Command";
1461 case TRB_RESET_EP:
1462 return "Reset Endpoint Command";
1463 case TRB_STOP_RING:
1464 return "Stop Ring Command";
1465 case TRB_SET_DEQ:
1466 return "Set TR Dequeue Pointer Command";
1467 case TRB_RESET_DEV:
1468 return "Reset Device Command";
1469 case TRB_FORCE_EVENT:
1470 return "Force Event Command";
1471 case TRB_NEG_BANDWIDTH:
1472 return "Negotiate Bandwidth Command";
1473 case TRB_SET_LT:
1474 return "Set Latency Tolerance Value Command";
1475 case TRB_GET_BW:
1476 return "Get Port Bandwidth Command";
1477 case TRB_FORCE_HEADER:
1478 return "Force Header Command";
1479 case TRB_CMD_NOOP:
1480 return "No-Op Command";
1481 case TRB_TRANSFER:
1482 return "Transfer Event";
1483 case TRB_COMPLETION:
1484 return "Command Completion Event";
1485 case TRB_PORT_STATUS:
1486 return "Port Status Change Event";
1487 case TRB_BANDWIDTH_EVENT:
1488 return "Bandwidth Request Event";
1489 case TRB_DOORBELL:
1490 return "Doorbell Event";
1491 case TRB_HC_EVENT:
1492 return "Host Controller Event";
1493 case TRB_DEV_NOTE:
1494 return "Device Notification Event";
1495 case TRB_MFINDEX_WRAP:
1496 return "MFINDEX Wrap Event";
1497 case TRB_NEC_CMD_COMP:
1498 return "NEC Command Completion Event";
1499 case TRB_NEC_GET_FW:
1500 return "NET Get Firmware Revision Command";
1501 default:
1502 return "UNKNOWN";
1503 }
1504 }
1505
1506 #define TRB_TYPE_LINK(x) (((x) & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK))
1507
1508 #define TRB_TYPE_LINK_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
1509 cpu_to_le32(TRB_TYPE(TRB_LINK)))
1510 #define TRB_TYPE_NOOP_LE32(x) (((x) & cpu_to_le32(TRB_TYPE_BITMASK)) == \
1511 cpu_to_le32(TRB_TYPE(TRB_TR_NOOP)))
1512
1513 #define NEC_FW_MINOR(p) (((p) >> 0) & 0xff)
1514 #define NEC_FW_MAJOR(p) (((p) >> 8) & 0xff)
1515
1516
1517
1518
1519
1520
1521 #define TRBS_PER_SEGMENT 256
1522
1523 #define MAX_RSVD_CMD_TRBS (TRBS_PER_SEGMENT - 3)
1524 #define TRB_SEGMENT_SIZE (TRBS_PER_SEGMENT*16)
1525 #define TRB_SEGMENT_SHIFT (ilog2(TRB_SEGMENT_SIZE))
1526
1527 #define TRB_MAX_BUFF_SHIFT 16
1528 #define TRB_MAX_BUFF_SIZE (1 << TRB_MAX_BUFF_SHIFT)
1529
1530 #define TRB_BUFF_LEN_UP_TO_BOUNDARY(addr) (TRB_MAX_BUFF_SIZE - \
1531 (addr & (TRB_MAX_BUFF_SIZE - 1)))
1532 #define MAX_SOFT_RETRY 3
1533
1534
1535
1536
1537 #define AVOID_BEI_INTERVAL_MIN 8
1538 #define AVOID_BEI_INTERVAL_MAX 32
1539
1540 struct xhci_segment {
1541 union xhci_trb *trbs;
1542
1543 struct xhci_segment *next;
1544 dma_addr_t dma;
1545
1546 dma_addr_t bounce_dma;
1547 void *bounce_buf;
1548 unsigned int bounce_offs;
1549 unsigned int bounce_len;
1550 };
1551
1552 enum xhci_cancelled_td_status {
1553 TD_DIRTY = 0,
1554 TD_HALTED,
1555 TD_CLEARING_CACHE,
1556 TD_CLEARED,
1557 };
1558
1559 struct xhci_td {
1560 struct list_head td_list;
1561 struct list_head cancelled_td_list;
1562 int status;
1563 enum xhci_cancelled_td_status cancel_status;
1564 struct urb *urb;
1565 struct xhci_segment *start_seg;
1566 union xhci_trb *first_trb;
1567 union xhci_trb *last_trb;
1568 struct xhci_segment *last_trb_seg;
1569 struct xhci_segment *bounce_seg;
1570
1571 bool urb_length_set;
1572 unsigned int num_trbs;
1573 };
1574
1575
1576 #define XHCI_CMD_DEFAULT_TIMEOUT (5 * HZ)
1577
1578
1579 struct xhci_cd {
1580 struct xhci_command *command;
1581 union xhci_trb *cmd_trb;
1582 };
1583
1584 enum xhci_ring_type {
1585 TYPE_CTRL = 0,
1586 TYPE_ISOC,
1587 TYPE_BULK,
1588 TYPE_INTR,
1589 TYPE_STREAM,
1590 TYPE_COMMAND,
1591 TYPE_EVENT,
1592 };
1593
1594 static inline const char *xhci_ring_type_string(enum xhci_ring_type type)
1595 {
1596 switch (type) {
1597 case TYPE_CTRL:
1598 return "CTRL";
1599 case TYPE_ISOC:
1600 return "ISOC";
1601 case TYPE_BULK:
1602 return "BULK";
1603 case TYPE_INTR:
1604 return "INTR";
1605 case TYPE_STREAM:
1606 return "STREAM";
1607 case TYPE_COMMAND:
1608 return "CMD";
1609 case TYPE_EVENT:
1610 return "EVENT";
1611 }
1612
1613 return "UNKNOWN";
1614 }
1615
1616 struct xhci_ring {
1617 struct xhci_segment *first_seg;
1618 struct xhci_segment *last_seg;
1619 union xhci_trb *enqueue;
1620 struct xhci_segment *enq_seg;
1621 union xhci_trb *dequeue;
1622 struct xhci_segment *deq_seg;
1623 struct list_head td_list;
1624
1625
1626
1627
1628
1629 u32 cycle_state;
1630 unsigned int err_count;
1631 unsigned int stream_id;
1632 unsigned int num_segs;
1633 unsigned int num_trbs_free;
1634 unsigned int num_trbs_free_temp;
1635 unsigned int bounce_buf_len;
1636 enum xhci_ring_type type;
1637 bool last_td_was_short;
1638 struct radix_tree_root *trb_address_map;
1639 };
1640
1641 struct xhci_erst_entry {
1642
1643 __le64 seg_addr;
1644 __le32 seg_size;
1645
1646 __le32 rsvd;
1647 };
1648
1649 struct xhci_erst {
1650 struct xhci_erst_entry *entries;
1651 unsigned int num_entries;
1652
1653 dma_addr_t erst_dma_addr;
1654
1655 unsigned int erst_size;
1656 };
1657
1658 struct xhci_scratchpad {
1659 u64 *sp_array;
1660 dma_addr_t sp_dma;
1661 void **sp_buffers;
1662 };
1663
1664 struct urb_priv {
1665 int num_tds;
1666 int num_tds_done;
1667 struct xhci_td td[];
1668 };
1669
1670
1671
1672
1673
1674
1675 #define ERST_NUM_SEGS 1
1676
1677 #define POLL_TIMEOUT 60
1678
1679 #define XHCI_STOP_EP_CMD_TIMEOUT 5
1680
1681
1682 struct s3_save {
1683 u32 command;
1684 u32 dev_nt;
1685 u64 dcbaa_ptr;
1686 u32 config_reg;
1687 u32 irq_pending;
1688 u32 irq_control;
1689 u32 erst_size;
1690 u64 erst_base;
1691 u64 erst_dequeue;
1692 };
1693
1694
1695 struct dev_info {
1696 u32 dev_id;
1697 struct list_head list;
1698 };
1699
1700 struct xhci_bus_state {
1701 unsigned long bus_suspended;
1702 unsigned long next_statechange;
1703
1704
1705
1706 u32 port_c_suspend;
1707 u32 suspended_ports;
1708 u32 port_remote_wakeup;
1709 unsigned long resume_done[USB_MAXCHILDREN];
1710
1711 unsigned long resuming_ports;
1712
1713 unsigned long rexit_ports;
1714 struct completion rexit_done[USB_MAXCHILDREN];
1715 struct completion u3exit_done[USB_MAXCHILDREN];
1716 };
1717
1718
1719
1720
1721
1722
1723 #define XHCI_MAX_REXIT_TIMEOUT_MS 20
1724 struct xhci_port_cap {
1725 u32 *psi;
1726 u8 psi_count;
1727 u8 psi_uid_count;
1728 u8 maj_rev;
1729 u8 min_rev;
1730 };
1731
1732 struct xhci_port {
1733 __le32 __iomem *addr;
1734 int hw_portnum;
1735 int hcd_portnum;
1736 struct xhci_hub *rhub;
1737 struct xhci_port_cap *port_cap;
1738 };
1739
1740 struct xhci_hub {
1741 struct xhci_port **ports;
1742 unsigned int num_ports;
1743 struct usb_hcd *hcd;
1744
1745 struct xhci_bus_state bus_state;
1746
1747 u8 maj_rev;
1748 u8 min_rev;
1749 };
1750
1751
1752 struct xhci_hcd {
1753 struct usb_hcd *main_hcd;
1754 struct usb_hcd *shared_hcd;
1755
1756 struct xhci_cap_regs __iomem *cap_regs;
1757 struct xhci_op_regs __iomem *op_regs;
1758 struct xhci_run_regs __iomem *run_regs;
1759 struct xhci_doorbell_array __iomem *dba;
1760
1761 struct xhci_intr_reg __iomem *ir_set;
1762
1763
1764 __u32 hcs_params1;
1765 __u32 hcs_params2;
1766 __u32 hcs_params3;
1767 __u32 hcc_params;
1768 __u32 hcc_params2;
1769
1770 spinlock_t lock;
1771
1772
1773 u8 sbrn;
1774 u16 hci_version;
1775 u8 max_slots;
1776 u8 max_interrupters;
1777 u8 max_ports;
1778 u8 isoc_threshold;
1779
1780 u32 imod_interval;
1781 u32 isoc_bei_interval;
1782 int event_ring_max;
1783
1784 int page_size;
1785
1786 int page_shift;
1787
1788 int msix_count;
1789
1790 struct clk *clk;
1791 struct clk *reg_clk;
1792
1793 struct reset_control *reset;
1794
1795 struct xhci_device_context_array *dcbaa;
1796 struct xhci_ring *cmd_ring;
1797 unsigned int cmd_ring_state;
1798 #define CMD_RING_STATE_RUNNING (1 << 0)
1799 #define CMD_RING_STATE_ABORTED (1 << 1)
1800 #define CMD_RING_STATE_STOPPED (1 << 2)
1801 struct list_head cmd_list;
1802 unsigned int cmd_ring_reserved_trbs;
1803 struct delayed_work cmd_timer;
1804 struct completion cmd_ring_stop_completion;
1805 struct xhci_command *current_cmd;
1806 struct xhci_ring *event_ring;
1807 struct xhci_erst erst;
1808
1809 struct xhci_scratchpad *scratchpad;
1810
1811 struct list_head lpm_failed_devs;
1812
1813
1814
1815 struct mutex mutex;
1816
1817 struct xhci_virt_device *devs[MAX_HC_SLOTS];
1818
1819 struct xhci_root_port_bw_info *rh_bw;
1820
1821
1822 struct dma_pool *device_pool;
1823 struct dma_pool *segment_pool;
1824 struct dma_pool *small_streams_pool;
1825 struct dma_pool *medium_streams_pool;
1826
1827
1828 unsigned int xhc_state;
1829 unsigned long run_graceperiod;
1830 u32 command;
1831 struct s3_save s3;
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844 #define XHCI_STATE_DYING (1 << 0)
1845 #define XHCI_STATE_HALTED (1 << 1)
1846 #define XHCI_STATE_REMOVING (1 << 2)
1847 unsigned long long quirks;
1848 #define XHCI_LINK_TRB_QUIRK BIT_ULL(0)
1849 #define XHCI_RESET_EP_QUIRK BIT_ULL(1)
1850 #define XHCI_NEC_HOST BIT_ULL(2)
1851 #define XHCI_AMD_PLL_FIX BIT_ULL(3)
1852 #define XHCI_SPURIOUS_SUCCESS BIT_ULL(4)
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862 #define XHCI_EP_LIMIT_QUIRK BIT_ULL(5)
1863 #define XHCI_BROKEN_MSI BIT_ULL(6)
1864 #define XHCI_RESET_ON_RESUME BIT_ULL(7)
1865 #define XHCI_SW_BW_CHECKING BIT_ULL(8)
1866 #define XHCI_AMD_0x96_HOST BIT_ULL(9)
1867 #define XHCI_TRUST_TX_LENGTH BIT_ULL(10)
1868 #define XHCI_LPM_SUPPORT BIT_ULL(11)
1869 #define XHCI_INTEL_HOST BIT_ULL(12)
1870 #define XHCI_SPURIOUS_REBOOT BIT_ULL(13)
1871 #define XHCI_COMP_MODE_QUIRK BIT_ULL(14)
1872 #define XHCI_AVOID_BEI BIT_ULL(15)
1873 #define XHCI_PLAT BIT_ULL(16)
1874 #define XHCI_SLOW_SUSPEND BIT_ULL(17)
1875 #define XHCI_SPURIOUS_WAKEUP BIT_ULL(18)
1876
1877 #define XHCI_BROKEN_STREAMS BIT_ULL(19)
1878 #define XHCI_PME_STUCK_QUIRK BIT_ULL(20)
1879 #define XHCI_MTK_HOST BIT_ULL(21)
1880 #define XHCI_SSIC_PORT_UNUSED BIT_ULL(22)
1881 #define XHCI_NO_64BIT_SUPPORT BIT_ULL(23)
1882 #define XHCI_MISSING_CAS BIT_ULL(24)
1883
1884 #define XHCI_BROKEN_PORT_PED BIT_ULL(25)
1885 #define XHCI_LIMIT_ENDPOINT_INTERVAL_7 BIT_ULL(26)
1886 #define XHCI_U2_DISABLE_WAKE BIT_ULL(27)
1887 #define XHCI_ASMEDIA_MODIFY_FLOWCONTROL BIT_ULL(28)
1888 #define XHCI_HW_LPM_DISABLE BIT_ULL(29)
1889 #define XHCI_SUSPEND_DELAY BIT_ULL(30)
1890 #define XHCI_INTEL_USB_ROLE_SW BIT_ULL(31)
1891 #define XHCI_ZERO_64B_REGS BIT_ULL(32)
1892 #define XHCI_DEFAULT_PM_RUNTIME_ALLOW BIT_ULL(33)
1893 #define XHCI_RESET_PLL_ON_DISCONNECT BIT_ULL(34)
1894 #define XHCI_SNPS_BROKEN_SUSPEND BIT_ULL(35)
1895 #define XHCI_RENESAS_FW_QUIRK BIT_ULL(36)
1896 #define XHCI_SKIP_PHY_INIT BIT_ULL(37)
1897 #define XHCI_DISABLE_SPARSE BIT_ULL(38)
1898 #define XHCI_SG_TRB_CACHE_SIZE_QUIRK BIT_ULL(39)
1899 #define XHCI_NO_SOFT_RETRY BIT_ULL(40)
1900 #define XHCI_BROKEN_D3COLD BIT_ULL(41)
1901 #define XHCI_EP_CTX_BROKEN_DCS BIT_ULL(42)
1902
1903 unsigned int num_active_eps;
1904 unsigned int limit_active_eps;
1905 struct xhci_port *hw_ports;
1906 struct xhci_hub usb2_rhub;
1907 struct xhci_hub usb3_rhub;
1908
1909 unsigned hw_lpm_support:1;
1910
1911 unsigned broken_suspend:1;
1912
1913 unsigned allow_single_roothub:1;
1914
1915 u32 *ext_caps;
1916 unsigned int num_ext_caps;
1917
1918 struct xhci_port_cap *port_caps;
1919 unsigned int num_port_caps;
1920
1921 struct timer_list comp_mode_recovery_timer;
1922 u32 port_status_u0;
1923 u16 test_mode;
1924
1925 #define COMP_MODE_RCVRY_MSECS 2000
1926
1927 struct dentry *debugfs_root;
1928 struct dentry *debugfs_slots;
1929 struct list_head regset_list;
1930
1931 void *dbc;
1932
1933 unsigned long priv[] __aligned(sizeof(s64));
1934 };
1935
1936
1937 struct xhci_driver_overrides {
1938 size_t extra_priv_size;
1939 int (*reset)(struct usb_hcd *hcd);
1940 int (*start)(struct usb_hcd *hcd);
1941 int (*add_endpoint)(struct usb_hcd *hcd, struct usb_device *udev,
1942 struct usb_host_endpoint *ep);
1943 int (*drop_endpoint)(struct usb_hcd *hcd, struct usb_device *udev,
1944 struct usb_host_endpoint *ep);
1945 int (*check_bandwidth)(struct usb_hcd *, struct usb_device *);
1946 void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);
1947 };
1948
1949 #define XHCI_CFC_DELAY 10
1950
1951
1952 static inline struct xhci_hcd *hcd_to_xhci(struct usb_hcd *hcd)
1953 {
1954 struct usb_hcd *primary_hcd;
1955
1956 if (usb_hcd_is_primary_hcd(hcd))
1957 primary_hcd = hcd;
1958 else
1959 primary_hcd = hcd->primary_hcd;
1960
1961 return (struct xhci_hcd *) (primary_hcd->hcd_priv);
1962 }
1963
1964 static inline struct usb_hcd *xhci_to_hcd(struct xhci_hcd *xhci)
1965 {
1966 return xhci->main_hcd;
1967 }
1968
1969 static inline struct usb_hcd *xhci_get_usb3_hcd(struct xhci_hcd *xhci)
1970 {
1971 if (xhci->shared_hcd)
1972 return xhci->shared_hcd;
1973
1974 if (!xhci->usb2_rhub.num_ports)
1975 return xhci->main_hcd;
1976
1977 return NULL;
1978 }
1979
1980 static inline bool xhci_hcd_is_usb3(struct usb_hcd *hcd)
1981 {
1982 struct xhci_hcd *xhci = hcd_to_xhci(hcd);
1983
1984 return hcd == xhci_get_usb3_hcd(xhci);
1985 }
1986
1987 static inline bool xhci_has_one_roothub(struct xhci_hcd *xhci)
1988 {
1989 return xhci->allow_single_roothub &&
1990 (!xhci->usb2_rhub.num_ports || !xhci->usb3_rhub.num_ports);
1991 }
1992
1993 #define xhci_dbg(xhci, fmt, args...) \
1994 dev_dbg(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1995 #define xhci_err(xhci, fmt, args...) \
1996 dev_err(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1997 #define xhci_warn(xhci, fmt, args...) \
1998 dev_warn(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
1999 #define xhci_warn_ratelimited(xhci, fmt, args...) \
2000 dev_warn_ratelimited(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
2001 #define xhci_info(xhci, fmt, args...) \
2002 dev_info(xhci_to_hcd(xhci)->self.controller , fmt , ## args)
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013 static inline u64 xhci_read_64(const struct xhci_hcd *xhci,
2014 __le64 __iomem *regs)
2015 {
2016 return lo_hi_readq(regs);
2017 }
2018 static inline void xhci_write_64(struct xhci_hcd *xhci,
2019 const u64 val, __le64 __iomem *regs)
2020 {
2021 lo_hi_writeq(val, regs);
2022 }
2023
2024 static inline int xhci_link_trb_quirk(struct xhci_hcd *xhci)
2025 {
2026 return xhci->quirks & XHCI_LINK_TRB_QUIRK;
2027 }
2028
2029
2030 char *xhci_get_slot_state(struct xhci_hcd *xhci,
2031 struct xhci_container_ctx *ctx);
2032 void xhci_dbg_trace(struct xhci_hcd *xhci, void (*trace)(struct va_format *),
2033 const char *fmt, ...);
2034
2035
2036 void xhci_mem_cleanup(struct xhci_hcd *xhci);
2037 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags);
2038 void xhci_free_virt_device(struct xhci_hcd *xhci, int slot_id);
2039 int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id, struct usb_device *udev, gfp_t flags);
2040 int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *udev);
2041 void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci,
2042 struct usb_device *udev);
2043 unsigned int xhci_get_endpoint_index(struct usb_endpoint_descriptor *desc);
2044 unsigned int xhci_get_endpoint_address(unsigned int ep_index);
2045 unsigned int xhci_last_valid_endpoint(u32 added_ctxs);
2046 void xhci_endpoint_zero(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev, struct usb_host_endpoint *ep);
2047 void xhci_update_tt_active_eps(struct xhci_hcd *xhci,
2048 struct xhci_virt_device *virt_dev,
2049 int old_active_eps);
2050 void xhci_clear_endpoint_bw_info(struct xhci_bw_info *bw_info);
2051 void xhci_update_bw_info(struct xhci_hcd *xhci,
2052 struct xhci_container_ctx *in_ctx,
2053 struct xhci_input_control_ctx *ctrl_ctx,
2054 struct xhci_virt_device *virt_dev);
2055 void xhci_endpoint_copy(struct xhci_hcd *xhci,
2056 struct xhci_container_ctx *in_ctx,
2057 struct xhci_container_ctx *out_ctx,
2058 unsigned int ep_index);
2059 void xhci_slot_copy(struct xhci_hcd *xhci,
2060 struct xhci_container_ctx *in_ctx,
2061 struct xhci_container_ctx *out_ctx);
2062 int xhci_endpoint_init(struct xhci_hcd *xhci, struct xhci_virt_device *virt_dev,
2063 struct usb_device *udev, struct usb_host_endpoint *ep,
2064 gfp_t mem_flags);
2065 struct xhci_ring *xhci_ring_alloc(struct xhci_hcd *xhci,
2066 unsigned int num_segs, unsigned int cycle_state,
2067 enum xhci_ring_type type, unsigned int max_packet, gfp_t flags);
2068 void xhci_ring_free(struct xhci_hcd *xhci, struct xhci_ring *ring);
2069 int xhci_ring_expansion(struct xhci_hcd *xhci, struct xhci_ring *ring,
2070 unsigned int num_trbs, gfp_t flags);
2071 int xhci_alloc_erst(struct xhci_hcd *xhci,
2072 struct xhci_ring *evt_ring,
2073 struct xhci_erst *erst,
2074 gfp_t flags);
2075 void xhci_initialize_ring_info(struct xhci_ring *ring,
2076 unsigned int cycle_state);
2077 void xhci_free_erst(struct xhci_hcd *xhci, struct xhci_erst *erst);
2078 void xhci_free_endpoint_ring(struct xhci_hcd *xhci,
2079 struct xhci_virt_device *virt_dev,
2080 unsigned int ep_index);
2081 struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci,
2082 unsigned int num_stream_ctxs,
2083 unsigned int num_streams,
2084 unsigned int max_packet, gfp_t flags);
2085 void xhci_free_stream_info(struct xhci_hcd *xhci,
2086 struct xhci_stream_info *stream_info);
2087 void xhci_setup_streams_ep_input_ctx(struct xhci_hcd *xhci,
2088 struct xhci_ep_ctx *ep_ctx,
2089 struct xhci_stream_info *stream_info);
2090 void xhci_setup_no_streams_ep_input_ctx(struct xhci_ep_ctx *ep_ctx,
2091 struct xhci_virt_ep *ep);
2092 void xhci_free_device_endpoint_resources(struct xhci_hcd *xhci,
2093 struct xhci_virt_device *virt_dev, bool drop_control_ep);
2094 struct xhci_ring *xhci_dma_to_transfer_ring(
2095 struct xhci_virt_ep *ep,
2096 u64 address);
2097 struct xhci_command *xhci_alloc_command(struct xhci_hcd *xhci,
2098 bool allocate_completion, gfp_t mem_flags);
2099 struct xhci_command *xhci_alloc_command_with_ctx(struct xhci_hcd *xhci,
2100 bool allocate_completion, gfp_t mem_flags);
2101 void xhci_urb_free_priv(struct urb_priv *urb_priv);
2102 void xhci_free_command(struct xhci_hcd *xhci,
2103 struct xhci_command *command);
2104 struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd *xhci,
2105 int type, gfp_t flags);
2106 void xhci_free_container_ctx(struct xhci_hcd *xhci,
2107 struct xhci_container_ctx *ctx);
2108
2109
2110 typedef void (*xhci_get_quirks_t)(struct device *, struct xhci_hcd *);
2111 int xhci_handshake(void __iomem *ptr, u32 mask, u32 done, u64 timeout_us);
2112 void xhci_quiesce(struct xhci_hcd *xhci);
2113 int xhci_halt(struct xhci_hcd *xhci);
2114 int xhci_start(struct xhci_hcd *xhci);
2115 int xhci_reset(struct xhci_hcd *xhci, u64 timeout_us);
2116 int xhci_run(struct usb_hcd *hcd);
2117 int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);
2118 void xhci_shutdown(struct usb_hcd *hcd);
2119 void xhci_init_driver(struct hc_driver *drv,
2120 const struct xhci_driver_overrides *over);
2121 int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
2122 struct usb_host_endpoint *ep);
2123 int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev,
2124 struct usb_host_endpoint *ep);
2125 int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
2126 void xhci_reset_bandwidth(struct usb_hcd *hcd, struct usb_device *udev);
2127 int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id);
2128 int xhci_ext_cap_init(struct xhci_hcd *xhci);
2129
2130 int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup);
2131 int xhci_resume(struct xhci_hcd *xhci, bool hibernated);
2132
2133 irqreturn_t xhci_irq(struct usb_hcd *hcd);
2134 irqreturn_t xhci_msi_irq(int irq, void *hcd);
2135 int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev);
2136 int xhci_alloc_tt_info(struct xhci_hcd *xhci,
2137 struct xhci_virt_device *virt_dev,
2138 struct usb_device *hdev,
2139 struct usb_tt *tt, gfp_t mem_flags);
2140
2141
2142 dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, union xhci_trb *trb);
2143 struct xhci_segment *trb_in_td(struct xhci_hcd *xhci,
2144 struct xhci_segment *start_seg, union xhci_trb *start_trb,
2145 union xhci_trb *end_trb, dma_addr_t suspect_dma, bool debug);
2146 int xhci_is_vendor_info_code(struct xhci_hcd *xhci, unsigned int trb_comp_code);
2147 void xhci_ring_cmd_db(struct xhci_hcd *xhci);
2148 int xhci_queue_slot_control(struct xhci_hcd *xhci, struct xhci_command *cmd,
2149 u32 trb_type, u32 slot_id);
2150 int xhci_queue_address_device(struct xhci_hcd *xhci, struct xhci_command *cmd,
2151 dma_addr_t in_ctx_ptr, u32 slot_id, enum xhci_setup_dev);
2152 int xhci_queue_vendor_command(struct xhci_hcd *xhci, struct xhci_command *cmd,
2153 u32 field1, u32 field2, u32 field3, u32 field4);
2154 int xhci_queue_stop_endpoint(struct xhci_hcd *xhci, struct xhci_command *cmd,
2155 int slot_id, unsigned int ep_index, int suspend);
2156 int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
2157 int slot_id, unsigned int ep_index);
2158 int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
2159 int slot_id, unsigned int ep_index);
2160 int xhci_queue_intr_tx(struct xhci_hcd *xhci, gfp_t mem_flags, struct urb *urb,
2161 int slot_id, unsigned int ep_index);
2162 int xhci_queue_isoc_tx_prepare(struct xhci_hcd *xhci, gfp_t mem_flags,
2163 struct urb *urb, int slot_id, unsigned int ep_index);
2164 int xhci_queue_configure_endpoint(struct xhci_hcd *xhci,
2165 struct xhci_command *cmd, dma_addr_t in_ctx_ptr, u32 slot_id,
2166 bool command_must_succeed);
2167 int xhci_queue_evaluate_context(struct xhci_hcd *xhci, struct xhci_command *cmd,
2168 dma_addr_t in_ctx_ptr, u32 slot_id, bool command_must_succeed);
2169 int xhci_queue_reset_ep(struct xhci_hcd *xhci, struct xhci_command *cmd,
2170 int slot_id, unsigned int ep_index,
2171 enum xhci_ep_reset_type reset_type);
2172 int xhci_queue_reset_device(struct xhci_hcd *xhci, struct xhci_command *cmd,
2173 u32 slot_id);
2174 void xhci_cleanup_stalled_ring(struct xhci_hcd *xhci, unsigned int slot_id,
2175 unsigned int ep_index, unsigned int stream_id,
2176 struct xhci_td *td);
2177 void xhci_stop_endpoint_command_watchdog(struct timer_list *t);
2178 void xhci_handle_command_timeout(struct work_struct *work);
2179
2180 void xhci_ring_ep_doorbell(struct xhci_hcd *xhci, unsigned int slot_id,
2181 unsigned int ep_index, unsigned int stream_id);
2182 void xhci_ring_doorbell_for_active_rings(struct xhci_hcd *xhci,
2183 unsigned int slot_id,
2184 unsigned int ep_index);
2185 void xhci_cleanup_command_queue(struct xhci_hcd *xhci);
2186 void inc_deq(struct xhci_hcd *xhci, struct xhci_ring *ring);
2187 unsigned int count_trbs(u64 addr, u64 len);
2188
2189
2190 void xhci_set_link_state(struct xhci_hcd *xhci, struct xhci_port *port,
2191 u32 link_state);
2192 void xhci_test_and_clear_bit(struct xhci_hcd *xhci, struct xhci_port *port,
2193 u32 port_bit);
2194 int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex,
2195 char *buf, u16 wLength);
2196 int xhci_hub_status_data(struct usb_hcd *hcd, char *buf);
2197 int xhci_find_raw_port_number(struct usb_hcd *hcd, int port1);
2198 struct xhci_hub *xhci_get_rhub(struct usb_hcd *hcd);
2199
2200 void xhci_hc_died(struct xhci_hcd *xhci);
2201
2202 #ifdef CONFIG_PM
2203 int xhci_bus_suspend(struct usb_hcd *hcd);
2204 int xhci_bus_resume(struct usb_hcd *hcd);
2205 unsigned long xhci_get_resuming_ports(struct usb_hcd *hcd);
2206 #else
2207 #define xhci_bus_suspend NULL
2208 #define xhci_bus_resume NULL
2209 #define xhci_get_resuming_ports NULL
2210 #endif
2211
2212 u32 xhci_port_state_to_neutral(u32 state);
2213 int xhci_find_slot_id_by_port(struct usb_hcd *hcd, struct xhci_hcd *xhci,
2214 u16 port);
2215 void xhci_ring_device(struct xhci_hcd *xhci, int slot_id);
2216
2217
2218 struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_container_ctx *ctx);
2219 struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx);
2220 struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx, unsigned int ep_index);
2221
2222 struct xhci_ring *xhci_triad_to_transfer_ring(struct xhci_hcd *xhci,
2223 unsigned int slot_id, unsigned int ep_index,
2224 unsigned int stream_id);
2225
2226 static inline struct xhci_ring *xhci_urb_to_transfer_ring(struct xhci_hcd *xhci,
2227 struct urb *urb)
2228 {
2229 return xhci_triad_to_transfer_ring(xhci, urb->dev->slot_id,
2230 xhci_get_endpoint_index(&urb->ep->desc),
2231 urb->stream_id);
2232 }
2233
2234
2235
2236
2237
2238
2239 static inline bool xhci_urb_suitable_for_idt(struct urb *urb)
2240 {
2241 if (!usb_endpoint_xfer_isoc(&urb->ep->desc) && usb_urb_dir_out(urb) &&
2242 usb_endpoint_maxp(&urb->ep->desc) >= TRB_IDT_MAX_SIZE &&
2243 urb->transfer_buffer_length <= TRB_IDT_MAX_SIZE &&
2244 !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP) &&
2245 !urb->num_sgs)
2246 return true;
2247
2248 return false;
2249 }
2250
2251 static inline char *xhci_slot_state_string(u32 state)
2252 {
2253 switch (state) {
2254 case SLOT_STATE_ENABLED:
2255 return "enabled/disabled";
2256 case SLOT_STATE_DEFAULT:
2257 return "default";
2258 case SLOT_STATE_ADDRESSED:
2259 return "addressed";
2260 case SLOT_STATE_CONFIGURED:
2261 return "configured";
2262 default:
2263 return "reserved";
2264 }
2265 }
2266
2267 static inline const char *xhci_decode_trb(char *str, size_t size,
2268 u32 field0, u32 field1, u32 field2, u32 field3)
2269 {
2270 int type = TRB_FIELD_TO_TYPE(field3);
2271
2272 switch (type) {
2273 case TRB_LINK:
2274 snprintf(str, size,
2275 "LINK %08x%08x intr %d type '%s' flags %c:%c:%c:%c",
2276 field1, field0, GET_INTR_TARGET(field2),
2277 xhci_trb_type_string(type),
2278 field3 & TRB_IOC ? 'I' : 'i',
2279 field3 & TRB_CHAIN ? 'C' : 'c',
2280 field3 & TRB_TC ? 'T' : 't',
2281 field3 & TRB_CYCLE ? 'C' : 'c');
2282 break;
2283 case TRB_TRANSFER:
2284 case TRB_COMPLETION:
2285 case TRB_PORT_STATUS:
2286 case TRB_BANDWIDTH_EVENT:
2287 case TRB_DOORBELL:
2288 case TRB_HC_EVENT:
2289 case TRB_DEV_NOTE:
2290 case TRB_MFINDEX_WRAP:
2291 snprintf(str, size,
2292 "TRB %08x%08x status '%s' len %d slot %d ep %d type '%s' flags %c:%c",
2293 field1, field0,
2294 xhci_trb_comp_code_string(GET_COMP_CODE(field2)),
2295 EVENT_TRB_LEN(field2), TRB_TO_SLOT_ID(field3),
2296
2297 TRB_TO_EP_INDEX(field3) + 1,
2298 xhci_trb_type_string(type),
2299 field3 & EVENT_DATA ? 'E' : 'e',
2300 field3 & TRB_CYCLE ? 'C' : 'c');
2301
2302 break;
2303 case TRB_SETUP:
2304 snprintf(str, size,
2305 "bRequestType %02x bRequest %02x wValue %02x%02x wIndex %02x%02x wLength %d length %d TD size %d intr %d type '%s' flags %c:%c:%c",
2306 field0 & 0xff,
2307 (field0 & 0xff00) >> 8,
2308 (field0 & 0xff000000) >> 24,
2309 (field0 & 0xff0000) >> 16,
2310 (field1 & 0xff00) >> 8,
2311 field1 & 0xff,
2312 (field1 & 0xff000000) >> 16 |
2313 (field1 & 0xff0000) >> 16,
2314 TRB_LEN(field2), GET_TD_SIZE(field2),
2315 GET_INTR_TARGET(field2),
2316 xhci_trb_type_string(type),
2317 field3 & TRB_IDT ? 'I' : 'i',
2318 field3 & TRB_IOC ? 'I' : 'i',
2319 field3 & TRB_CYCLE ? 'C' : 'c');
2320 break;
2321 case TRB_DATA:
2322 snprintf(str, size,
2323 "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c",
2324 field1, field0, TRB_LEN(field2), GET_TD_SIZE(field2),
2325 GET_INTR_TARGET(field2),
2326 xhci_trb_type_string(type),
2327 field3 & TRB_IDT ? 'I' : 'i',
2328 field3 & TRB_IOC ? 'I' : 'i',
2329 field3 & TRB_CHAIN ? 'C' : 'c',
2330 field3 & TRB_NO_SNOOP ? 'S' : 's',
2331 field3 & TRB_ISP ? 'I' : 'i',
2332 field3 & TRB_ENT ? 'E' : 'e',
2333 field3 & TRB_CYCLE ? 'C' : 'c');
2334 break;
2335 case TRB_STATUS:
2336 snprintf(str, size,
2337 "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c",
2338 field1, field0, TRB_LEN(field2), GET_TD_SIZE(field2),
2339 GET_INTR_TARGET(field2),
2340 xhci_trb_type_string(type),
2341 field3 & TRB_IOC ? 'I' : 'i',
2342 field3 & TRB_CHAIN ? 'C' : 'c',
2343 field3 & TRB_ENT ? 'E' : 'e',
2344 field3 & TRB_CYCLE ? 'C' : 'c');
2345 break;
2346 case TRB_NORMAL:
2347 case TRB_ISOC:
2348 case TRB_EVENT_DATA:
2349 case TRB_TR_NOOP:
2350 snprintf(str, size,
2351 "Buffer %08x%08x length %d TD size %d intr %d type '%s' flags %c:%c:%c:%c:%c:%c:%c:%c",
2352 field1, field0, TRB_LEN(field2), GET_TD_SIZE(field2),
2353 GET_INTR_TARGET(field2),
2354 xhci_trb_type_string(type),
2355 field3 & TRB_BEI ? 'B' : 'b',
2356 field3 & TRB_IDT ? 'I' : 'i',
2357 field3 & TRB_IOC ? 'I' : 'i',
2358 field3 & TRB_CHAIN ? 'C' : 'c',
2359 field3 & TRB_NO_SNOOP ? 'S' : 's',
2360 field3 & TRB_ISP ? 'I' : 'i',
2361 field3 & TRB_ENT ? 'E' : 'e',
2362 field3 & TRB_CYCLE ? 'C' : 'c');
2363 break;
2364
2365 case TRB_CMD_NOOP:
2366 case TRB_ENABLE_SLOT:
2367 snprintf(str, size,
2368 "%s: flags %c",
2369 xhci_trb_type_string(type),
2370 field3 & TRB_CYCLE ? 'C' : 'c');
2371 break;
2372 case TRB_DISABLE_SLOT:
2373 case TRB_NEG_BANDWIDTH:
2374 snprintf(str, size,
2375 "%s: slot %d flags %c",
2376 xhci_trb_type_string(type),
2377 TRB_TO_SLOT_ID(field3),
2378 field3 & TRB_CYCLE ? 'C' : 'c');
2379 break;
2380 case TRB_ADDR_DEV:
2381 snprintf(str, size,
2382 "%s: ctx %08x%08x slot %d flags %c:%c",
2383 xhci_trb_type_string(type),
2384 field1, field0,
2385 TRB_TO_SLOT_ID(field3),
2386 field3 & TRB_BSR ? 'B' : 'b',
2387 field3 & TRB_CYCLE ? 'C' : 'c');
2388 break;
2389 case TRB_CONFIG_EP:
2390 snprintf(str, size,
2391 "%s: ctx %08x%08x slot %d flags %c:%c",
2392 xhci_trb_type_string(type),
2393 field1, field0,
2394 TRB_TO_SLOT_ID(field3),
2395 field3 & TRB_DC ? 'D' : 'd',
2396 field3 & TRB_CYCLE ? 'C' : 'c');
2397 break;
2398 case TRB_EVAL_CONTEXT:
2399 snprintf(str, size,
2400 "%s: ctx %08x%08x slot %d flags %c",
2401 xhci_trb_type_string(type),
2402 field1, field0,
2403 TRB_TO_SLOT_ID(field3),
2404 field3 & TRB_CYCLE ? 'C' : 'c');
2405 break;
2406 case TRB_RESET_EP:
2407 snprintf(str, size,
2408 "%s: ctx %08x%08x slot %d ep %d flags %c:%c",
2409 xhci_trb_type_string(type),
2410 field1, field0,
2411 TRB_TO_SLOT_ID(field3),
2412
2413 TRB_TO_EP_INDEX(field3) + 1,
2414 field3 & TRB_TSP ? 'T' : 't',
2415 field3 & TRB_CYCLE ? 'C' : 'c');
2416 break;
2417 case TRB_STOP_RING:
2418 snprintf(str, size,
2419 "%s: slot %d sp %d ep %d flags %c",
2420 xhci_trb_type_string(type),
2421 TRB_TO_SLOT_ID(field3),
2422 TRB_TO_SUSPEND_PORT(field3),
2423
2424 TRB_TO_EP_INDEX(field3) + 1,
2425 field3 & TRB_CYCLE ? 'C' : 'c');
2426 break;
2427 case TRB_SET_DEQ:
2428 snprintf(str, size,
2429 "%s: deq %08x%08x stream %d slot %d ep %d flags %c",
2430 xhci_trb_type_string(type),
2431 field1, field0,
2432 TRB_TO_STREAM_ID(field2),
2433 TRB_TO_SLOT_ID(field3),
2434
2435 TRB_TO_EP_INDEX(field3) + 1,
2436 field3 & TRB_CYCLE ? 'C' : 'c');
2437 break;
2438 case TRB_RESET_DEV:
2439 snprintf(str, size,
2440 "%s: slot %d flags %c",
2441 xhci_trb_type_string(type),
2442 TRB_TO_SLOT_ID(field3),
2443 field3 & TRB_CYCLE ? 'C' : 'c');
2444 break;
2445 case TRB_FORCE_EVENT:
2446 snprintf(str, size,
2447 "%s: event %08x%08x vf intr %d vf id %d flags %c",
2448 xhci_trb_type_string(type),
2449 field1, field0,
2450 TRB_TO_VF_INTR_TARGET(field2),
2451 TRB_TO_VF_ID(field3),
2452 field3 & TRB_CYCLE ? 'C' : 'c');
2453 break;
2454 case TRB_SET_LT:
2455 snprintf(str, size,
2456 "%s: belt %d flags %c",
2457 xhci_trb_type_string(type),
2458 TRB_TO_BELT(field3),
2459 field3 & TRB_CYCLE ? 'C' : 'c');
2460 break;
2461 case TRB_GET_BW:
2462 snprintf(str, size,
2463 "%s: ctx %08x%08x slot %d speed %d flags %c",
2464 xhci_trb_type_string(type),
2465 field1, field0,
2466 TRB_TO_SLOT_ID(field3),
2467 TRB_TO_DEV_SPEED(field3),
2468 field3 & TRB_CYCLE ? 'C' : 'c');
2469 break;
2470 case TRB_FORCE_HEADER:
2471 snprintf(str, size,
2472 "%s: info %08x%08x%08x pkt type %d roothub port %d flags %c",
2473 xhci_trb_type_string(type),
2474 field2, field1, field0 & 0xffffffe0,
2475 TRB_TO_PACKET_TYPE(field0),
2476 TRB_TO_ROOTHUB_PORT(field3),
2477 field3 & TRB_CYCLE ? 'C' : 'c');
2478 break;
2479 default:
2480 snprintf(str, size,
2481 "type '%s' -> raw %08x %08x %08x %08x",
2482 xhci_trb_type_string(type),
2483 field0, field1, field2, field3);
2484 }
2485
2486 return str;
2487 }
2488
2489 static inline const char *xhci_decode_ctrl_ctx(char *str,
2490 unsigned long drop, unsigned long add)
2491 {
2492 unsigned int bit;
2493 int ret = 0;
2494
2495 str[0] = '\0';
2496
2497 if (drop) {
2498 ret = sprintf(str, "Drop:");
2499 for_each_set_bit(bit, &drop, 32)
2500 ret += sprintf(str + ret, " %d%s",
2501 bit / 2,
2502 bit % 2 ? "in":"out");
2503 ret += sprintf(str + ret, ", ");
2504 }
2505
2506 if (add) {
2507 ret += sprintf(str + ret, "Add:%s%s",
2508 (add & SLOT_FLAG) ? " slot":"",
2509 (add & EP0_FLAG) ? " ep0":"");
2510 add &= ~(SLOT_FLAG | EP0_FLAG);
2511 for_each_set_bit(bit, &add, 32)
2512 ret += sprintf(str + ret, " %d%s",
2513 bit / 2,
2514 bit % 2 ? "in":"out");
2515 }
2516 return str;
2517 }
2518
2519 static inline const char *xhci_decode_slot_context(char *str,
2520 u32 info, u32 info2, u32 tt_info, u32 state)
2521 {
2522 u32 speed;
2523 u32 hub;
2524 u32 mtt;
2525 int ret = 0;
2526
2527 speed = info & DEV_SPEED;
2528 hub = info & DEV_HUB;
2529 mtt = info & DEV_MTT;
2530
2531 ret = sprintf(str, "RS %05x %s%s%s Ctx Entries %d MEL %d us Port# %d/%d",
2532 info & ROUTE_STRING_MASK,
2533 ({ char *s;
2534 switch (speed) {
2535 case SLOT_SPEED_FS:
2536 s = "full-speed";
2537 break;
2538 case SLOT_SPEED_LS:
2539 s = "low-speed";
2540 break;
2541 case SLOT_SPEED_HS:
2542 s = "high-speed";
2543 break;
2544 case SLOT_SPEED_SS:
2545 s = "super-speed";
2546 break;
2547 case SLOT_SPEED_SSP:
2548 s = "super-speed plus";
2549 break;
2550 default:
2551 s = "UNKNOWN speed";
2552 } s; }),
2553 mtt ? " multi-TT" : "",
2554 hub ? " Hub" : "",
2555 (info & LAST_CTX_MASK) >> 27,
2556 info2 & MAX_EXIT,
2557 DEVINFO_TO_ROOT_HUB_PORT(info2),
2558 DEVINFO_TO_MAX_PORTS(info2));
2559
2560 ret += sprintf(str + ret, " [TT Slot %d Port# %d TTT %d Intr %d] Addr %d State %s",
2561 tt_info & TT_SLOT, (tt_info & TT_PORT) >> 8,
2562 GET_TT_THINK_TIME(tt_info), GET_INTR_TARGET(tt_info),
2563 state & DEV_ADDR_MASK,
2564 xhci_slot_state_string(GET_SLOT_STATE(state)));
2565
2566 return str;
2567 }
2568
2569
2570 static inline const char *xhci_portsc_link_state_string(u32 portsc)
2571 {
2572 switch (portsc & PORT_PLS_MASK) {
2573 case XDEV_U0:
2574 return "U0";
2575 case XDEV_U1:
2576 return "U1";
2577 case XDEV_U2:
2578 return "U2";
2579 case XDEV_U3:
2580 return "U3";
2581 case XDEV_DISABLED:
2582 return "Disabled";
2583 case XDEV_RXDETECT:
2584 return "RxDetect";
2585 case XDEV_INACTIVE:
2586 return "Inactive";
2587 case XDEV_POLLING:
2588 return "Polling";
2589 case XDEV_RECOVERY:
2590 return "Recovery";
2591 case XDEV_HOT_RESET:
2592 return "Hot Reset";
2593 case XDEV_COMP_MODE:
2594 return "Compliance mode";
2595 case XDEV_TEST_MODE:
2596 return "Test mode";
2597 case XDEV_RESUME:
2598 return "Resume";
2599 default:
2600 break;
2601 }
2602 return "Unknown";
2603 }
2604
2605 static inline const char *xhci_decode_portsc(char *str, u32 portsc)
2606 {
2607 int ret;
2608
2609 ret = sprintf(str, "%s %s %s Link:%s PortSpeed:%d ",
2610 portsc & PORT_POWER ? "Powered" : "Powered-off",
2611 portsc & PORT_CONNECT ? "Connected" : "Not-connected",
2612 portsc & PORT_PE ? "Enabled" : "Disabled",
2613 xhci_portsc_link_state_string(portsc),
2614 DEV_PORT_SPEED(portsc));
2615
2616 if (portsc & PORT_OC)
2617 ret += sprintf(str + ret, "OverCurrent ");
2618 if (portsc & PORT_RESET)
2619 ret += sprintf(str + ret, "In-Reset ");
2620
2621 ret += sprintf(str + ret, "Change: ");
2622 if (portsc & PORT_CSC)
2623 ret += sprintf(str + ret, "CSC ");
2624 if (portsc & PORT_PEC)
2625 ret += sprintf(str + ret, "PEC ");
2626 if (portsc & PORT_WRC)
2627 ret += sprintf(str + ret, "WRC ");
2628 if (portsc & PORT_OCC)
2629 ret += sprintf(str + ret, "OCC ");
2630 if (portsc & PORT_RC)
2631 ret += sprintf(str + ret, "PRC ");
2632 if (portsc & PORT_PLC)
2633 ret += sprintf(str + ret, "PLC ");
2634 if (portsc & PORT_CEC)
2635 ret += sprintf(str + ret, "CEC ");
2636 if (portsc & PORT_CAS)
2637 ret += sprintf(str + ret, "CAS ");
2638
2639 ret += sprintf(str + ret, "Wake: ");
2640 if (portsc & PORT_WKCONN_E)
2641 ret += sprintf(str + ret, "WCE ");
2642 if (portsc & PORT_WKDISC_E)
2643 ret += sprintf(str + ret, "WDE ");
2644 if (portsc & PORT_WKOC_E)
2645 ret += sprintf(str + ret, "WOE ");
2646
2647 return str;
2648 }
2649
2650 static inline const char *xhci_decode_usbsts(char *str, u32 usbsts)
2651 {
2652 int ret = 0;
2653
2654 ret = sprintf(str, " 0x%08x", usbsts);
2655
2656 if (usbsts == ~(u32)0)
2657 return str;
2658
2659 if (usbsts & STS_HALT)
2660 ret += sprintf(str + ret, " HCHalted");
2661 if (usbsts & STS_FATAL)
2662 ret += sprintf(str + ret, " HSE");
2663 if (usbsts & STS_EINT)
2664 ret += sprintf(str + ret, " EINT");
2665 if (usbsts & STS_PORT)
2666 ret += sprintf(str + ret, " PCD");
2667 if (usbsts & STS_SAVE)
2668 ret += sprintf(str + ret, " SSS");
2669 if (usbsts & STS_RESTORE)
2670 ret += sprintf(str + ret, " RSS");
2671 if (usbsts & STS_SRE)
2672 ret += sprintf(str + ret, " SRE");
2673 if (usbsts & STS_CNR)
2674 ret += sprintf(str + ret, " CNR");
2675 if (usbsts & STS_HCE)
2676 ret += sprintf(str + ret, " HCE");
2677
2678 return str;
2679 }
2680
2681 static inline const char *xhci_decode_doorbell(char *str, u32 slot, u32 doorbell)
2682 {
2683 u8 ep;
2684 u16 stream;
2685 int ret;
2686
2687 ep = (doorbell & 0xff);
2688 stream = doorbell >> 16;
2689
2690 if (slot == 0) {
2691 sprintf(str, "Command Ring %d", doorbell);
2692 return str;
2693 }
2694 ret = sprintf(str, "Slot %d ", slot);
2695 if (ep > 0 && ep < 32)
2696 ret = sprintf(str + ret, "ep%d%s",
2697 ep / 2,
2698 ep % 2 ? "in" : "out");
2699 else if (ep == 0 || ep < 248)
2700 ret = sprintf(str + ret, "Reserved %d", ep);
2701 else
2702 ret = sprintf(str + ret, "Vendor Defined %d", ep);
2703 if (stream)
2704 ret = sprintf(str + ret, " Stream %d", stream);
2705
2706 return str;
2707 }
2708
2709 static inline const char *xhci_ep_state_string(u8 state)
2710 {
2711 switch (state) {
2712 case EP_STATE_DISABLED:
2713 return "disabled";
2714 case EP_STATE_RUNNING:
2715 return "running";
2716 case EP_STATE_HALTED:
2717 return "halted";
2718 case EP_STATE_STOPPED:
2719 return "stopped";
2720 case EP_STATE_ERROR:
2721 return "error";
2722 default:
2723 return "INVALID";
2724 }
2725 }
2726
2727 static inline const char *xhci_ep_type_string(u8 type)
2728 {
2729 switch (type) {
2730 case ISOC_OUT_EP:
2731 return "Isoc OUT";
2732 case BULK_OUT_EP:
2733 return "Bulk OUT";
2734 case INT_OUT_EP:
2735 return "Int OUT";
2736 case CTRL_EP:
2737 return "Ctrl";
2738 case ISOC_IN_EP:
2739 return "Isoc IN";
2740 case BULK_IN_EP:
2741 return "Bulk IN";
2742 case INT_IN_EP:
2743 return "Int IN";
2744 default:
2745 return "INVALID";
2746 }
2747 }
2748
2749 static inline const char *xhci_decode_ep_context(char *str, u32 info,
2750 u32 info2, u64 deq, u32 tx_info)
2751 {
2752 int ret;
2753
2754 u32 esit;
2755 u16 maxp;
2756 u16 avg;
2757
2758 u8 max_pstr;
2759 u8 ep_state;
2760 u8 interval;
2761 u8 ep_type;
2762 u8 burst;
2763 u8 cerr;
2764 u8 mult;
2765
2766 bool lsa;
2767 bool hid;
2768
2769 esit = CTX_TO_MAX_ESIT_PAYLOAD_HI(info) << 16 |
2770 CTX_TO_MAX_ESIT_PAYLOAD(tx_info);
2771
2772 ep_state = info & EP_STATE_MASK;
2773 max_pstr = CTX_TO_EP_MAXPSTREAMS(info);
2774 interval = CTX_TO_EP_INTERVAL(info);
2775 mult = CTX_TO_EP_MULT(info) + 1;
2776 lsa = !!(info & EP_HAS_LSA);
2777
2778 cerr = (info2 & (3 << 1)) >> 1;
2779 ep_type = CTX_TO_EP_TYPE(info2);
2780 hid = !!(info2 & (1 << 7));
2781 burst = CTX_TO_MAX_BURST(info2);
2782 maxp = MAX_PACKET_DECODED(info2);
2783
2784 avg = EP_AVG_TRB_LENGTH(tx_info);
2785
2786 ret = sprintf(str, "State %s mult %d max P. Streams %d %s",
2787 xhci_ep_state_string(ep_state), mult,
2788 max_pstr, lsa ? "LSA " : "");
2789
2790 ret += sprintf(str + ret, "interval %d us max ESIT payload %d CErr %d ",
2791 (1 << interval) * 125, esit, cerr);
2792
2793 ret += sprintf(str + ret, "Type %s %sburst %d maxp %d deq %016llx ",
2794 xhci_ep_type_string(ep_type), hid ? "HID" : "",
2795 burst, maxp, deq);
2796
2797 ret += sprintf(str + ret, "avg trb len %d", avg);
2798
2799 return str;
2800 }
2801
2802 #endif