Skip to content

Commit

Permalink
usb: mtu3: add tracepoints to help debug
Browse files Browse the repository at this point in the history
This patch implements a few initial tracepoints for the
mtu3 driver. More traces can be added as necessary in order
to ease the task of debugging.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Chunfeng Yun authored and Greg Kroah-Hartman committed Mar 26, 2019
1 parent 4aab6ad commit 83374e0
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 1 deletion.
7 changes: 7 additions & 0 deletions drivers/usb/mtu3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

ccflags-$(CONFIG_USB_MTU3_DEBUG) += -DDEBUG

# define_trace.h needs to know how to find our header
CFLAGS_mtu3_trace.o := -I$(src)

obj-$(CONFIG_USB_MTU3) += mtu3.o

mtu3-y := mtu3_plat.o

ifneq ($(CONFIG_TRACING),)
mtu3-y += mtu3_trace.o
endif

ifneq ($(filter y,$(CONFIG_USB_MTU3_HOST) $(CONFIG_USB_MTU3_DUAL_ROLE)),)
mtu3-y += mtu3_host.o
endif
Expand Down
5 changes: 5 additions & 0 deletions drivers/usb/mtu3/mtu3_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "mtu3.h"
#include "mtu3_debug.h"
#include "mtu3_trace.h"

static int ep_fifo_alloc(struct mtu3_ep *mep, u32 seg_size)
{
Expand Down Expand Up @@ -656,6 +657,8 @@ static irqreturn_t mtu3_link_isr(struct mtu3 *mtu)
break;
}
dev_dbg(mtu->dev, "%s: %s\n", __func__, usb_speed_string(udev_speed));
mtu3_dbg_trace(mtu->dev, "link speed %s",
usb_speed_string(udev_speed));

mtu->g.speed = udev_speed;
mtu->g.ep0->maxpacket = maxpkt;
Expand All @@ -678,6 +681,7 @@ static irqreturn_t mtu3_u3_ltssm_isr(struct mtu3 *mtu)
ltssm &= mtu3_readl(mbase, U3D_LTSSM_INTR_ENABLE);
mtu3_writel(mbase, U3D_LTSSM_INTR, ltssm); /* W1C */
dev_dbg(mtu->dev, "=== LTSSM[%x] ===\n", ltssm);
trace_mtu3_u3_ltssm_isr(ltssm);

if (ltssm & (HOT_RST_INTR | WARM_RST_INTR))
mtu3_gadget_reset(mtu);
Expand Down Expand Up @@ -708,6 +712,7 @@ static irqreturn_t mtu3_u2_common_isr(struct mtu3 *mtu)
u2comm &= mtu3_readl(mbase, U3D_COMMON_USB_INTR_ENABLE);
mtu3_writel(mbase, U3D_COMMON_USB_INTR, u2comm); /* W1C */
dev_dbg(mtu->dev, "=== U2COMM[%x] ===\n", u2comm);
trace_mtu3_u2_common_isr(u2comm);

if (u2comm & SUSPEND_INTR)
mtu3_gadget_suspend(mtu);
Expand Down
8 changes: 8 additions & 0 deletions drivers/usb/mtu3/mtu3_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ static inline void ssusb_debugfs_remove_root(struct ssusb_mtk *ssusb) {}

#endif /* CONFIG_DEBUG_FS */

#if IS_ENABLED(CONFIG_TRACING)
void mtu3_dbg_trace(struct device *dev, const char *fmt, ...);

#else
static inline void mtu3_dbg_trace(struct device *dev, const char *fmt, ...) {}

#endif /* CONFIG_TRACING */

