0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef __LINUX_XHCI_DBGCAP_H
0010 #define __LINUX_XHCI_DBGCAP_H
0011
0012 #include <linux/tty.h>
0013 #include <linux/kfifo.h>
0014
0015 struct dbc_regs {
0016 __le32 capability;
0017 __le32 doorbell;
0018 __le32 ersts;
0019 __le32 __reserved_0;
0020 __le64 erstba;
0021 __le64 erdp;
0022 __le32 control;
0023 __le32 status;
0024 __le32 portsc;
0025 __le32 __reserved_1;
0026 __le64 dccp;
0027 __le32 devinfo1;
0028 __le32 devinfo2;
0029 };
0030
0031 struct dbc_info_context {
0032 __le64 string0;
0033 __le64 manufacturer;
0034 __le64 product;
0035 __le64 serial;
0036 __le32 length;
0037 __le32 __reserved_0[7];
0038 };
0039
0040 #define DBC_CTRL_DBC_RUN BIT(0)
0041 #define DBC_CTRL_PORT_ENABLE BIT(1)
0042 #define DBC_CTRL_HALT_OUT_TR BIT(2)
0043 #define DBC_CTRL_HALT_IN_TR BIT(3)
0044 #define DBC_CTRL_DBC_RUN_CHANGE BIT(4)
0045 #define DBC_CTRL_DBC_ENABLE BIT(31)
0046 #define DBC_CTRL_MAXBURST(p) (((p) >> 16) & 0xff)
0047 #define DBC_DOOR_BELL_TARGET(p) (((p) & 0xff) << 8)
0048
0049 #define DBC_MAX_PACKET 1024
0050 #define DBC_MAX_STRING_LENGTH 64
0051 #define DBC_STRING_MANUFACTURER "Linux Foundation"
0052 #define DBC_STRING_PRODUCT "Linux USB Debug Target"
0053 #define DBC_STRING_SERIAL "0001"
0054 #define DBC_CONTEXT_SIZE 64
0055
0056
0057
0058
0059 #define DBC_PORTSC_CONN_STATUS BIT(0)
0060 #define DBC_PORTSC_PORT_ENABLED BIT(1)
0061 #define DBC_PORTSC_CONN_CHANGE BIT(17)
0062 #define DBC_PORTSC_RESET_CHANGE BIT(21)
0063 #define DBC_PORTSC_LINK_CHANGE BIT(22)
0064 #define DBC_PORTSC_CONFIG_CHANGE BIT(23)
0065
0066 struct dbc_str_descs {
0067 char string0[DBC_MAX_STRING_LENGTH];
0068 char manufacturer[DBC_MAX_STRING_LENGTH];
0069 char product[DBC_MAX_STRING_LENGTH];
0070 char serial[DBC_MAX_STRING_LENGTH];
0071 };
0072
0073 #define DBC_PROTOCOL 1
0074 #define DBC_VENDOR_ID 0x1d6b
0075 #define DBC_PRODUCT_ID 0x0010
0076 #define DBC_DEVICE_REV 0x0010
0077
0078 enum dbc_state {
0079 DS_DISABLED = 0,
0080 DS_INITIALIZED,
0081 DS_ENABLED,
0082 DS_CONNECTED,
0083 DS_CONFIGURED,
0084 DS_STALLED,
0085 };
0086
0087 struct dbc_ep {
0088 struct xhci_dbc *dbc;
0089 struct list_head list_pending;
0090 struct xhci_ring *ring;
0091 unsigned int direction:1;
0092 };
0093
0094 #define DBC_QUEUE_SIZE 16
0095 #define DBC_WRITE_BUF_SIZE 8192
0096
0097
0098
0099
0100 struct dbc_port {
0101 struct tty_port port;
0102 spinlock_t port_lock;
0103 int minor;
0104
0105 struct list_head read_pool;
0106 struct list_head read_queue;
0107 unsigned int n_read;
0108 struct tasklet_struct push;
0109
0110 struct list_head write_pool;
0111 struct kfifo write_fifo;
0112
0113 bool registered;
0114 };
0115
0116 struct dbc_driver {
0117 int (*configure)(struct xhci_dbc *dbc);
0118 void (*disconnect)(struct xhci_dbc *dbc);
0119 };
0120
0121 struct xhci_dbc {
0122 spinlock_t lock;
0123 struct device *dev;
0124 struct xhci_hcd *xhci;
0125 struct dbc_regs __iomem *regs;
0126 struct xhci_ring *ring_evt;
0127 struct xhci_ring *ring_in;
0128 struct xhci_ring *ring_out;
0129 struct xhci_erst erst;
0130 struct xhci_container_ctx *ctx;
0131
0132 struct dbc_str_descs *string;
0133 dma_addr_t string_dma;
0134 size_t string_size;
0135
0136 enum dbc_state state;
0137 struct delayed_work event_work;
0138 unsigned resume_required:1;
0139 struct dbc_ep eps[2];
0140
0141 const struct dbc_driver *driver;
0142 void *priv;
0143 };
0144
0145 struct dbc_request {
0146 void *buf;
0147 unsigned int length;
0148 dma_addr_t dma;
0149 void (*complete)(struct xhci_dbc *dbc,
0150 struct dbc_request *req);
0151 struct list_head list_pool;
0152 int status;
0153 unsigned int actual;
0154
0155 struct xhci_dbc *dbc;
0156 struct list_head list_pending;
0157 dma_addr_t trb_dma;
0158 union xhci_trb *trb;
0159 unsigned direction:1;
0160 };
0161
0162 #define dbc_bulkout_ctx(d) \
0163 ((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE))
0164 #define dbc_bulkin_ctx(d) \
0165 ((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE * 2))
0166 #define dbc_bulkout_enq(d) \
0167 xhci_trb_virt_to_dma((d)->ring_out->enq_seg, (d)->ring_out->enqueue)
0168 #define dbc_bulkin_enq(d) \
0169 xhci_trb_virt_to_dma((d)->ring_in->enq_seg, (d)->ring_in->enqueue)
0170 #define dbc_epctx_info2(t, p, b) \
0171 cpu_to_le32(EP_TYPE(t) | MAX_PACKET(p) | MAX_BURST(b))
0172 #define dbc_ep_dma_direction(d) \
0173 ((d)->direction ? DMA_FROM_DEVICE : DMA_TO_DEVICE)
0174
0175 #define BULK_OUT 0
0176 #define BULK_IN 1
0177 #define EPID_OUT 2
0178 #define EPID_IN 3
0179
0180 enum evtreturn {
0181 EVT_ERR = -1,
0182 EVT_DONE,
0183 EVT_GSER,
0184 EVT_DISC,
0185 };
0186
0187 static inline struct dbc_ep *get_in_ep(struct xhci_dbc *dbc)
0188 {
0189 return &dbc->eps[BULK_IN];
0190 }
0191
0192 static inline struct dbc_ep *get_out_ep(struct xhci_dbc *dbc)
0193 {
0194 return &dbc->eps[BULK_OUT];
0195 }
0196
0197 #ifdef CONFIG_USB_XHCI_DBGCAP
0198 int xhci_create_dbc_dev(struct xhci_hcd *xhci);
0199 void xhci_remove_dbc_dev(struct xhci_hcd *xhci);
0200 int xhci_dbc_init(void);
0201 void xhci_dbc_exit(void);
0202 int dbc_tty_init(void);
0203 void dbc_tty_exit(void);
0204 int xhci_dbc_tty_probe(struct device *dev, void __iomem *res, struct xhci_hcd *xhci);
0205 void xhci_dbc_tty_remove(struct xhci_dbc *dbc);
0206 struct xhci_dbc *xhci_alloc_dbc(struct device *dev, void __iomem *res,
0207 const struct dbc_driver *driver);
0208 void xhci_dbc_remove(struct xhci_dbc *dbc);
0209 struct dbc_request *dbc_alloc_request(struct xhci_dbc *dbc,
0210 unsigned int direction,
0211 gfp_t flags);
0212 void dbc_free_request(struct dbc_request *req);
0213 int dbc_ep_queue(struct dbc_request *req);
0214 #ifdef CONFIG_PM
0215 int xhci_dbc_suspend(struct xhci_hcd *xhci);
0216 int xhci_dbc_resume(struct xhci_hcd *xhci);
0217 #endif
0218 #else
0219 static inline int xhci_create_dbc_dev(struct xhci_hcd *xhci)
0220 {
0221 return 0;
0222 }
0223
0224 static inline void xhci_remove_dbc_dev(struct xhci_hcd *xhci)
0225 {
0226 }
0227 static inline int xhci_dbc_init(void)
0228 {
0229 return 0;
0230 }
0231 static inline void xhci_dbc_exit(void)
0232 {
0233 }
0234 static inline int xhci_dbc_suspend(struct xhci_hcd *xhci)
0235 {
0236 return 0;
0237 }
0238
0239 static inline int xhci_dbc_resume(struct xhci_hcd *xhci)
0240 {
0241 return 0;
0242 }
0243 #endif
0244 #endif