You've already forked linux-rockchip
mirror of
https://github.com/armbian/linux-rockchip.git
synced 2026-01-06 11:08:10 -08:00
usb: xhci: Add DbC support in xHCI driver
xHCI compatible USB host controllers(i.e. super-speed USB3 controllers) can be implemented with the Debug Capability(DbC). It presents a debug device which is fully compliant with the USB framework and provides the equivalent of a very high performance full-duplex serial link. The debug capability operation model and registers interface are defined in 7.6.8 of the xHCI specification, revision 1.1. The DbC debug device shares a root port with the xHCI host. By default, the debug capability is disabled and the root port is assigned to xHCI. When the DbC is enabled, the root port will be assigned to the DbC debug device, and the xHCI sees nothing on this port. This implementation uses a sysfs node named <dbc> under the xHCI device to manage the enabling and disabling of the debug capability. When the debug capability is enabled, it will present a debug device through the debug port. This debug device is fully compliant with the USB3 framework, and it can be enumerated by a debug host on the other end of the USB link. As soon as the debug device is configured, a TTY serial device named /dev/ttyDBC0 will be created. Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
67d2ea9fde
commit
dfba2174dc
25
Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd
Normal file
25
Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd
Normal file
@@ -0,0 +1,25 @@
|
||||
What: /sys/bus/pci/drivers/xhci_hcd/.../dbc
|
||||
Date: June 2017
|
||||
Contact: Lu Baolu <baolu.lu@linux.intel.com>
|
||||
Description:
|
||||
xHCI compatible USB host controllers (i.e. super-speed
|
||||
USB3 controllers) are often implemented with the Debug
|
||||
Capability (DbC). It can present a debug device which
|
||||
is fully compliant with the USB framework and provides
|
||||
the equivalent of a very high performance full-duplex
|
||||
serial link for debug purpose.
|
||||
|
||||
The DbC debug device shares a root port with xHCI host.
|
||||
When the DbC is enabled, the root port will be assigned
|
||||
to the Debug Capability. Otherwise, it will be assigned
|
||||
to xHCI.
|
||||
|
||||
Writing "enable" to this attribute will enable the DbC
|
||||
functionality and the shared root port will be assigned
|
||||
to the DbC device. Writing "disable" to this attribute
|
||||
will disable the DbC functionality and the shared root
|
||||
port will roll back to the xHCI.
|
||||
|
||||
Reading this attribute gives the state of the DbC. It
|
||||
can be one of the following states: disabled, enabled,
|
||||
initialized, connected, configured and stalled.
|
||||
@@ -27,6 +27,14 @@ config USB_XHCI_HCD
|
||||
module will be called xhci-hcd.
|
||||
|
||||
if USB_XHCI_HCD
|
||||
config USB_XHCI_DBGCAP
|
||||
bool "xHCI support for debug capability"
|
||||
depends on TTY
|
||||
---help---
|
||||
Say 'Y' to enable the support for the xHCI debug capability. Make
|
||||
sure that your xHCI host supports the extended debug capability and
|
||||
you want a TTY serial device based on the xHCI debug capability
|
||||
before enabling this option. If unsure, say 'N'.
|
||||
|
||||
config USB_XHCI_PCI
|
||||
tristate
|
||||
|
||||
@@ -14,6 +14,11 @@ fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o
|
||||
xhci-hcd-y := xhci.o xhci-mem.o
|
||||
xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o
|
||||
xhci-hcd-y += xhci-trace.o
|
||||
|
||||
ifneq ($(CONFIG_USB_XHCI_DBGCAP), )
|
||||
xhci-hcd-y += xhci-dbgcap.o xhci-dbgtty.o
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_USB_XHCI_MTK), )
|
||||
xhci-hcd-y += xhci-mtk-sch.o
|
||||
endif
|
||||
|
||||
996
drivers/usb/host/xhci-dbgcap.c
Normal file
996
drivers/usb/host/xhci-dbgcap.c
Normal file
File diff suppressed because it is too large
Load Diff
229
drivers/usb/host/xhci-dbgcap.h
Normal file
229
drivers/usb/host/xhci-dbgcap.h
Normal file
@@ -0,0 +1,229 @@
|
||||
|
||||
/**
|
||||
* xhci-dbgcap.h - xHCI debug capability support
|
||||
*
|
||||
* Copyright (C) 2017 Intel Corporation
|
||||
*
|
||||
* Author: Lu Baolu <baolu.lu@linux.intel.com>
|
||||
*/
|
||||
#ifndef __LINUX_XHCI_DBGCAP_H
|
||||
#define __LINUX_XHCI_DBGCAP_H
|
||||
|
||||
#include <linux/tty.h>
|
||||
#include <linux/kfifo.h>
|
||||
|
||||
struct dbc_regs {
|
||||
__le32 capability;
|
||||
__le32 doorbell;
|
||||
__le32 ersts; /* Event Ring Segment Table Size*/
|
||||
__le32 __reserved_0; /* 0c~0f reserved bits */
|
||||
__le64 erstba; /* Event Ring Segment Table Base Address */
|
||||
__le64 erdp; /* Event Ring Dequeue Pointer */
|
||||
__le32 control;
|
||||
__le32 status;
|
||||
__le32 portsc; /* Port status and control */
|
||||
__le32 __reserved_1; /* 2b~28 reserved bits */
|
||||
__le64 dccp; /* Debug Capability Context Pointer */
|
||||
__le32 devinfo1; /* Device Descriptor Info Register 1 */
|
||||
__le32 devinfo2; /* Device Descriptor Info Register 2 */
|
||||
};
|
||||
|
||||
struct dbc_info_context {
|
||||
__le64 string0;
|
||||
__le64 manufacturer;
|
||||
__le64 product;
|
||||
__le64 serial;
|
||||
__le32 length;
|
||||
__le32 __reserved_0[7];
|
||||
};
|
||||
|
||||
#define DBC_CTRL_DBC_RUN BIT(0)
|
||||
#define DBC_CTRL_PORT_ENABLE BIT(1)
|
||||
#define DBC_CTRL_HALT_OUT_TR BIT(2)
|
||||
#define DBC_CTRL_HALT_IN_TR BIT(3)
|
||||
#define DBC_CTRL_DBC_RUN_CHANGE BIT(4)
|
||||
#define DBC_CTRL_DBC_ENABLE BIT(31)
|
||||
#define DBC_CTRL_MAXBURST(p) (((p) >> 16) & 0xff)
|
||||
#define DBC_DOOR_BELL_TARGET(p) (((p) & 0xff) << 8)
|
||||
|
||||
#define DBC_MAX_PACKET 1024
|
||||
#define DBC_MAX_STRING_LENGTH 64
|
||||
#define DBC_STRING_MANUFACTURER "Linux Foundation"
|
||||
#define DBC_STRING_PRODUCT "Linux USB Debug Target"
|
||||
#define DBC_STRING_SERIAL "0001"
|
||||
#define DBC_CONTEXT_SIZE 64
|
||||
|
||||
/*
|
||||
* Port status:
|
||||
*/
|
||||
#define DBC_PORTSC_CONN_STATUS BIT(0)
|
||||
#define DBC_PORTSC_PORT_ENABLED BIT(1)
|
||||
#define DBC_PORTSC_CONN_CHANGE BIT(17)
|
||||
#define DBC_PORTSC_RESET_CHANGE BIT(21)
|
||||
#define DBC_PORTSC_LINK_CHANGE BIT(22)
|
||||
#define DBC_PORTSC_CONFIG_CHANGE BIT(23)
|
||||
|
||||
struct dbc_str_descs {
|
||||
char string0[DBC_MAX_STRING_LENGTH];
|
||||
char manufacturer[DBC_MAX_STRING_LENGTH];
|
||||
char product[DBC_MAX_STRING_LENGTH];
|
||||
char serial[DBC_MAX_STRING_LENGTH];
|
||||
};
|
||||
|
||||
#define DBC_PROTOCOL 1 /* GNU Remote Debug Command */
|
||||
#define DBC_VENDOR_ID 0x1d6b /* Linux Foundation 0x1d6b */
|
||||
#define DBC_PRODUCT_ID 0x0010 /* device 0010 */
|
||||
#define DBC_DEVICE_REV 0x0010 /* 0.10 */
|
||||
|
||||
enum dbc_state {
|
||||
DS_DISABLED = 0,
|
||||
DS_INITIALIZED,
|
||||
DS_ENABLED,
|
||||
DS_CONNECTED,
|
||||
DS_CONFIGURED,
|
||||
DS_STALLED,
|
||||
};
|
||||
|
||||
struct dbc_request {
|
||||
void *buf;
|
||||
unsigned int length;
|
||||
dma_addr_t dma;
|
||||
void (*complete)(struct xhci_hcd *xhci,
|
||||
struct dbc_request *req);
|
||||
struct list_head list_pool;
|
||||
int status;
|
||||
unsigned int actual;
|
||||
|
||||
struct dbc_ep *dep;
|
||||
struct list_head list_pending;
|
||||
dma_addr_t trb_dma;
|
||||
union xhci_trb *trb;
|
||||
unsigned direction:1;
|
||||
};
|
||||
|
||||
struct dbc_ep {
|
||||
struct xhci_dbc *dbc;
|
||||
struct list_head list_pending;
|
||||
struct xhci_ring *ring;
|
||||
unsigned direction:1;
|
||||
};
|
||||
|
||||
#define DBC_QUEUE_SIZE 16
|
||||
#define DBC_WRITE_BUF_SIZE 8192
|
||||
|
||||
/*
|
||||
* Private structure for DbC hardware state:
|
||||
*/
|
||||
struct dbc_port {
|
||||
struct tty_port port;
|
||||
spinlock_t port_lock; /* port access */
|
||||
|
||||
struct list_head read_pool;
|
||||
struct list_head read_queue;
|
||||
unsigned int n_read;
|
||||
struct tasklet_struct push;
|
||||
|
||||
struct list_head write_pool;
|
||||
struct kfifo write_fifo;
|
||||
|
||||
bool registered;
|
||||
struct dbc_ep *in;
|
||||
struct dbc_ep *out;
|
||||
};
|
||||
|
||||
struct xhci_dbc {
|
||||
spinlock_t lock; /* device access */
|
||||
struct xhci_hcd *xhci;
|
||||
struct dbc_regs __iomem *regs;
|
||||
struct xhci_ring *ring_evt;
|
||||
struct xhci_ring *ring_in;
|
||||
struct xhci_ring *ring_out;
|
||||
struct xhci_erst erst;
|
||||
struct xhci_container_ctx *ctx;
|
||||
|
||||
struct dbc_str_descs *string;
|
||||
dma_addr_t string_dma;
|
||||
size_t string_size;
|
||||
|
||||
enum dbc_state state;
|
||||
struct delayed_work event_work;
|
||||
unsigned resume_required:1;
|
||||
struct dbc_ep eps[2];
|
||||
|
||||
struct dbc_port port;
|
||||
};
|
||||
|
||||
#define dbc_bulkout_ctx(d) \
|
||||
((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE))
|
||||
#define dbc_bulkin_ctx(d) \
|
||||
((struct xhci_ep_ctx *)((d)->ctx->bytes + DBC_CONTEXT_SIZE * 2))
|
||||
#define dbc_bulkout_enq(d) \
|
||||
xhci_trb_virt_to_dma((d)->ring_out->enq_seg, (d)->ring_out->enqueue)
|
||||
#define dbc_bulkin_enq(d) \
|
||||
xhci_trb_virt_to_dma((d)->ring_in->enq_seg, (d)->ring_in->enqueue)
|
||||
#define dbc_epctx_info2(t, p, b) \
|
||||
cpu_to_le32(EP_TYPE(t) | MAX_PACKET(p) | MAX_BURST(b))
|
||||
#define dbc_ep_dma_direction(d) \
|
||||
((d)->direction ? DMA_FROM_DEVICE : DMA_TO_DEVICE)
|
||||
|
||||
#define BULK_OUT 0
|
||||
#define BULK_IN 1
|
||||
#define EPID_OUT 2
|
||||
#define EPID_IN 3
|
||||
|
||||
enum evtreturn {
|
||||
EVT_ERR = -1,
|
||||
EVT_DONE,
|
||||
EVT_GSER,
|
||||
EVT_DISC,
|
||||
};
|
||||
|
||||
static inline struct dbc_ep *get_in_ep(struct xhci_hcd *xhci)
|
||||
{
|
||||
struct xhci_dbc *dbc = xhci->dbc;
|
||||
|
||||
return &dbc->eps[BULK_IN];
|
||||
}
|
||||
|
||||
static inline struct dbc_ep *get_out_ep(struct xhci_hcd *xhci)
|
||||
{
|
||||
struct xhci_dbc *dbc = xhci->dbc;
|
||||
|
||||
return &dbc->eps[BULK_OUT];
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_XHCI_DBGCAP
|
||||
int xhci_dbc_init(struct xhci_hcd *xhci);
|
||||
void xhci_dbc_exit(struct xhci_hcd *xhci);
|
||||
int xhci_dbc_tty_register_driver(struct xhci_hcd *xhci);
|
||||
void xhci_dbc_tty_unregister_driver(void);
|
||||
int xhci_dbc_tty_register_device(struct xhci_hcd *xhci);
|
||||
void xhci_dbc_tty_unregister_device(struct xhci_hcd *xhci);
|
||||
struct dbc_request *dbc_alloc_request(struct dbc_ep *dep, gfp_t gfp_flags);
|
||||
void dbc_free_request(struct dbc_ep *dep, struct dbc_request *req);
|
||||
int dbc_ep_queue(struct dbc_ep *dep, struct dbc_request *req, gfp_t gfp_flags);
|
||||
#ifdef CONFIG_PM
|
||||
int xhci_dbc_suspend(struct xhci_hcd *xhci);
|
||||
int xhci_dbc_resume(struct xhci_hcd *xhci);
|
||||
#endif /* CONFIG_PM */
|
||||
#else
|
||||
static inline int xhci_dbc_init(struct xhci_hcd *xhci)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void xhci_dbc_exit(struct xhci_hcd *xhci)
|
||||
{
|
||||
}
|
||||
|
||||
static inline int xhci_dbc_suspend(struct xhci_hcd *xhci)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int xhci_dbc_resume(struct xhci_hcd *xhci)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_USB_XHCI_DBGCAP */
|
||||
#endif /* __LINUX_XHCI_DBGCAP_H */
|
||||
497
drivers/usb/host/xhci-dbgtty.c
Normal file
497
drivers/usb/host/xhci-dbgtty.c
Normal file
@@ -0,0 +1,497 @@
|
||||
/**
|
||||
* xhci-dbgtty.c - tty glue for xHCI debug capability
|
||||
*
|
||||
* Copyright (C) 2017 Intel Corporation
|
||||
*
|
||||
* Author: Lu Baolu <baolu.lu@linux.intel.com>
|
||||
*/
|
||||
|
||||
#include <linux/slab.h>
|
||||
#include <linux/tty.h>
|
||||
#include <linux/tty_flip.h>
|
||||
|
||||
#include "xhci.h"
|
||||
#include "xhci-dbgcap.h"
|
||||
|
||||
static unsigned int
|
||||
dbc_send_packet(struct dbc_port *port, char *packet, unsigned int size)
|
||||
{
|
||||
unsigned int len;
|
||||
|
||||
len = kfifo_len(&port->write_fifo);
|
||||
if (len < size)
|
||||
size = len;
|
||||
if (size != 0)
|
||||
size = kfifo_out(&port->write_fifo, packet, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
static int dbc_start_tx(struct dbc_port *port)
|
||||
__releases(&port->port_lock)
|
||||
__acquires(&port->port_lock)
|
||||
{
|
||||
int len;
|
||||
struct dbc_request *req;
|
||||
int status = 0;
|
||||
bool do_tty_wake = false;
|
||||
struct list_head *pool = &port->write_pool;
|
||||
|
||||
while (!list_empty(pool)) {
|
||||
req = list_entry(pool->next, struct dbc_request, list_pool);
|
||||
len = dbc_send_packet(port, req->buf, DBC_MAX_PACKET);
|
||||
if (len == 0)
|
||||
break;
|
||||
do_tty_wake = true;
|
||||
|
||||
req->length = len;
|
||||
list_del(&req->list_pool);
|
||||
|
||||
spin_unlock(&port->port_lock);
|
||||
status = dbc_ep_queue(port->out, req, GFP_ATOMIC);
|
||||
spin_lock(&port->port_lock);
|
||||
|
||||
if (status) {
|
||||
list_add(&req->list_pool, pool);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (do_tty_wake && port->port.tty)
|
||||
tty_wakeup(port->port.tty);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static void dbc_start_rx(struct dbc_port *port)
|
||||
__releases(&port->port_lock)
|
||||
__acquires(&port->port_lock)
|
||||
{
|
||||
struct dbc_request *req;
|
||||
int status;
|
||||
struct list_head *pool = &port->read_pool;
|
||||
|
||||
while (!list_empty(pool)) {
|
||||
if (!port->port.tty)
|
||||
break;
|
||||
|
||||
req = list_entry(pool->next, struct dbc_request, list_pool);
|
||||
list_del(&req->list_pool);
|
||||
req->length = DBC_MAX_PACKET;
|
||||
|
||||
spin_unlock(&port->port_lock);
|
||||
status = dbc_ep_queue(port->in, req, GFP_ATOMIC);
|
||||
spin_lock(&port->port_lock);
|
||||
|
||||
if (status) {
|
||||
list_add(&req->list_pool, pool);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dbc_read_complete(struct xhci_hcd *xhci, struct dbc_request *req)
|
||||
{
|
||||
struct xhci_dbc *dbc = xhci->dbc;
|
||||
struct dbc_port *port = &dbc->port;
|
||||
|
||||
spin_lock(&port->port_lock);
|
||||
list_add_tail(&req->list_pool, &port->read_queue);
|
||||
tasklet_schedule(&port->push);
|
||||
spin_unlock(&port->port_lock);
|
||||
}
|
||||
|
||||
static void dbc_write_complete(struct xhci_hcd *xhci, struct dbc_request *req)
|
||||
{
|
||||
struct xhci_dbc *dbc = xhci->dbc;
|
||||
struct dbc_port *port = &dbc->port;
|
||||
|
||||
spin_lock(&port->port_lock);
|
||||
list_add(&req->list_pool, &port->write_pool);
|
||||
switch (req->status) {
|
||||
case 0:
|
||||
dbc_start_tx(port);
|
||||
break;
|
||||
case -ESHUTDOWN:
|
||||
break;
|
||||
default:
|
||||
xhci_warn(xhci, "unexpected write complete status %d\n",
|
||||
req->status);
|
||||
break;
|
||||
}
|
||||
spin_unlock(&port->port_lock);
|
||||
}
|
||||
|
||||
void xhci_dbc_free_req(struct dbc_ep *dep, struct dbc_request *req)
|
||||
{
|
||||
kfree(req->buf);
|
||||
dbc_free_request(dep, req);
|
||||
}
|
||||
|
||||
static int
|
||||
xhci_dbc_alloc_requests(struct dbc_ep *dep, struct list_head *head,
|
||||
void (*fn)(struct xhci_hcd *, struct dbc_request *))
|
||||
{
|
||||
int i;
|
||||
struct dbc_request *req;
|
||||
|
||||
for (i = 0; i < DBC_QUEUE_SIZE; i++) {
|
||||
req = dbc_alloc_request(dep, GFP_ATOMIC);
|
||||
if (!req)
|
||||
break;
|
||||
|
||||
req->length = DBC_MAX_PACKET;
|
||||
req->buf = kmalloc(req->length, GFP_KERNEL);
|
||||
if (!req->buf) {
|
||||
xhci_dbc_free_req(dep, req);
|
||||
break;
|
||||
}
|
||||
|
||||
req->complete = fn;
|
||||
list_add_tail(&req->list_pool, head);
|
||||
}
|
||||
|
||||
return list_empty(head) ? -ENOMEM : 0;
|
||||
}
|
||||
|
||||
static void
|
||||
xhci_dbc_free_requests(struct dbc_ep *dep, struct list_head *head)
|
||||
{
|
||||
struct dbc_request *req;
|
||||
|
||||
while (!list_empty(head)) {
|
||||
req = list_entry(head->next, struct dbc_request, list_pool);
|
||||
list_del(&req->list_pool);
|
||||
xhci_dbc_free_req(dep, req);
|
||||
}
|
||||
}
|
||||
|
||||
static int dbc_tty_install(struct tty_driver *driver, struct tty_struct *tty)
|
||||
{
|
||||
struct dbc_port *port = driver->driver_state;
|
||||
|
||||
tty->driver_data = port;
|
||||
|
||||
return tty_port_install(&port->port, driver, tty);
|
||||
}
|
||||
|
||||
static int dbc_tty_open(struct tty_struct *tty, struct file *file)
|
||||
{
|
||||
struct dbc_port *port = tty->driver_data;
|
||||
|
||||
return tty_port_open(&port->port, tty, file);
|
||||
}
|
||||
|
||||
static void dbc_tty_close(struct tty_struct *tty, struct file *file)
|
||||
{
|
||||
struct dbc_port *port = tty->driver_data;
|
||||
|
||||
tty_port_close(&port->port, tty, file);
|
||||
}
|
||||
|
||||
static int dbc_tty_write(struct tty_struct *tty,
|
||||
const unsigned char *buf,
|
||||
int count)
|
||||
{
|
||||
struct dbc_port *port = tty->driver_data;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&port->port_lock, flags);
|
||||
if (count)
|
||||
count = kfifo_in(&port->write_fifo, buf, count);
|
||||
dbc_start_tx(port);
|
||||
spin_unlock_irqrestore(&port->port_lock, flags);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int dbc_tty_put_char(struct tty_struct *tty, unsigned char ch)
|
||||
{
|
||||
struct dbc_port *port = tty->driver_data;
|
||||
unsigned long flags;
|
||||
int status;
|
||||
|
||||
spin_lock_irqsave(&port->port_lock, flags);
|
||||
status = kfifo_put(&port->write_fifo, ch);
|
||||
spin_unlock_irqrestore(&port->port_lock, flags);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
static void dbc_tty_flush_chars(struct tty_struct *tty)
|
||||
{
|
||||
struct dbc_port *port = tty->driver_data;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&port->port_lock, flags);
|
||||
dbc_start_tx(port);
|
||||
spin_unlock_irqrestore(&port->port_lock, flags);
|
||||
}
|
||||
|
||||
static int dbc_tty_write_room(struct tty_struct *tty)
|
||||
{
|
||||
struct dbc_port *port = tty->driver_data;
|
||||
unsigned long flags;
|
||||
int room = 0;
|
||||
|
||||
spin_lock_irqsave(&port->port_lock, flags);
|
||||
room = kfifo_avail(&port->write_fifo);
|
||||
spin_unlock_irqrestore(&port->port_lock, flags);
|
||||
|
||||
return room;
|
||||
}
|
||||
|
||||
static int dbc_tty_chars_in_buffer(struct tty_struct *tty)
|
||||
{
|
||||
struct dbc_port *port = tty->driver_data;
|
||||
unsigned long flags;
|
||||
int chars = 0;
|
||||
|
||||
spin_lock_irqsave(&port->port_lock, flags);
|
||||
chars = kfifo_len(&port->write_fifo);
|
||||
spin_unlock_irqrestore(&port->port_lock, flags);
|
||||
|
||||
return chars;
|
||||
}
|
||||
|
||||
static void dbc_tty_unthrottle(struct tty_struct *tty)
|
||||
{
|
||||
struct dbc_port *port = tty->driver_data;
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&port->port_lock, flags);
|
||||
tasklet_schedule(&port->push);
|
||||
spin_unlock_irqrestore(&port->port_lock, flags);
|
||||
}
|
||||
|
||||
static const struct tty_operations dbc_tty_ops = {
|
||||
.install = dbc_tty_install,
|
||||
.open = dbc_tty_open,
|
||||
.close = dbc_tty_close,
|
||||
.write = dbc_tty_write,
|
||||
.put_char = dbc_tty_put_char,
|
||||
.flush_chars = dbc_tty_flush_chars,
|
||||
.write_room = dbc_tty_write_room,
|
||||
.chars_in_buffer = dbc_tty_chars_in_buffer,
|
||||
.unthrottle = dbc_tty_unthrottle,
|
||||
};
|
||||
|
||||
static struct tty_driver *dbc_tty_driver;
|
||||
|
||||
int xhci_dbc_tty_register_driver(struct xhci_hcd *xhci)
|
||||
{
|
||||
int status;
|
||||
struct xhci_dbc *dbc = xhci->dbc;
|
||||
|
||||
dbc_tty_driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW |
|
||||
TTY_DRIVER_DYNAMIC_DEV);
|
||||
if (IS_ERR(dbc_tty_driver)) {
|
||||
status = PTR_ERR(dbc_tty_driver);
|
||||
dbc_tty_driver = NULL;
|
||||
return status;
|
||||
}
|
||||
|
||||
dbc_tty_driver->driver_name = "dbc_serial";
|
||||
dbc_tty_driver->name = "ttyDBC";
|
||||
|
||||
dbc_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
|
||||
dbc_tty_driver->subtype = SERIAL_TYPE_NORMAL;
|
||||
dbc_tty_driver->init_termios = tty_std_termios;
|
||||
dbc_tty_driver->init_termios.c_cflag =
|
||||
B9600 | CS8 | CREAD | HUPCL | CLOCAL;
|
||||
dbc_tty_driver->init_termios.c_ispeed = 9600;
|
||||
dbc_tty_driver->init_termios.c_ospeed = 9600;
|
||||
dbc_tty_driver->driver_state = &dbc->port;
|
||||
|
||||
tty_set_operations(dbc_tty_driver, &dbc_tty_ops);
|
||||
|
||||
status = tty_register_driver(dbc_tty_driver);
|
||||
if (status) {
|
||||
xhci_err(xhci,
|
||||
"can't register dbc tty driver, err %d\n", status);
|
||||
put_tty_driver(dbc_tty_driver);
|
||||
dbc_tty_driver = NULL;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
void xhci_dbc_tty_unregister_driver(void)
|
||||
{
|
||||
tty_unregister_driver(dbc_tty_driver);
|
||||
put_tty_driver(dbc_tty_driver);
|
||||
dbc_tty_driver = NULL;
|
||||
}
|
||||
|
||||
static void dbc_rx_push(unsigned long _port)
|
||||
{
|
||||
struct dbc_request *req;
|
||||
struct tty_struct *tty;
|
||||
bool do_push = false;
|
||||
bool disconnect = false;
|
||||
struct dbc_port *port = (void *)_port;
|
||||
struct list_head *queue = &port->read_queue;
|
||||
|
||||
spin_lock_irq(&port->port_lock);
|
||||
tty = port->port.tty;
|
||||
while (!list_empty(queue)) {
|
||||
req = list_first_entry(queue, struct dbc_request, list_pool);
|
||||
|
||||
if (tty && tty_throttled(tty))
|
||||
break;
|
||||
|
||||
switch (req->status) {
|
||||
case 0:
|
||||
break;
|
||||
case -ESHUTDOWN:
|
||||
disconnect = true;
|
||||
break;
|
||||
default:
|
||||
pr_warn("ttyDBC0: unexpected RX status %d\n",
|
||||
req->status);
|
||||
break;
|
||||
}
|
||||
|
||||
if (req->actual) {
|
||||
char *packet = req->buf;
|
||||
unsigned int n, size = req->actual;
|
||||
int count;
|
||||
|
||||
n = port->n_read;
|
||||
if (n) {
|
||||
packet += n;
|
||||
size -= n;
|
||||
}
|
||||
|
||||
count = tty_insert_flip_string(&port->port, packet,
|
||||
size);
|
||||
if (count)
|
||||
do_push = true;
|
||||
if (count != size) {
|
||||
port->n_read += count;
|
||||
break;
|
||||
}
|
||||
port->n_read = 0;
|
||||
}
|
||||
|
||||
list_move(&req->list_pool, &port->read_pool);
|
||||
}
|
||||
|
||||
if (do_push)
|
||||
tty_flip_buffer_push(&port->port);
|
||||
|
||||
if (!list_empty(queue) && tty) {
|
||||
if (!tty_throttled(tty)) {
|
||||
if (do_push)
|
||||
tasklet_schedule(&port->push);
|
||||
else
|
||||
pr_warn("ttyDBC0: RX not scheduled?\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (!disconnect)
|
||||
dbc_start_rx(port);
|
||||
|
||||
spin_unlock_irq(&port->port_lock);
|
||||
}
|
||||
|
||||
static int dbc_port_activate(struct tty_port *_port, struct tty_struct *tty)
|
||||
{
|
||||
struct dbc_port *port = container_of(_port, struct dbc_port, port);
|
||||
|
||||
spin_lock_irq(&port->port_lock);
|
||||
dbc_start_rx(port);
|
||||
spin_unlock_irq(&port->port_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct tty_port_operations dbc_port_ops = {
|
||||
.activate = dbc_port_activate,
|
||||
};
|
||||
|
||||
static void
|
||||
xhci_dbc_tty_init_port(struct xhci_hcd *xhci, struct dbc_port *port)
|
||||
{
|
||||
tty_port_init(&port->port);
|
||||
spin_lock_init(&port->port_lock);
|
||||
tasklet_init(&port->push, dbc_rx_push, (unsigned long)port);
|
||||
INIT_LIST_HEAD(&port->read_pool);
|
||||
INIT_LIST_HEAD(&port->read_queue);
|
||||
INIT_LIST_HEAD(&port->write_pool);
|
||||
|
||||
port->in = get_in_ep(xhci);
|
||||
port->out = get_out_ep(xhci);
|
||||
port->port.ops = &dbc_port_ops;
|
||||
port->n_read = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
xhci_dbc_tty_exit_port(struct dbc_port *port)
|
||||
{
|
||||
tasklet_kill(&port->push);
|
||||
tty_port_destroy(&port->port);
|
||||
}
|
||||
|
||||
int xhci_dbc_tty_register_device(struct xhci_hcd *xhci)
|
||||
{
|
||||
int ret;
|
||||
struct device *tty_dev;
|
||||
struct xhci_dbc *dbc = xhci->dbc;
|
||||
struct dbc_port *port = &dbc->port;
|
||||
|
||||
xhci_dbc_tty_init_port(xhci, port);
|
||||
tty_dev = tty_port_register_device(&port->port,
|
||||
dbc_tty_driver, 0, NULL);
|
||||
ret = IS_ERR_OR_NULL(tty_dev);
|
||||
if (ret)
|
||||
goto register_fail;
|
||||
|
||||
ret = kfifo_alloc(&port->write_fifo, DBC_WRITE_BUF_SIZE, GFP_KERNEL);
|
||||
if (ret)
|
||||
goto buf_alloc_fail;
|
||||
|
||||
ret = xhci_dbc_alloc_requests(port->in, &port->read_pool,
|
||||
dbc_read_complete);
|
||||
if (ret)
|
||||
goto request_fail;
|
||||
|
||||
ret = xhci_dbc_alloc_requests(port->out, &port->write_pool,
|
||||
dbc_write_complete);
|
||||
if (ret)
|
||||
goto request_fail;
|
||||
|
||||
port->registered = true;
|
||||
|
||||
return 0;
|
||||
|
||||
request_fail:
|
||||
xhci_dbc_free_requests(port->in, &port->read_pool);
|
||||
xhci_dbc_free_requests(port->out, &port->write_pool);
|
||||
kfifo_free(&port->write_fifo);
|
||||
|
||||
buf_alloc_fail:
|
||||
tty_unregister_device(dbc_tty_driver, 0);
|
||||
|
||||
register_fail:
|
||||
xhci_dbc_tty_exit_port(port);
|
||||
|
||||
xhci_err(xhci, "can't register tty port, err %d\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void xhci_dbc_tty_unregister_device(struct xhci_hcd *xhci)
|
||||
{
|
||||
struct xhci_dbc *dbc = xhci->dbc;
|
||||
struct dbc_port *port = &dbc->port;
|
||||
|
||||
tty_unregister_device(dbc_tty_driver, 0);
|
||||
xhci_dbc_tty_exit_port(port);
|
||||
port->registered = false;
|
||||
|
||||
kfifo_free(&port->write_fifo);
|
||||
xhci_dbc_free_requests(get_out_ep(xhci), &port->read_pool);
|
||||
xhci_dbc_free_requests(get_out_ep(xhci), &port->read_queue);
|
||||
xhci_dbc_free_requests(get_in_ep(xhci), &port->write_pool);
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <linux/tracepoint.h>
|
||||
#include "xhci.h"
|
||||
#include "xhci-dbgcap.h"
|
||||
|
||||
#define XHCI_MSG_MAX 500
|
||||
|
||||
@@ -155,6 +156,21 @@ DEFINE_EVENT(xhci_log_trb, xhci_queue_trb,
|
||||
TP_ARGS(ring, trb)
|
||||
);
|
||||
|
||||
DEFINE_EVENT(xhci_log_trb, xhci_dbc_handle_event,
|
||||
TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
|
||||
TP_ARGS(ring, trb)
|
||||
);
|
||||
|
||||
DEFINE_EVENT(xhci_log_trb, xhci_dbc_handle_transfer,
|
||||
TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
|
||||
TP_ARGS(ring, trb)
|
||||
);
|
||||
|
||||
DEFINE_EVENT(xhci_log_trb, xhci_dbc_gadget_ep_queue,
|
||||
TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
|
||||
TP_ARGS(ring, trb)
|
||||
);
|
||||
|
||||
DECLARE_EVENT_CLASS(xhci_log_virt_dev,
|
||||
TP_PROTO(struct xhci_virt_device *vdev),
|
||||
TP_ARGS(vdev),
|
||||
@@ -478,6 +494,49 @@ DEFINE_EVENT(xhci_log_portsc, xhci_handle_port_status,
|
||||
TP_ARGS(portnum, portsc)
|
||||
);
|
||||
|
||||
DECLARE_EVENT_CLASS(xhci_dbc_log_request,
|
||||
TP_PROTO(struct dbc_request *req),
|
||||
TP_ARGS(req),
|
||||
TP_STRUCT__entry(
|
||||
__field(struct dbc_request *, req)
|
||||
__field(bool, dir)
|
||||
__field(unsigned int, actual)
|
||||
__field(unsigned int, length)
|
||||
__field(int, status)
|
||||
),
|
||||
TP_fast_assign(
|
||||
__entry->req = req;
|
||||
__entry->dir = req->direction;
|
||||
__entry->actual = req->actual;
|
||||
__entry->length = req->length;
|
||||
__entry->status = req->status;
|
||||
),
|
||||
TP_printk("%s: req %p length %u/%u ==> %d",
|
||||
__entry->dir ? "bulk-in" : "bulk-out",
|
||||
__entry->req, __entry->actual,
|
||||
__entry->length, __entry->status
|
||||
)
|
||||
);
|
||||
|
||||
DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_alloc_request,
|
||||
TP_PROTO(struct dbc_request *req),
|
||||
TP_ARGS(req)
|
||||
);
|
||||
|
||||
DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_free_request,
|
||||
TP_PROTO(struct dbc_request *req),
|
||||
TP_ARGS(req)
|
||||
);
|
||||
|
||||
DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_queue_request,
|
||||
TP_PROTO(struct dbc_request *req),
|
||||
TP_ARGS(req)
|
||||
);
|
||||
|
||||
DEFINE_EVENT(xhci_dbc_log_request, xhci_dbc_giveback_request,
|
||||
TP_PROTO(struct dbc_request *req),
|
||||
TP_ARGS(req)
|
||||
);
|
||||
#endif /* __XHCI_TRACE_H */
|
||||
|
||||
/* this part must be outside header guard */
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "xhci-trace.h"
|
||||
#include "xhci-mtk.h"
|
||||
#include "xhci-debugfs.h"
|
||||
#include "xhci-dbgcap.h"
|
||||
|
||||
#define DRIVER_AUTHOR "Sarah Sharp"
|
||||
#define DRIVER_DESC "'eXtensible' Host Controller (xHC) Driver"
|
||||
@@ -622,6 +623,8 @@ int xhci_run(struct usb_hcd *hcd)
|
||||
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
|
||||
"Finished xhci_run for USB2 roothub");
|
||||
|
||||
xhci_dbc_init(xhci);
|
||||
|
||||
xhci_debugfs_init(xhci);
|
||||
|
||||
return 0;
|
||||
@@ -654,6 +657,8 @@ static void xhci_stop(struct usb_hcd *hcd)
|
||||
|
||||
xhci_debugfs_exit(xhci);
|
||||
|
||||
xhci_dbc_exit(xhci);
|
||||
|
||||
spin_lock_irq(&xhci->lock);
|
||||
xhci->xhc_state |= XHCI_STATE_HALTED;
|
||||
xhci->cmd_ring_state = CMD_RING_STATE_STOPPED;
|
||||
@@ -870,6 +875,8 @@ int xhci_suspend(struct xhci_hcd *xhci, bool do_wakeup)
|
||||
xhci->shared_hcd->state != HC_STATE_SUSPENDED)
|
||||
return -EINVAL;
|
||||
|
||||
xhci_dbc_suspend(xhci);
|
||||
|
||||
/* Clear root port wake on bits if wakeup not allowed. */
|
||||
if (!do_wakeup)
|
||||
xhci_disable_port_wake_on_bits(xhci);
|
||||
@@ -1065,6 +1072,8 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
|
||||
|
||||
spin_unlock_irq(&xhci->lock);
|
||||
|
||||
xhci_dbc_resume(xhci);
|
||||
|
||||
done:
|
||||
if (retval == 0) {
|
||||
/* Resume root hubs only when have pending events. */
|
||||
|
||||
@@ -1856,6 +1856,7 @@ struct xhci_hcd {
|
||||
struct dentry *debugfs_slots;
|
||||
struct list_head regset_list;
|
||||
|
||||
void *dbc;
|
||||
/* platform-specific data -- must come last */
|
||||
unsigned long priv[0] __aligned(sizeof(s64));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user