#endif /* __MTU3_DEBUG_H__ */
1 change: 1 addition & 0 deletions drivers/usb/mtu3/mtu3_dr.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ static void ssusb_set_mailbox(struct otg_switch_mtk *otg_sx,
struct mtu3 *mtu = ssusb->u3d;

dev_dbg(ssusb->dev, "mailbox state(%d)\n", status);
mtu3_dbg_trace(ssusb->dev, "mailbox %d", status);

switch (status) {
case MTU3_ID_GROUND:
Expand Down
14 changes: 13 additions & 1 deletion drivers/usb/mtu3/mtu3_gadget.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

#include "mtu3.h"
#include "mtu3_trace.h"

void mtu3_req_complete(struct mtu3_ep *mep,
struct usb_request *req, int status)
Expand All @@ -25,6 +26,8 @@ __acquires(mep->mtu->lock)

mtu = mreq->mtu;
mep->busy = 1;

trace_mtu3_req_complete(mreq);
spin_unlock(&mtu->lock);

/* ep0 makes use of PIO, needn't unmap it */
Expand Down Expand Up @@ -201,6 +204,7 @@ static int mtu3_gadget_ep_enable(struct usb_ep *ep,
spin_unlock_irqrestore(&mtu->lock, flags);

dev_dbg(mtu->dev, "%s active_ep=%d\n", __func__, mtu->active_ep);
trace_mtu3_gadget_ep_enable(mep);

return ret;
}
Expand All @@ -212,6 +216,7 @@ static int mtu3_gadget_ep_disable(struct usb_ep *ep)
unsigned long flags;

dev_dbg(mtu->dev, "%s %s\n", __func__, mep->name);
trace_mtu3_gadget_ep_disable(mep);

if (!(mep->flags & MTU3_EP_ENABLED)) {
dev_warn(mtu->dev, "%s is already disabled\n", mep->name);
Expand Down Expand Up @@ -242,13 +247,17 @@ struct usb_request *mtu3_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
mreq->request.dma = DMA_ADDR_INVALID;
mreq->epnum = mep->epnum;
mreq->mep = mep;
trace_mtu3_alloc_request(mreq);

return &mreq->request;
}

void mtu3_free_request(struct usb_ep *ep, struct usb_request *req)
{
kfree(to_mtu3_request(req));
struct mtu3_request *mreq = to_mtu3_request(req);

trace_mtu3_free_request(mreq);
kfree(mreq);
}

static int mtu3_gadget_queue(struct usb_ep *ep,
Expand Down Expand Up @@ -316,6 +325,7 @@ static int mtu3_gadget_queue(struct usb_ep *ep,

error:
spin_unlock_irqrestore(&mtu->lock, flags);
trace_mtu3_gadget_queue(mreq);

return ret;
}
Expand All @@ -333,6 +343,7 @@ static int mtu3_gadget_dequeue(struct usb_ep *ep, struct usb_request *req)
return -EINVAL;

dev_dbg(mtu->dev, "%s : req=%p\n", __func__, req);
trace_mtu3_gadget_dequeue(mreq);

spin_lock_irqsave(&mtu->lock, flags);

Expand Down Expand Up @@ -403,6 +414,7 @@ static int mtu3_gadget_ep_set_halt(struct usb_ep *ep, int value)

done:
spin_unlock_irqrestore(&mtu->lock, flags);
trace_mtu3_gadget_ep_set_halt(mep);

return ret;
}
Expand Down
4 changes: 4 additions & 0 deletions drivers/usb/mtu3/mtu3_gadget_ep0.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <linux/usb/composite.h>

#include "mtu3.h"
#include "mtu3_debug.h"
#include "mtu3_trace.h"

/* ep0 is always mtu3->in_eps[0] */
#define next_ep0_request(mtu) next_request((mtu)->ep0)
Expand Down Expand Up @@ -634,6 +636,7 @@ __acquires(mtu->lock)
int handled = 0;

ep0_read_setup(mtu, &setup);
trace_mtu3_handle_setup(&setup);

if ((setup.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD)
handled = handle_standard_request(mtu, &setup);
Expand Down Expand Up @@ -710,6 +713,7 @@ irqreturn_t mtu3_ep0_isr(struct mtu3 *mtu)
ret = IRQ_HANDLED;
}
dev_dbg(mtu->dev, "ep0_state: %s\n", decode_ep0_state(mtu));
mtu3_dbg_trace(mtu->dev, "ep0_state %s", decode_ep0_state(mtu));

switch (mtu->ep0_state) {
case MU3D_EP0_STATE_TX:
Expand Down
7 changes: 7 additions & 0 deletions drivers/usb/mtu3/mtu3_qmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <linux/iopoll.h>

#include "mtu3.h"
#include "mtu3_trace.h"

#define QMU_CHECKSUM_LEN 16

Expand Down Expand Up @@ -275,6 +276,7 @@ static int mtu3_prepare_tx_gpd(struct mtu3_ep *mep, struct mtu3_request *mreq)
gpd->dw0_info |= cpu_to_le32(GPD_FLAGS_IOC | GPD_FLAGS_HWO);

mreq->gpd = gpd;
trace_mtu3_prepare_gpd(mep, gpd);

return 0;
}
Expand Down Expand Up @@ -307,6 +309,7 @@ static int mtu3_prepare_rx_gpd(struct mtu3_ep *mep, struct mtu3_request *mreq)
gpd->dw0_info |= cpu_to_le32(GPD_FLAGS_IOC | GPD_FLAGS_HWO);

mreq->gpd = gpd;
trace_mtu3_prepare_gpd(mep, gpd);

return 0;
}
Expand Down Expand Up @@ -431,6 +434,7 @@ static void qmu_tx_zlp_error_handler(struct mtu3 *mtu, u8 epnum)
}

