xhci-dbc.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * xhci-dbc.h - xHCI debug capability early driver
  4. *
  5. * Copyright (C) 2016 Intel Corporation
  6. *
  7. * Author: Lu Baolu <baolu.lu@linux.intel.com>
  8. */
  9. #ifndef __LINUX_XHCI_DBC_H
  10. #define __LINUX_XHCI_DBC_H
  11. #include <linux/types.h>
  12. #include <linux/usb/ch9.h>
  13. /*
  14. * xHCI Debug Capability Register interfaces:
  15. */
  16. struct xdbc_regs {
  17. __le32 capability;
  18. __le32 doorbell;
  19. __le32 ersts; /* Event Ring Segment Table Size*/
  20. __le32 __reserved_0; /* 0c~0f reserved bits */
  21. __le64 erstba; /* Event Ring Segment Table Base Address */
  22. __le64 erdp; /* Event Ring Dequeue Pointer */
  23. __le32 control;
  24. __le32 status;
  25. __le32 portsc; /* Port status and control */
  26. __le32 __reserved_1; /* 2b~28 reserved bits */
  27. __le64 dccp; /* Debug Capability Context Pointer */
  28. __le32 devinfo1; /* Device Descriptor Info Register 1 */
  29. __le32 devinfo2; /* Device Descriptor Info Register 2 */
  30. };
  31. #define DEBUG_MAX_BURST(p) (((p) >> 16) & 0xff)
  32. #define CTRL_DBC_RUN BIT(0)
  33. #define CTRL_PORT_ENABLE BIT(1)
  34. #define CTRL_HALT_OUT_TR BIT(2)
  35. #define CTRL_HALT_IN_TR BIT(3)
  36. #define CTRL_DBC_RUN_CHANGE BIT(4)
  37. #define CTRL_DBC_ENABLE BIT(31)
  38. #define DCST_DEBUG_PORT(p) (((p) >> 24) & 0xff)
  39. #define PORTSC_CONN_STATUS BIT(0)
  40. #define PORTSC_CONN_CHANGE BIT(17)
  41. #define PORTSC_RESET_CHANGE BIT(21)
  42. #define PORTSC_LINK_CHANGE BIT(22)
  43. #define PORTSC_CONFIG_CHANGE BIT(23)
  44. /*
  45. * xHCI Debug Capability data structures:
  46. */
  47. struct xdbc_trb {
  48. __le32 field[4];
  49. };
  50. struct xdbc_erst_entry {
  51. __le64 seg_addr;
  52. __le32 seg_size;
  53. __le32 __reserved_0;
  54. };
  55. struct xdbc_info_context {
  56. __le64 string0;
  57. __le64 manufacturer;
  58. __le64 product;
  59. __le64 serial;
  60. __le32 length;
  61. __le32 __reserved_0[7];
  62. };
  63. struct xdbc_ep_context {
  64. __le32 ep_info1;
  65. __le32 ep_info2;
  66. __le64 deq;
  67. __le32 tx_info;
  68. __le32 __reserved_0[11];
  69. };
  70. struct xdbc_context {
  71. struct xdbc_info_context info;
  72. struct xdbc_ep_context out;
  73. struct xdbc_ep_context in;
  74. };
  75. #define XDBC_INFO_CONTEXT_SIZE 48
  76. #define XDBC_MAX_STRING_LENGTH 64
  77. #define XDBC_STRING_MANUFACTURER "Linux Foundation"
  78. #define XDBC_STRING_PRODUCT "Linux USB GDB Target"
  79. #define XDBC_STRING_SERIAL "0001"
  80. struct xdbc_strings {
  81. char string0[XDBC_MAX_STRING_LENGTH];
  82. char manufacturer[XDBC_MAX_STRING_LENGTH];
  83. char product[XDBC_MAX_STRING_LENGTH];
  84. char serial[XDBC_MAX_STRING_LENGTH];
  85. };
  86. #define XDBC_PROTOCOL 1 /* GNU Remote Debug Command Set */
  87. #define XDBC_VENDOR_ID 0x1d6b /* Linux Foundation 0x1d6b */
  88. #define XDBC_PRODUCT_ID 0x0011 /* __le16 idProduct; device 0011 */
  89. #define XDBC_DEVICE_REV 0x0010 /* 0.10 */
  90. /*
  91. * xHCI Debug Capability software state structures:
  92. */
  93. struct xdbc_segment {
  94. struct xdbc_trb *trbs;
  95. dma_addr_t dma;
  96. };
  97. #define XDBC_TRBS_PER_SEGMENT 256
  98. struct xdbc_ring {
  99. struct xdbc_segment *segment;
  100. struct xdbc_trb *enqueue;
  101. struct xdbc_trb *dequeue;
  102. u32 cycle_state;
  103. };
  104. #define XDBC_EPID_OUT 2
  105. #define XDBC_EPID_IN 3
  106. struct xdbc_state {
  107. u16 vendor;
  108. u16 device;
  109. u32 bus;
  110. u32 dev;
  111. u32 func;
  112. void __iomem *xhci_base;
  113. u64 xhci_start;
  114. size_t xhci_length;
  115. int port_number;
  116. /* DbC register base */
  117. struct xdbc_regs __iomem *xdbc_reg;
  118. /* DbC table page */
  119. dma_addr_t table_dma;
  120. void *table_base;
  121. /* event ring segment table */
  122. dma_addr_t erst_dma;
  123. size_t erst_size;
  124. void *erst_base;
  125. /* event ring segments */
  126. struct xdbc_ring evt_ring;
  127. struct xdbc_segment evt_seg;
  128. /* debug capability contexts */
  129. dma_addr_t dbcc_dma;
  130. size_t dbcc_size;
  131. void *dbcc_base;
  132. /* descriptor strings */
  133. dma_addr_t string_dma;
  134. size_t string_size;
  135. void *string_base;
  136. /* bulk OUT endpoint */
  137. struct xdbc_ring out_ring;
  138. struct xdbc_segment out_seg;
  139. void *out_buf;
  140. dma_addr_t out_dma;
  141. /* bulk IN endpoint */
  142. struct xdbc_ring in_ring;
  143. struct xdbc_segment in_seg;
  144. void *in_buf;
  145. dma_addr_t in_dma;
  146. u32 flags;
  147. /* spinlock for early_xdbc_write() reentrancy */
  148. raw_spinlock_t lock;
  149. };
  150. #define XDBC_PCI_MAX_BUSES 256
  151. #define XDBC_PCI_MAX_DEVICES 32
  152. #define XDBC_PCI_MAX_FUNCTION 8
  153. #define XDBC_TABLE_ENTRY_SIZE 64
  154. #define XDBC_ERST_ENTRY_NUM 1
  155. #define XDBC_DBCC_ENTRY_NUM 3
  156. #define XDBC_STRING_ENTRY_NUM 4
  157. /* Bits definitions for xdbc_state.flags: */
  158. #define XDBC_FLAGS_INITIALIZED BIT(0)
  159. #define XDBC_FLAGS_IN_STALL BIT(1)
  160. #define XDBC_FLAGS_OUT_STALL BIT(2)
  161. #define XDBC_FLAGS_IN_PROCESS BIT(3)
  162. #define XDBC_FLAGS_OUT_PROCESS BIT(4)
  163. #define XDBC_FLAGS_CONFIGURED BIT(5)
  164. #define XDBC_MAX_PACKET 1024
  165. /* Door bell target: */
  166. #define OUT_EP_DOORBELL 0
  167. #define IN_EP_DOORBELL 1
  168. #define DOOR_BELL_TARGET(p) (((p) & 0xff) << 8)
  169. #define xdbc_read64(regs) xhci_read_64(NULL, (regs))
  170. #define xdbc_write64(val, regs) xhci_write_64(NULL, (val), (regs))
  171. #endif /* __LINUX_XHCI_DBC_H */