xhci-dbgcap.h 6.2 KB

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