xhci-ext-caps.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * xHCI host controller driver
  4. *
  5. * Copyright (C) 2008 Intel Corp.
  6. *
  7. * Author: Sarah Sharp
  8. * Some code borrowed from the Linux EHCI driver.
  9. */
  10. /* HC should halt within 16 ms, but use 32 ms as some hosts take longer */
  11. #define XHCI_MAX_HALT_USEC (32 * 1000)
  12. /* HC not running - set to 1 when run/stop bit is cleared. */
  13. #define XHCI_STS_HALT (1<<0)
  14. /* HCCPARAMS offset from PCI base address */
  15. #define XHCI_HCC_PARAMS_OFFSET 0x10
  16. /* HCCPARAMS contains the first extended capability pointer */
  17. #define XHCI_HCC_EXT_CAPS(p) (((p)>>16)&0xffff)
  18. /* Command and Status registers offset from the Operational Registers address */
  19. #define XHCI_CMD_OFFSET 0x00
  20. #define XHCI_STS_OFFSET 0x04
  21. #define XHCI_MAX_EXT_CAPS 50
  22. /* Capability Register */
  23. /* bits 7:0 - how long is the Capabilities register */
  24. #define XHCI_HC_LENGTH(p) (((p)>>00)&0x00ff)
  25. /* Extended capability register fields */
  26. #define XHCI_EXT_CAPS_ID(p) (((p)>>0)&0xff)
  27. #define XHCI_EXT_CAPS_NEXT(p) (((p)>>8)&0xff)
  28. #define XHCI_EXT_CAPS_VAL(p) ((p)>>16)
  29. /* Extended capability IDs - ID 0 reserved */
  30. #define XHCI_EXT_CAPS_LEGACY 1
  31. #define XHCI_EXT_CAPS_PROTOCOL 2
  32. #define XHCI_EXT_CAPS_PM 3
  33. #define XHCI_EXT_CAPS_VIRT 4
  34. #define XHCI_EXT_CAPS_ROUTE 5
  35. /* IDs 6-9 reserved */
  36. #define XHCI_EXT_CAPS_DEBUG 10
  37. /* Vendor caps */
  38. #define XHCI_EXT_CAPS_VENDOR_INTEL 192
  39. #define XHCI_EXT_CAPS_INTEL_SPR_SHADOW 206
  40. /* USB Legacy Support Capability - section 7.1.1 */
  41. #define XHCI_HC_BIOS_OWNED (1 << 16)
  42. #define XHCI_HC_OS_OWNED (1 << 24)
  43. /* USB Legacy Support Capability - section 7.1.1 */
  44. /* Add this offset, plus the value of xECP in HCCPARAMS to the base address */
  45. #define XHCI_LEGACY_SUPPORT_OFFSET (0x00)
  46. /* USB Legacy Support Control and Status Register - section 7.1.2 */
  47. /* Add this offset, plus the value of xECP in HCCPARAMS to the base address */
  48. #define XHCI_LEGACY_CONTROL_OFFSET (0x04)
  49. /* bits 1:3, 5:12, and 17:19 need to be preserved; bits 21:28 should be zero */
  50. #define XHCI_LEGACY_DISABLE_SMI ((0x7 << 1) + (0xff << 5) + (0x7 << 17))
  51. #define XHCI_LEGACY_SMI_EVENTS (0x7 << 29)
  52. /* USB 2.0 xHCI 0.96 L1C capability - section 7.2.2.1.3.2 */
  53. #define XHCI_L1C (1 << 16)
  54. /* USB 2.0 xHCI 1.0 hardware LMP capability - section 7.2.2.1.3.2 */
  55. #define XHCI_HLC (1 << 19)
  56. #define XHCI_BLC (1 << 20)
  57. /* Intel SPR shadow capability */
  58. #define XHCI_INTEL_SPR_ESS_PORT_OFFSET 0x8ac4 /* SuperSpeed port control */
  59. #define XHCI_INTEL_SPR_TUNEN BIT(4) /* Tunnel mode enabled */
  60. /* command register values to disable interrupts and halt the HC */
  61. /* start/stop HC execution - do not write unless HC is halted*/
  62. #define XHCI_CMD_RUN (1 << 0)
  63. /* Event Interrupt Enable - get irq when EINT bit is set in USBSTS register */
  64. #define XHCI_CMD_EIE (1 << 2)
  65. /* Host System Error Interrupt Enable - get irq when HSEIE bit set in USBSTS */
  66. #define XHCI_CMD_HSEIE (1 << 3)
  67. /* Enable Wrap Event - '1' means xHC generates an event when MFINDEX wraps. */
  68. #define XHCI_CMD_EWE (1 << 10)
  69. #define XHCI_IRQS (XHCI_CMD_EIE | XHCI_CMD_HSEIE | XHCI_CMD_EWE)
  70. /* true: Controller Not Ready to accept doorbell or op reg writes after reset */
  71. #define XHCI_STS_CNR (1 << 11)
  72. /**
  73. * struct xhci_protocol_caps
  74. * @revision: major revision, minor revision, capability ID,
  75. * and next capability pointer.
  76. * @name_string: Four ASCII characters to say which spec this xHC
  77. * follows, typically "USB ".
  78. * @port_info: Port offset, count, and protocol-defined information.
  79. */
  80. struct xhci_protocol_caps {
  81. u32 revision;
  82. u32 name_string;
  83. u32 port_info;
  84. };
  85. #define XHCI_EXT_PORT_MAJOR(x) (((x) >> 24) & 0xff)
  86. #define XHCI_EXT_PORT_MINOR(x) (((x) >> 16) & 0xff)
  87. #define XHCI_EXT_PORT_PSIC(x) (((x) >> 28) & 0x0f)
  88. #define XHCI_EXT_PORT_OFF(x) ((x) & 0xff)
  89. #define XHCI_EXT_PORT_COUNT(x) (((x) >> 8) & 0xff)
  90. #define XHCI_EXT_PORT_PSIV(x) (((x) >> 0) & 0x0f)
  91. #define XHCI_EXT_PORT_PSIE(x) (((x) >> 4) & 0x03)
  92. #define XHCI_EXT_PORT_PLT(x) (((x) >> 6) & 0x03)
  93. #define XHCI_EXT_PORT_PFD(x) (((x) >> 8) & 0x01)
  94. #define XHCI_EXT_PORT_LP(x) (((x) >> 14) & 0x03)
  95. #define XHCI_EXT_PORT_PSIM(x) (((x) >> 16) & 0xffff)
  96. #include <linux/io.h>
  97. /**
  98. * Find the offset of the extended capabilities with capability ID id.
  99. *
  100. * @base PCI MMIO registers base address.
  101. * @start address at which to start looking, (0 or HCC_PARAMS to start at
  102. * beginning of list)
  103. * @id Extended capability ID to search for, or 0 for the next
  104. * capability
  105. *
  106. * Returns the offset of the next matching extended capability structure.
  107. * Some capabilities can occur several times, e.g., the XHCI_EXT_CAPS_PROTOCOL,
  108. * and this provides a way to find them all.
  109. */
  110. static inline int xhci_find_next_ext_cap(void __iomem *base, u32 start, int id)
  111. {
  112. u32 val;
  113. u32 next;
  114. u32 offset;
  115. offset = start;
  116. if (!start || start == XHCI_HCC_PARAMS_OFFSET) {
  117. val = readl(base + XHCI_HCC_PARAMS_OFFSET);
  118. if (val == ~0)
  119. return 0;
  120. offset = XHCI_HCC_EXT_CAPS(val) << 2;
  121. if (!offset)
  122. return 0;
  123. }
  124. do {
  125. val = readl(base + offset);
  126. if (val == ~0)
  127. return 0;
  128. if (offset != start && (id == 0 || XHCI_EXT_CAPS_ID(val) == id))
  129. return offset;
  130. next = XHCI_EXT_CAPS_NEXT(val);
  131. offset += next << 2;
  132. } while (next);
  133. return 0;
  134. }