xhci-dbgcap.h 5.6 KB

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