Loading...
Note: File does not exist in v3.1.
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
12#include <linux/tty.h>
13#include <linux/kfifo.h>
14
15struct dbc_regs {
16 __le32 capability;
17 __le32 doorbell;
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 */
22 __le32 control;
23 __le32 status;
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 */
29};
30
31struct dbc_info_context {
32 __le64 string0;
33 __le64 manufacturer;
34 __le64 product;
35 __le64 serial;
36 __le32 length;
37 __le32 __reserved_0[7];
38};
39
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)
48
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
55
56/*
57 * Port status:
58 */
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)
65
66struct 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];
71};
72
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 */
77
78enum dbc_state {
79 DS_DISABLED = 0,
80 DS_INITIALIZED,
81 DS_ENABLED,
82 DS_CONNECTED,
83 DS_CONFIGURED,
84 DS_STALLED,
85 DS_MAX
86};
87
88struct dbc_ep {
89 struct xhci_dbc *dbc;
90 struct list_head list_pending;
91 struct xhci_ring *ring;
92 unsigned int direction:1;
93};
94
95#define DBC_QUEUE_SIZE 16
96#define DBC_WRITE_BUF_SIZE 8192
97
98/*
99 * Private structure for DbC hardware state:
100 */
101struct dbc_port {
102 struct tty_port port;
103 spinlock_t port_lock; /* port access */
104 int minor;
105
106 struct list_head read_pool;
107 struct list_head read_queue;
108 unsigned int n_read;
109 struct tasklet_struct push;
110
111 struct list_head write_pool;
112 struct kfifo write_fifo;
113
114 bool registered;
115};
116
117struct dbc_driver {
118 int (*configure)(struct xhci_dbc *dbc);
119 void (*disconnect)(struct xhci_dbc *dbc);
120};
121
122struct xhci_dbc {
123 spinlock_t lock; /* device access */
124 struct device *dev;
125 struct xhci_hcd *xhci;
126 struct dbc_regs __iomem *regs;
127 struct xhci_ring *ring_evt;
128 struct xhci_ring *ring_in;
129 struct xhci_ring *ring_out;
130 struct xhci_erst erst;
131 struct xhci_container_ctx *ctx;
132
133 struct dbc_str_descs *string;
134 dma_addr_t string_dma;
135 size_t string_size;
136 u16 idVendor;
137 u16 idProduct;
138 u16 bcdDevice;
139 u8 bInterfaceProtocol;
140
141 enum dbc_state state;
142 struct delayed_work event_work;
143 unsigned resume_required:1;
144 struct dbc_ep eps[2];
145
146 const struct dbc_driver *driver;
147 void *priv;
148};
149
150struct dbc_request {
151 void *buf;
152 unsigned int length;
153 dma_addr_t dma;
154 void (*complete)(struct xhci_dbc *dbc,
155 struct dbc_request *req);
156 struct list_head list_pool;
157 int status;
158 unsigned int actual;
159
160 struct xhci_dbc *dbc;
161 struct list_head list_pending;
162 dma_addr_t trb_dma;
163 union xhci_trb *trb;
164 unsigned direction:1;
165};
166
167#define dbc_bulkout_ctx(d) \
168 ((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE))
169#define dbc_bulkin_ctx(d) \
170 ((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE * 2))
171#define dbc_bulkout_enq(d) \
172 xhci_trb_virt_to_dma((d)->ring_out->enq_seg, (d)->ring_out->enqueue)
173#define dbc_bulkin_enq(d) \
174 xhci_trb_virt_to_dma((d)->ring_in->enq_seg, (d)->ring_in->enqueue)
175#define dbc_epctx_info2(t, p, b) \
176 cpu_to_le32(EP_TYPE(t) | MAX_PACKET(p) | MAX_BURST(b))
177#define dbc_ep_dma_direction(d) \
178 ((d)->direction ? DMA_FROM_DEVICE : DMA_TO_DEVICE)
179
180#define BULK_OUT 0
181#define BULK_IN 1
182#define EPID_OUT 2
183#define EPID_IN 3
184
185enum evtreturn {
186 EVT_ERR = -1,
187 EVT_DONE,
188 EVT_GSER,
189 EVT_DISC,
190};
191
192static inline struct dbc_ep *get_in_ep(struct xhci_dbc *dbc)
193{
194 return &dbc->eps[BULK_IN];
195}
196
197static inline struct dbc_ep *get_out_ep(struct xhci_dbc *dbc)
198{
199 return &dbc->eps[BULK_OUT];
200}
201
202#ifdef CONFIG_USB_XHCI_DBGCAP
203int xhci_create_dbc_dev(struct xhci_hcd *xhci);
204void xhci_remove_dbc_dev(struct xhci_hcd *xhci);
205int xhci_dbc_init(void);
206void xhci_dbc_exit(void);
207int dbc_tty_init(void);
208void dbc_tty_exit(void);
209int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_hcd *xhci);
210void xhci_dbc_tty_remove(struct xhci_dbc *dbc);
211struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res,
212 const struct dbc_driver *driver);
213void xhci_dbc_remove(struct xhci_dbc *dbc);
214struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc,
215 unsigned int direction,
216 gfp_t flags);
217void dbc_free_request(struct dbc_request *req);
218int dbc_ep_queue(struct dbc_request *req);
219#ifdef CONFIG_PM
220int xhci_dbc_suspend(struct xhci_hcd *xhci);
221int xhci_dbc_resume(struct xhci_hcd *xhci);
222#endif /* CONFIG_PM */
223#else
224static inline int xhci_create_dbc_dev(struct xhci_hcd *xhci)
225{
226 return 0;
227}
228
229static inline void xhci_remove_dbc_dev(struct xhci_hcd *xhci)
230{
231}
232static inline int xhci_dbc_init(void)
233{
234 return 0;
235}
236static inline void xhci_dbc_exit(void)
237{
238}
239static inline int xhci_dbc_suspend(struct xhci_hcd *xhci)
240{
241 return 0;
242}
243
244static inline int xhci_dbc_resume(struct xhci_hcd *xhci)
245{
246 return 0;
247}
248#endif /* CONFIG_USB_XHCI_DBGCAP */
249#endif /* __LINUX_XHCI_DBGCAP_H */