Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9a8d30fc authored by Mayank Rana's avatar Mayank Rana
Browse files

dwc3: Check USB LPM status before accessing any register



USB debugfs entries can be accessed when USB session is not active or
USB is in low power mode. This results into unclocked register access.
Fix this issue by checking USB LPM status.

debugfs_create_regset32() fops related APIs are used to get USB dwc3
register dump. These fops don't have support to query device status
before accessing registers. Hence by default disabling creation of
regdump debugfs entry.

Change-Id: I67b00532eca159e000c848cb056d9759c47aefe9
Signed-off-by: default avatarMayank Rana <mrana@codeaurora.org>
parent 2a9b54e9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -850,6 +850,7 @@ struct dwc3_scratchpad_array {
 * @vbus_draw: current to be drawn from USB
 * @imod_interval: set the interrupt moderation interval in 250ns
 *			increments or 0 to disable.
 * @create_reg_debugfs: create debugfs entry to allow dwc3 register dump
 */
struct dwc3 {
	struct usb_ctrlrequest	*ctrl_req;
@@ -1046,6 +1047,7 @@ struct dwc3 {
	unsigned long		l1_remote_wakeup_cnt;

	wait_queue_head_t	wait_linkstate;
	bool			create_reg_debugfs;
};

/* -------------------------------------------------------------------------- */
+39 −4
Original line number Diff line number Diff line
@@ -368,6 +368,11 @@ static int dwc3_mode_show(struct seq_file *s, void *unused)
	unsigned long		flags;
	u32			reg;

	if (atomic_read(&dwc->in_lpm)) {
		seq_puts(s, "USB device is powered off\n");
		return 0;
	}

	spin_lock_irqsave(&dwc->lock, flags);
	reg = dwc3_readl(dwc->regs, DWC3_GCTL);
	spin_unlock_irqrestore(&dwc->lock, flags);
@@ -403,6 +408,11 @@ static ssize_t dwc3_mode_write(struct file *file,
	u32			mode = 0;
	char buf[32] = {};

	if (atomic_read(&dwc->in_lpm)) {
		dev_err(dwc->dev, "USB device is powered off\n");
		return count;
	}

	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
		return -EFAULT;

@@ -437,6 +447,12 @@ static int dwc3_testmode_show(struct seq_file *s, void *unused)
	unsigned long		flags;
	u32			reg;


	if (atomic_read(&dwc->in_lpm)) {
		seq_puts(s, "USB device is powered off\n");
		return 0;
	}

	spin_lock_irqsave(&dwc->lock, flags);
	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
	reg &= DWC3_DCTL_TSTCTRL_MASK;
@@ -483,6 +499,11 @@ static ssize_t dwc3_testmode_write(struct file *file,
	u32			testmode = 0;
	char			buf[32] = {};

	if (atomic_read(&dwc->in_lpm)) {
		seq_puts(s, "USB device is powered off\n");
		return count;
	}

	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
		return -EFAULT;

@@ -521,6 +542,11 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused)
	enum dwc3_link_state	state;
	u32			reg;

	if (atomic_read(&dwc->in_lpm)) {
		seq_puts(s, "USB device is powered off\n");
		return 0;
	}

	spin_lock_irqsave(&dwc->lock, flags);
	reg = dwc3_readl(dwc->regs, DWC3_DSTS);
	state = DWC3_DSTS_USBLNKST(reg);
@@ -590,6 +616,11 @@ static ssize_t dwc3_link_state_write(struct file *file,
	enum dwc3_link_state	state = 0;
	char			buf[32] = {};

	if (atomic_read(&dwc->in_lpm)) {
		seq_puts(s, "USB device is powered off\n");
		return count;
	}

	if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
		return -EFAULT;

@@ -1241,11 +1272,15 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
	dwc->regset->nregs = ARRAY_SIZE(dwc3_regs);
	dwc->regset->base = dwc->regs;

	file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
	if (dwc->create_reg_debugfs) {
		file = debugfs_create_regset32("regdump", 0444,
						root, dwc->regset);
		if (!file) {
			dev_dbg(dwc->dev, "Can't create debugfs regdump\n");
			ret = -ENOMEM;
			goto err1;
		}
	}

	if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
		file = debugfs_create_file("mode", S_IRUGO | S_IWUSR, root,