xhci-dbgcap.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 <[email protected]>
  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_ep {
  78. struct xhci_dbc *dbc;
  79. struct list_head list_pending;
  80. struct xhci_ring *ring;
  81. unsigned int direction:1;
  82. };
  83. #define DBC_QUEUE_SIZE 16
  84. #define DBC_WRITE_BUF_SIZE 8192
  85. /*
  86. * Private structure for DbC hardware state:
  87. */
  88. struct dbc_port {
  89. struct tty_port port;
  90. spinlock_t port_lock; /* port access */
  91. int minor;
  92. struct list_head read_pool;
  93. struct list_head read_queue;
  94. unsigned int n_read;
  95. struct tasklet_struct push;
  96. struct list_head write_pool;
  97. struct kfifo write_fifo;
  98. bool registered;
  99. };
  100. struct dbc_driver {
  101. int (*configure)(struct xhci_dbc *dbc);
  102. void (*disconnect)(struct xhci_dbc *dbc);
  103. };
  104. struct xhci_dbc {
  105. spinlock_t lock; /* device access */
  106. struct device *dev;
  107. struct xhci_hcd *xhci;
  108. struct dbc_regs __iomem *regs;
  109. struct xhci_ring *ring_evt;
  110. struct xhci_ring *ring_in;
  111. struct xhci_ring *ring_out;
  112. struct xhci_erst erst;
  113. struct xhci_container_ctx *ctx;
  114. struct dbc_str_descs *string;
  115. dma_addr_t string_dma;
  116. size_t string_size;
  117. enum dbc_state state;
  118. struct delayed_work event_work;
  119. unsigned resume_required:1;
  120. struct dbc_ep eps[2];
  121. const struct dbc_driver *driver;
  122. void *priv;
  123. };
  124. struct dbc_request {
  125. void *buf;
  126. unsigned int length;
  127. dma_addr_t dma;
  128. void (*complete)(struct xhci_dbc *dbc,
  129. struct dbc_request *req);
  130. struct list_head list_pool;
  131. int status;
  132. unsigned int actual;
  133. struct xhci_dbc *dbc;
  134. struct list_head list_pending;
  135. dma_addr_t trb_dma;
  136. union xhci_trb *trb;
  137. unsigned direction:1;
  138. };
  139. #define dbc_bulkout_ctx(d) \
  140. ((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE))
  141. #define dbc_bulkin_ctx(d) \
  142. ((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE * 2))
  143. #define dbc_bulkout_enq(d) \
  144. xhci_trb_virt_to_dma((d)->ring_out->enq_seg, (d)->ring_out->enqueue)
  145. #define dbc_bulkin_enq(d) \
  146. xhci_trb_virt_to_dma((d)->ring_in->enq_seg, (d)->ring_in->enqueue)
  147. #define dbc_epctx_info2(t, p, b) \
  148. cpu_to_le32(EP_TYPE(t) | MAX_PACKET(p) | MAX_BURST(b))
  149. #define dbc_ep_dma_direction(d) \
  150. ((d)->direction ? DMA_FROM_DEVICE : DMA_TO_DEVICE)
  151. #define BULK_OUT 0
  152. #define BULK_IN 1
  153. #define EPID_OUT 2
  154. #define EPID_IN 3
  155. enum evtreturn {
  156. EVT_ERR = -1,
  157. EVT_DONE,
  158. EVT_GSER,
  159. EVT_DISC,
  160. };
  161. static inline struct dbc_ep *get_in_ep(struct xhci_dbc *dbc)
  162. {
  163. return &dbc->eps[BULK_IN];
  164. }
  165. static inline struct dbc_ep *get_out_ep(struct xhci_dbc *dbc)
  166. {
  167. return &dbc->eps[BULK_OUT];
  168. }
  169. #ifdef CONFIG_USB_XHCI_DBGCAP
  170. int xhci_create_dbc_dev(struct xhci_hcd *xhci);
  171. void xhci_remove_dbc_dev(struct xhci_hcd *xhci);
  172. int xhci_dbc_init(void);
  173. void xhci_dbc_exit(void);
  174. int dbc_tty_init(void);
  175. void dbc_tty_exit(void);
  176. int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_hcd *xhci);
  177. void xhci_dbc_tty_remove(struct xhci_dbc *dbc);
  178. struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res,
  179. const struct dbc_driver *driver);
  180. void xhci_dbc_remove(struct xhci_dbc *dbc);
  181. struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc,
  182. unsigned int direction,
  183. gfp_t flags);
  184. void dbc_free_request(struct dbc_request *req);
  185. int dbc_ep_queue(struct dbc_request *req);
  186. #ifdef CONFIG_PM
  187. int xhci_dbc_suspend(struct xhci_hcd *xhci);
  188. int xhci_dbc_resume(struct xhci_hcd *xhci);
  189. #endif /* CONFIG_PM */
  190. #else
  191. static inline int xhci_create_dbc_dev(struct xhci_hcd *xhci)
  192. {
  193. return 0;
  194. }
  195. static inline void xhci_remove_dbc_dev(struct xhci_hcd *xhci)
  196. {
  197. }
  198. static inline int xhci_dbc_init(void)
  199. {
  200. return 0;
  201. }
  202. static inline void xhci_dbc_exit(void)
  203. {
  204. }
  205. static inline int xhci_dbc_suspend(struct xhci_hcd *xhci)
  206. {
  207. return 0;
  208. }
  209. static inline int xhci_dbc_resume(struct xhci_hcd *xhci)
  210. {
  211. return 0;
  212. }
  213. #endif /* CONFIG_USB_XHCI_DBGCAP */
  214. #endif /* __LINUX_XHCI_DBGCAP_H */