Re: [PATCH] usb: chipidea: udc: avoid gadget driver insertion in host mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/08/2014 04:46 AM, Peter Chen wrote:
On Sun, Jul 06, 2014 at 11:31:00PM +0500, Abbas Raza wrote:
On 07/06/2014 03:38 PM, Peter Chen wrote:
On Fri, Jul 04, 2014 at 05:40:59PM +0500, Abbas Raza wrote:
From: Abbas Raza <Abbas_Raza@xxxxxxxxxx>

When gadget driver is inserted and OTG is in host mode, interrupts
occur which are not handled by chipidea driver causing following
problem. To avoid this problem, don't allow insertion of gadget
driver in host mode.

root@mx6q:~# echo -n host > /sys/kernel/debug/ci_hdrc.0/role
root@mx6q:~# modprobe g_ether
using random self ethernet address
using random host ethernet address
usb0: HOST MAC aa:4b:f8:b4:d7:81
usb0: MAC 5e:65:a8:9e:6e:45
using random self ethernet address
using random host ethernet address
g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
g_ether gadget: g_ether ready
root@mx6q35:~# irq 75: nobody cared (try booting with the "irqpoll" option)
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.16.0-rc2-00001-gd675913 #53
Backtrace:
[<80012418>] (dump_backtrace) from [<800126fc>] (show_stack+0x18/0x1c)
  r6:8092bae0 r5:8092bae0 r4:00000000 r3:00000000
[<800126e4>] (show_stack) from [<806770bc>] (dump_stack+0x8c/0xa4)
[<80677030>] (dump_stack) from [<80074520>] (__report_bad_irq+0x28/0xc8)
  r6:0000004b r5:00000000 r4:be00ab00 r3:00000000
[<800744f8>] (__report_bad_irq) from [<80074ae8>] (note_interrupt+0x264/0x2c4)
  r6:0000004b r5:00000000 r4:be00ab00 r3:00000000
[<80074884>] (note_interrupt) from [<80072400>] (handle_irq_event_percpu+0xb4/0x13c)
  r10:80969dc6 r9:be00ab00 r8:0000004b r7:00000000 r6:00000000 r5:00000000
  r4:00000000 r3:00000000
[<8007234c>] (handle_irq_event_percpu) from [<800724cc>] (handle_irq_event+0x44/0x64)
  r10:00000000 r9:806816b0 r8:80907f20 r7:0000004b r6:bd882c40 r5:be00ab5c
  r4:be00ab00
[<80072488>] (handle_irq_event) from [<800758b8>] (handle_fasteoi_irq+0xc8/0x1bc)
  r6:8092bd64 r5:be00ab5c r4:be00ab00 r3:00000000
[<800757f0>] (handle_fasteoi_irq) from [<80071b14>] (generic_handle_irq+0x30/0x44)
  r6:80906020 r5:80902e2c r4:0000004b r3:800757f0
[<80071ae4>] (generic_handle_irq) from [<8000f3d8>] (handle_IRQ+0x54/0xbc)
  r4:8090ed2c r3:00000180
[<8000f384>] (handle_IRQ) from [<800086cc>] (gic_handle_irq+0x30/0x68)
  r8:00000000 r7:f4000100 r6:80907e28 r5:8090eea0 r4:f400010c r3:000000a0
[<8000869c>] (gic_handle_irq) from [<80013264>] (__irq_svc+0x44/0x5c)
Exception stack(0x80907e28 to 0x80907e70)
7e20:                   00000001 00000000 00000000 80911f70 00000282 80906000
7e40: 8002eec4 0000001d 00000000 806816b0 00000000 80907ebc 00000000 80907e70
7e60: 800663c4 8002e9bc 60000113 ffffffff
  r7:80907e5c r6:ffffffff r5:60000113 r4:8002e9bc
[<8002e8f4>] (__do_softirq) from [<8002eec4>] (irq_exit+0xb8/0x10c)
  r10:00000000 r9:806816b0 r8:00000000 r7:0000001d r6:80906000 r5:80902e2c
  r4:80906000
[<8002ee0c>] (irq_exit) from [<8000f3e0>] (handle_IRQ+0x5c/0xbc)
  r5:80902e2c r4:8090ed2c
[<8000f384>] (handle_IRQ) from [<800086cc>] (gic_handle_irq+0x30/0x68)
  r8:80969dc3 r7:f4000100 r6:80907f20 r5:8090eea0 r4:f400010c r3:000000a0
