1 /* SPDX-License-Identifier: GPL-2.0 */
3 * xhci-dbgcap.h - xHCI debug capability support
5 * Copyright (C) 2017 Intel Corporation
7 * Author: Lu Baolu <baolu.lu@linux.intel.com>
9 #ifndef __LINUX_XHCI_DBGCAP_H
10 #define __LINUX_XHCI_DBGCAP_H
12 #include <linux/tty.h>
13 #include <linux/kfifo.h>
18 __le32 ersts
; /* Event Ring Segment Table Size*/
19 __le32 __reserved_0
; /* 0c~0f reserved bits */
20 __le64 erstba
; /* Event Ring Segment Table Base Address */
21 __le64 erdp
; /* Event Ring Dequeue Pointer */
24 __le32 portsc
; /* Port status and control */
25 __le32 __reserved_1
; /* 2b~28 reserved bits */
26 __le64 dccp
; /* Debug Capability Context Pointer */
27 __le32 devinfo1
; /* Device Descriptor Info Register 1 */
28 __le32 devinfo2
; /* Device Descriptor Info Register 2 */
31 struct dbc_info_context
{
37 __le32 __reserved_0
[7];
40 #define DBC_CTRL_DBC_RUN BIT(0)
41 #define DBC_CTRL_PORT_ENABLE BIT(1)
42 #define DBC_CTRL_HALT_OUT_TR BIT(2)
43 #define DBC_CTRL_HALT_IN_TR BIT(3)
44 #define DBC_CTRL_DBC_RUN_CHANGE BIT(4)
45 #define DBC_CTRL_DBC_ENABLE BIT(31)
46 #define DBC_CTRL_MAXBURST(p) (((p) >> 16) & 0xff)
47 #define DBC_DOOR_BELL_TARGET(p) (((p) & 0xff) << 8)
49 #define DBC_MAX_PACKET 1024
50 #define DBC_MAX_STRING_LENGTH 64
51 #define DBC_STRING_MANUFACTURER "Linux Foundation"
52 #define DBC_STRING_PRODUCT "Linux USB Debug Target"
53 #define DBC_STRING_SERIAL "0001"
54 #define DBC_CONTEXT_SIZE 64
59 #define DBC_PORTSC_CONN_STATUS BIT(0)
60 #define DBC_PORTSC_PORT_ENABLED BIT(1)
61 #define DBC_PORTSC_CONN_CHANGE BIT(17)
62 #define DBC_PORTSC_RESET_CHANGE BIT(21)
63 #define DBC_PORTSC_LINK_CHANGE BIT(22)
64 #define DBC_PORTSC_CONFIG_CHANGE BIT(23)
66 struct dbc_str_descs
{
67 char string0
[DBC_MAX_STRING_LENGTH
];
68 char manufacturer
[DBC_MAX_STRING_LENGTH
];
69 char product
[DBC_MAX_STRING_LENGTH
];
70 char serial
[DBC_MAX_STRING_LENGTH
];
73 #define DBC_PROTOCOL 1 /* GNU Remote Debug Command */
74 #define DBC_VENDOR_ID 0x1d6b /* Linux Foundation 0x1d6b */
75 #define DBC_PRODUCT_ID 0x0010 /* device 0010 */
76 #define DBC_DEVICE_REV 0x0010 /* 0.10 */
91 void (*complete
)(struct xhci_hcd
*xhci
,
92 struct dbc_request
*req
);
93 struct list_head list_pool
;
98 struct list_head list_pending
;
101 unsigned direction
:1;
105 struct xhci_dbc
*dbc
;
106 struct list_head list_pending
;
107 struct xhci_ring
*ring
;
108 unsigned direction
:1;
111 #define DBC_QUEUE_SIZE 16
112 #define DBC_WRITE_BUF_SIZE 8192
115 * Private structure for DbC hardware state:
118 struct tty_port port
;
119 spinlock_t port_lock
; /* port access */
121 struct list_head read_pool
;
122 struct list_head read_queue
;
124 struct tasklet_struct push
;
126 struct list_head write_pool
;
127 struct kfifo write_fifo
;
135 spinlock_t lock
; /* device access */
136 struct xhci_hcd
*xhci
;
137 struct dbc_regs __iomem
*regs
;
138 struct xhci_ring
*ring_evt
;
139 struct xhci_ring
*ring_in
;
140 struct xhci_ring
*ring_out
;
141 struct xhci_erst erst
;
142 struct xhci_container_ctx
*ctx
;
144 struct dbc_str_descs
*string
;
145 dma_addr_t string_dma
;
148 enum dbc_state state
;
149 struct delayed_work event_work
;
150 unsigned resume_required
:1;
151 struct dbc_ep eps
[2];
153 struct dbc_port port
;
156 #define dbc_bulkout_ctx(d) \
157 ((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE))
158 #define dbc_bulkin_ctx(d) \
159 ((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE * 2))
160 #define dbc_bulkout_enq(d) \
161 xhci_trb_virt_to_dma((d)->ring_out->enq_seg, (d)->ring_out->enqueue)
162 #define dbc_bulkin_enq(d) \
163 xhci_trb_virt_to_dma((d)->ring_in->enq_seg, (d)->ring_in->enqueue)
164 #define dbc_epctx_info2(t, p, b) \
165 cpu_to_le32(EP_TYPE(t) | MAX_PACKET(p) | MAX_BURST(b))
166 #define dbc_ep_dma_direction(d) \
167 ((d)->direction ? DMA_FROM_DEVICE : DMA_TO_DEVICE)
181 static inline struct dbc_ep
*get_in_ep(struct xhci_hcd
*xhci
)
183 struct xhci_dbc
*dbc
= xhci
->dbc
;
185 return &dbc
->eps
[BULK_IN
];
188 static inline struct dbc_ep
*get_out_ep(struct xhci_hcd
*xhci
)
190 struct xhci_dbc
*dbc
= xhci
->dbc
;
192 return &dbc
->eps
[BULK_OUT
];
195 #ifdef CONFIG_USB_XHCI_DBGCAP
196 int xhci_dbc_init(struct xhci_hcd
*xhci
);
197 void xhci_dbc_exit(struct xhci_hcd
*xhci
);
198 int xhci_dbc_tty_register_driver(struct xhci_hcd
*xhci
);
199 void xhci_dbc_tty_unregister_driver(void);
200 int xhci_dbc_tty_register_device(struct xhci_hcd
*xhci
);
201 void xhci_dbc_tty_unregister_device(struct xhci_hcd
*xhci
);
202 struct dbc_request
*dbc_alloc_request(struct dbc_ep
*dep
, gfp_t gfp_flags
);
203 void dbc_free_request(struct dbc_ep
*dep
, struct dbc_request
*req
);
204 int dbc_ep_queue(struct dbc_ep
*dep
, struct dbc_request
*req
, gfp_t gfp_flags
);
206 int xhci_dbc_suspend(struct xhci_hcd
*xhci
);
207 int xhci_dbc_resume(struct xhci_hcd
*xhci
);
208 #endif /* CONFIG_PM */
210 static inline int xhci_dbc_init(struct xhci_hcd
*xhci
)
215 static inline void xhci_dbc_exit(struct xhci_hcd
*xhci
)
219 static inline int xhci_dbc_suspend(struct xhci_hcd
*xhci
)
224 static inline int xhci_dbc_resume(struct xhci_hcd
*xhci
)
228 #endif /* CONFIG_USB_XHCI_DBGCAP */
229 #endif /* __LINUX_XHCI_DBGCAP_H */