xhci-dbgcap.h 6.3 KB

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