dev_dbg(mtu->dev, "%s send ZLP for req=%p\n", __func__, mreq);
trace_mtu3_zlp_exp_gpd(mep, gpd_current);

mtu3_clrbits(mbase, MU3D_EP_TXCR0(mep->epnum), TX_DMAREQEN);

Expand Down Expand Up @@ -486,6 +490,7 @@ static void qmu_done_tx(struct mtu3 *mtu, u8 epnum)

request = &mreq->request;
request->actual = GPD_DATA_LEN(mtu, le32_to_cpu(gpd->dw3_info));
trace_mtu3_complete_gpd(mep, gpd);
mtu3_req_complete(mep, request, 0);

gpd = advance_deq_gpd(ring);
Expand Down Expand Up @@ -524,6 +529,7 @@ static void qmu_done_rx(struct mtu3 *mtu, u8 epnum)
req = &mreq->request;

req->actual = GPD_DATA_LEN(mtu, le32_to_cpu(gpd->dw3_info));
trace_mtu3_complete_gpd(mep, gpd);
mtu3_req_complete(mep, req, 0);

gpd = advance_deq_gpd(ring);
Expand Down Expand Up @@ -601,6 +607,7 @@ irqreturn_t mtu3_qmu_isr(struct mtu3 *mtu)
dev_dbg(mtu->dev, "=== QMUdone[tx=%x, rx=%x] QMUexp[%x] ===\n",
(qmu_done_status & 0xFFFF), qmu_done_status >> 16,
qmu_status);
trace_mtu3_qmu_isr(qmu_done_status, qmu_status);

if (qmu_done_status)
qmu_done_isr(mtu, qmu_done_status);
Expand Down
23 changes: 23 additions & 0 deletions drivers/usb/mtu3/mtu3_trace.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: GPL-2.0
/**
* mtu3_trace.c - trace support
*
* Copyright (C) 2019 MediaTek Inc.
*
* Author: Chunfeng Yun <chunfeng.yun@mediatek.com>
*/

#define CREATE_TRACE_POINTS
#include "mtu3_trace.h"

void mtu3_dbg_trace(struct device *dev, const char *fmt, ...)
{
struct va_format vaf;
va_list args;

va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
trace_mtu3_log(dev, &vaf);
va_end(args);
}
Loading

0 comments on commit 83374e0

Please sign in to comment.