xhci-dbgcap.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /**
  3. * xhci-dbgcap.h - xHCI debug capability support
  4. *
  5. * Copyright (C) 2017 Intel Corporation
  6. *
  7. * Author: Lu Baolu <baolu.lu@linux.intel.com>
  8. */
  9. #ifndef __LINUX_XHCI_DBGCAP_H
  10. #define __LINUX_XHCI_DBGCAP_H
  11. #include <linux/tty.h>
  12. #include <linux/kfifo.h>
  13. struct dbc_regs {
  14. __le32 capability;
  15. __le32 doorbell;
  16. __le32 ersts; /* Event Ring Segment Table Size*/
  17. __le32 __reserved_0; /* 0c~0f reserved bits */
  18. __le64 erstba; /* Event Ring Segment Table Base Address */
  19. __le64 erdp; /* Event Ring Dequeue Pointer */
  20. __le32 control;
  21. __le32 status;
  22. __le32 portsc; /* Port status and control */
  23. __le32 __reserved_1; /* 2b~28 reserved bits */
  24. __le64 dccp; /* Debug Capability Context Pointer */
  25. __le32 devinfo1; /* Device Descriptor Info Register 1 */
  26. __le32 devinfo2; /* Device Descriptor Info Register 2 */
  27. };
  28. struct dbc_info_context {
  29. __le64 string0;
  30. __le64 manufacturer;
  31. __le64 product;
  32. __le64 serial;
  33. __le32 length;
  34. __le32 __reserved_0[7];
  35. };
  36. #define DBC_CTRL_DBC_RUN BIT(0)
  37. #define DBC_CTRL_PORT_ENABLE BIT(1)
  38. #define DBC_CTRL_HALT_OUT_TR BIT(2)
  39. #define DBC_CTRL_HALT_IN_TR BIT(3)
  40. #define DBC_CTRL_DBC_RUN_CHANGE BIT(4)
  41. #define DBC_CTRL_DBC_ENABLE BIT(31)
  42. #define DBC_CTRL_MAXBURST(p) (((p) >> 16) & 0xff)
  43. #define DBC_DOOR_BELL_TARGET(p) (((p) & 0xff) << 8)
  44. #define DBC_MAX_PACKET 1024
  45. #define DBC_MAX_STRING_LENGTH 64
  46. #define DBC_STRING_MANUFACTURER "Linux Foundation"
  47. #define DBC_STRING_PRODUCT "Linux USB Debug Target"
  48. #define DBC_STRING_SERIAL "0001"
  49. #define DBC_CONTEXT_SIZE 64
  50. /*
  51. * Port status:
  52. */
  53. #define DBC_PORTSC_CONN_STATUS BIT(0)
  54. #define DBC_PORTSC_PORT_ENABLED BIT(1)
  55. #define DBC_PORTSC_CONN_CHANGE BIT(17)
  56. #define DBC_PORTSC_RESET_CHANGE BIT(21)
  57. #define DBC_PORTSC_LINK_CHANGE BIT(22)
  58. #define DBC_PORTSC_CONFIG_CHANGE BIT(23)
  59. struct dbc_str_descs {
  60. char string0[DBC_MAX_STRING_LENGTH];
  61. char manufacturer[DBC_MAX_STRING_LENGTH];
  62. char product[DBC_MAX_STRING_LENGTH];
  63. char serial[DBC_MAX_STRING_LENGTH];
  64. };
  65. #define DBC_PROTOCOL 1 /* GNU Remote Debug Command */
  66. #define DBC_VENDOR_ID 0x1d6b /* Linux Foundation 0x1d6b */
  67. #define DBC_PRODUCT_ID 0x0010 /* device 0010 */
  68. #define DBC_DEVICE_REV 0x0010 /* 0.10 */
  69. enum dbc_state {
  70. DS_DISABLED = 0,
  71. DS_INITIALIZED,
  72. DS_ENABLED,
  73. DS_CONNECTED,
  74. DS_CONFIGURED,
  75. DS_STALLED,
  76. };
  77. struct dbc_request {
  78. void *buf;
  79. unsigned int length;
  80. dma_addr_t dma;
  81. void (*complete)(struct xhci_hcd *xhci,
  82. struct dbc_request *req);
  83. struct list_head list_pool;
  84. int status;
  85. unsigned int actual;
  86. struct dbc_ep *dep;
  87. struct list_head list_pending;
  88. dma_addr_t trb_dma;
  89. union xhci_trb *trb;
  90. unsigned direction:1;
  91. };
  92. struct dbc_ep {
  93. struct xhci_dbc *dbc;
  94. struct list_head list_pending;
  95. struct xhci_ring *ring;
  96. unsigned direction:1;
  97. };
  98. #define DBC_QUEUE_SIZE 16
  99. #define DBC_WRITE_BUF_SIZE 8192
  100. /*
  101. * Private structure for DbC hardware state:
  102. */
  103. struct dbc_port {
  104. struct tty_port port;
  105. spinlock_t port_lock; /* port access */
  106. struct list_head read_pool;
  107. struct list_head read_queue;
  108. unsigned int n_read;
  109. struct tasklet_struct push;
  110. struct list_head write_pool;
  111. struct kfifo write_fifo;
  112. bool registered;
  113. struct dbc_ep *in;
  114. struct dbc_ep *out;
  115. };
  116. struct xhci_dbc {
  117. spinlock_t lock; /* device access */
  118. struct xhci_hcd *xhci;
  119. struct dbc_regs __iomem *regs;
  120. struct xhci_ring *ring_evt;
  121. struct xhci_ring *ring_in;
  122. struct xhci_ring *ring_out;
  123. struct xhci_erst erst;
  124. struct xhci_container_ctx *ctx;
  125. struct dbc_str_descs *string;
  126. dma_addr_t string_dma;
  127. size_t string_size;
  128. enum dbc_state state;
  129. struct delayed_work event_work;
  130. unsigned resume_required:1;
  131. struct dbc_ep eps[2];
  132. struct dbc_port port;
  133. };
  134. #define dbc_bulkout_ctx(d) \
  135. ((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE))
  136. #define dbc_bulkin_ctx(d) \
  137. ((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE * 2))
  138. #define dbc_bulkout_enq(d) \
  139. xhci_trb_virt_to_dma((d)->ring_out->enq_seg, (d)->ring_out->enqueue)
  140. #define dbc_bulkin_enq(d) \
  141. xhci_trb_virt_to_dma((d)->ring_in->enq_seg, (d)->ring_in->enqueue)
  142. #define dbc_epctx_info2(t, p, b) \
  143. cpu_to_le32(EP_TYPE(t) | MAX_PACKET(p) | MAX_BURST(b))
  144. #define dbc_ep_dma_direction(d) \
  145. ((d)->direction ? DMA_FROM_DEVICE : DMA_TO_DEVICE)
  146. #define BULK_OUT 0
  147. #define BULK_IN 1
  148. #define EPID_OUT 2
  149. #define EPID_IN 3
  150. enum evtreturn {
  151. EVT_ERR = -1,
  152. EVT_DONE,
  153. EVT_GSER,
  154. EVT_DISC,
  155. };
  156. static inline struct dbc_ep *get_in_ep(struct xhci_hcd *xhci)
  157. {
  158. struct xhci_dbc *dbc = xhci->dbc;
  159. return &dbc->eps[BULK_IN];
  160. }
  161. static inline struct dbc_ep *get_out_ep(struct xhci_hcd *xhci)
  162. {
  163. struct xhci_dbc *dbc = xhci->dbc;
  164. return &dbc->eps[BULK_OUT];
  165. }
  166. #ifdef CONFIG_USB_XHCI_DBGCAP
  167. int xhci_dbc_init(struct xhci_hcd *xhci);
  168. void xhci_dbc_exit(struct xhci_hcd *xhci);
  169. int xhci_dbc_tty_register_driver(struct xhci_hcd *xhci);
  170. void xhci_dbc_tty_unregister_driver(void);
  171. int xhci_dbc_tty_register_device(struct xhci_hcd *xhci);
  172. void xhci_dbc_tty_unregister_device(struct xhci_hcd *xhci);
  173. struct dbc_request *dbc_alloc_request(struct dbc_ep *dep, gfp_t gfp_flags);
  174. void dbc_free_request(struct dbc_ep *dep, struct dbc_request *req);
  175. int dbc_ep_queue(struct dbc_ep *dep, struct dbc_request *req, gfp_t gfp_flags);
  176. #ifdef CONFIG_PM
  177. int xhci_dbc_suspend(struct xhci_hcd *xhci);
  178. int xhci_dbc_resume(struct xhci_hcd *xhci);
  179. #endif /* CONFIG_PM */
  180. #else
  181. static inline int xhci_dbc_init(struct xhci_hcd *xhci)
  182. {
  183. return 0;
  184. }
  185. static inline void xhci_dbc_exit(struct xhci_hcd *xhci)
  186. {
  187. }
  188. static inline int xhci_dbc_suspend(struct xhci_hcd *xhci)
  189. {
  190. return 0;
  191. }
  192. static inline int xhci_dbc_resume(struct xhci_hcd *xhci)
  193. {
  194. return 0;
  195. }
  196. #endif /* CONFIG_USB_XHCI_DBGCAP */
  197. #endif /* __LINUX_XHCI_DBGCAP_H */