[<8000869c>] (gic_handle_irq) from [<80013264>] (__irq_svc+0x44/0x5c)
Exception stack(0x80907f20 to 0x80907f68)
7f20: 00000001 00000001 00000000 80911f70 80906000 8090e98c 8090e938 80969dc3
7f40: 80969dc3 806816b0 00000000 80907f74 00000000 80907f68 8006640c 8000f754
7f60: 20000013 ffffffff
  r7:80907f54 r6:ffffffff r5:20000013 r4:8000f754
[<8000f72c>] (arch_cpu_idle) from [<80061c7c>] (cpu_startup_entry+0x104/0x16c)
[<80061b78>] (cpu_startup_entry) from [<80672258>] (rest_init+0xb0/0xd8)
  r7:808f4c00 r3:00000000
[<806721a8>] (rest_init) from [<808b2bec>] (start_kernel+0x33c/0x3a8)
  r5:8096a000 r4:8090ea30
[<808b28b0>] (start_kernel) from [<10008074>] (0x10008074)
handlers:
[<804456a8>] ci_irq
Disabling IRQ #75
usb 2-1: new high-speed USB device number 2 using ci_hdrc
usb 2-1: device descriptor read/64, error -110
usb 2-1: device descriptor read/64, error -110
usb 2-1: new high-speed USB device number 3 using ci_hdrc
usb 2-1: device descriptor read/64, error -110
usb 2-1: device descriptor read/64, error -110
usb 2-1: new high-speed USB device number 4 using ci_hdrc
usb 2-1: device not accepting address 4, error -110
usb 2-1: new high-speed USB device number 5 using ci_hdrc
usb 2-1: device not accepting address 5, error -110
usb usb2-port1: unable to enumerate USB device
usb 2-1: new full-speed USB device number 6 using ci_hdrc
usb 2-1: device descriptor read/64, error -110
usb 2-1: device descriptor read/64, error -110
usb 2-1: new full-speed USB device number 7 using ci_hdrc
usb 2-1: device descriptor read/64, error -110
usb 2-1: device descriptor read/64, error -110
usb 2-1: new full-speed USB device number 8 using ci_hdrc
usb 2-1: device not accepting address 8, error -110
usb usb2-port1: cannot reset (err = -32)
usb usb2-port1: cannot reset (err = -32)
usb usb2-port1: cannot reset (err = -32)
usb usb2-port1: cannot reset (err = -32)
usb usb2-port1: cannot reset (err = -32)
usb usb2-port1: Cannot enable. Maybe the USB cable is bad?
usb usb2-port1: unable to enumerate USB device

Signed-off-by: Abbas Raza <Abbas_Raza@xxxxxxxxxx>
---
  drivers/usb/chipidea/udc.c | 6 ++++++
  1 file changed, 6 insertions(+)

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 69425b3..7a12d13 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1633,6 +1633,12 @@ static int ci_udc_start(struct usb_gadget *gadget,
  	unsigned long flags;
  	int retval = -ENOMEM;
+	if (ci->role == CI_ROLE_HOST) {
+		dev_err(ci->dev, "error: cannot register gadget driver in host"
+								 "mode\n");
+		return -EPERM;
+	}
+
  	if (driver->disconnect == NULL)
  		return -EINVAL;
--
1.8.3.2

Hi Abbas, I can't reproduce it no matter current role is host or
peripheral with GregKH's latest usb next.

The reason for it : the controller switches to device mode when it is
working at host mode, have a check for ci->vbus_active please (at ci_udc_start),
it should not be true when load usb gadget driver at host mode.

Hi Peter,

Actually the steps to reproduce (can be see below) it are not
straight forward but some user can run these steps and get into
issues. Please have a look.

Steps to reproduce this issue:
1) boot target (imx6 board) which is connected to a usb host using
OTG cable. Target's OTG port will be in gadget mode after boot.
2) now switch OTG role to host
3) modprobe g_ether
4) you will see the backtrace (unhandled interrupts)
Thanks, Abbas.

But we do need to support load gadget driver when we at host mode,
assume it is at host mode during boots up, and the initialization script
will load gadget driver, if it fails to load, the gadget can't work
when the user switch ID cable to Micro-B cable which is connected to pc.

The support for switching role through /sys entry is not well
for current chipidea driver, the well supported are:
- role switch through id pin (the connection is not there)
- role switch through otg fsm  (the connection is there)

Right.

I will try to add solution for switching role without depending on
id pin (through /sys entry) for non otg fsm solution.

What do you mean by 'switching role without depending on id pin'? I think this is already supported
because /sys/kernel/debug/ci_hdrc.0/role file switches role without caring about the id pin status.
Or do you want to add an option to disable id pin based role switching? Please clarify

Thanks .
Abbas Raza

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux