From patchwork Wed Sep 20 19:57:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 113171 Delivered-To: patches@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1171356qgf; Wed, 20 Sep 2017 12:57:35 -0700 (PDT) X-Received: by 10.98.201.21 with SMTP id k21mr3290725pfg.262.1505937455609; Wed, 20 Sep 2017 12:57:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505937455; cv=none; d=google.com; s=arc-20160816; b=Wss3NbBqkhbv2eORs7cjzrHxfPW+qFCnik9cm56Amhv8g0igb9Gx+tjXTqdAAvRdAE yaOwE9eNRH35y+vOuEBYw+QAoU76T9E4PaL8MAhlovXUtj5fr6UpEMr0OEDHayUMOC16 helq7dbI3AAkn0bGRrpaSedng5vgt8mOQisQvFBi9AJbPLnOMsQniXsMu3/WDFw5zhxH yqPl0X+tM3VW9AspYC3/UD9NdYr5nkeSv7XHfus/ctyQf6HfjjgY3qz9H1jEaftNaWCR b17czAn3VUj2Qt2tEBUm+sypP7Terffj/zesr41zt84FOPmee74w1WP/Gwxu0G+uh4pM L80Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=QMQJfVjGhCqQeebsMU/4Yes5HlBi27BS34HjyHfo2gM=; b=LPI3szkAcZBDQZz3bykwIN622opm+0cMW2LKhiUQllRKiE77HHEYO+WNeMZmRuos4h pik2LsVAP4X4UseG40CyKwPnZdRWq1oVOdYCWggmiMyp2v0wN0WMH/oDGtK//s64r1EN Dwy00dnzJeo+ykqgbv31mqfvINn+AXZ74A3ojvSRdPT0DeFy4SjkistRKLYMcOvDBWsr fDTAROoXlAb3SGirMxpCr6hJ9axQnm8O60UV/1JbBkxlM0VdXp64JUeqwexHfyharyck mDqnFx9gV7PNrhjfOdvUtUNFpGm6JlurLNRrrIv1FBhHsXT52lLE3K4e435oLdWd4HPZ 9zJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RS7fAyNF; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 3sor1392929plz.67.2017.09.20.12.57.35 for (Google Transport Security); Wed, 20 Sep 2017 12:57:35 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RS7fAyNF; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QMQJfVjGhCqQeebsMU/4Yes5HlBi27BS34HjyHfo2gM=; b=RS7fAyNF5QKc9W0BeJmyQSlvEThJg/0vtILReTOhR7rasucTjZKhDeLWkht19QL4Gc D3MJPmpMG4Cpm8fQf5j7DWjCg56GIxwE5CRtCIhOm80wv721POn84A4d0+yFMVjbOP6L 8/rAzZ2yTRmBt2fpn8pStJZ/vm7H+HM5kiMII= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QMQJfVjGhCqQeebsMU/4Yes5HlBi27BS34HjyHfo2gM=; b=kqx53jg1t7S5yzN5YVA/a3fmlydoKTr1HeCpSG/dpcdDYB5jueBH8wnsU3VLJVroWX yQZAVDugVddJuJg/1EE6ww2xj0qQVdtD719pdyOlmtTzaT7TvpseqDivyukdvza8HGLz jvFjljjtNmmfmVhCt1a/KtYzGRrEDnyu64Bv3xtrvOeERSZ5ML1ngC5hHisZe/GVM9L4 6tj0BH6o1qM9TauaOHQm8gdrCthoH20BmCQ4Fo4NzwWPLBZoEPypHfmRRlNgHVfxMsKG Du/CgcWYQ12pcP9iCjlASWEqqSXxU5XuBJXyVt+DdVTYjmkpFUxFcMaqO9RjhRm250wG sD/w== X-Gm-Message-State: AHPjjUjIA0xWqcFpEqrThxU8LBfo/7BYsZraEkmHT1VmV45wkQZGXFPL C1i+e0wM3F71jsub6kbOweuaAyKA X-Google-Smtp-Source: AOwi7QAz8K2an9ZWAyrHHHTv3t2UvW+6MHweCrHkhA+fkeiOWjYqpUAv3klObLZJkRkOrw/i0N3UKw== X-Received: by 10.84.177.129 with SMTP id x1mr3206601plb.161.1505937455277; Wed, 20 Sep 2017 12:57:35 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id i2sm9991660pfd.21.2017.09.20.12.57.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 20 Sep 2017 12:57:34 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Wei Xu , Guodong Xu , Amit Pundir , YongQin Liu , John Youn , Minas Harutyunyan , Douglas Anderson , Chen Yu , Felipe Balbi , Greg Kroah-Hartman , linux-usb@vger.kernel.org Subject: [RESEND x2][PATCH 2/3] usb: dwc2: Error out of dwc2_hsotg_ep_disable() if we're in host mode Date: Wed, 20 Sep 2017 12:57:27 -0700 Message-Id: <1505937448-13475-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505937448-13475-1-git-send-email-john.stultz@linaro.org> References: <1505937448-13475-1-git-send-email-john.stultz@linaro.org> We've found that while in host mode, using Android, if one runs the command: stop adbd The existing usb devices being utilized in host mode are disconnected. This is most visible with usb networking devices. This seems to be due to adbd closing the file: /dev/usb-ffs/adb/ep0 Which calls ffs_ep0_release() and the following backtrace: [] dwc2_hsotg_ep_disable+0x148/0x150 [] dwc2_hsotg_udc_stop+0x60/0x110 [] usb_gadget_remove_driver+0x58/0x78 [] usb_gadget_unregister_driver+0x74/0xe8 [] unregister_gadget+0x28/0x58 [] unregister_gadget_item+0x2c/0x40 [] ffs_data_clear+0xe8/0xf8 [] ffs_data_reset+0x20/0x58 [] ffs_data_closed+0x98/0xe8 [] ffs_ep0_release+0x20/0x30 Then when dwc2_hsotg_ep_disable() is called, we call kill_all_requests() which causes a bunch of the following messages: dwc2 f72c0000.usb: Mode Mismatch Interrupt: currently in Host mode dwc2 f72c0000.usb: Mode Mismatch Interrupt: currently in Host mode dwc2 f72c0000.usb: Mode Mismatch Interrupt: currently in Host mode dwc2 f72c0000.usb: Mode Mismatch Interrupt: currently in Host mode dwc2 f72c0000.usb: Mode Mismatch Interrupt: currently in Host mode dwc2 f72c0000.usb: Mode Mismatch Interrupt: currently in Host mode dwc2 f72c0000.usb: Mode Mismatch Interrupt: currently in Host mode dwc2 f72c0000.usb: Mode Mismatch Interrupt: currently in Host mode init: Service 'adbd' (pid 1915) killed by signal 9 init: Sending signal 9 to service 'adbd' (pid 1915) process group... init: Successfully killed process cgroup uid 0 pid 1915 in 0ms init: processing action (init.svc.adbd=stopped) from (/init.usb.configfs.rc:15) dwc2 f72c0000.usb: dwc2_hc_chhltd_intr_dma: Channel 8 - ChHltd set, but reason is unknown dwc2 f72c0000.usb: hcint 0x00000002, intsts 0x04200029 dwc2 f72c0000.usb: dwc2_hc_chhltd_intr_dma: Channel 12 - ChHltd set, but reason is unknown dwc2 f72c0000.usb: hcint 0x00000002, intsts 0x04200029 dwc2 f72c0000.usb: dwc2_hc_chhltd_intr_dma: Channel 15 - ChHltd set, but reason is unknown dwc2 f72c0000.usb: hcint 0x00000002, intsts 0x04200029 dwc2 f72c0000.usb: dwc2_hc_chhltd_intr_dma: Channel 3 - ChHltd set, but reason is unknown dwc2 f72c0000.usb: hcint 0x00000002, intsts 0x04200029 dwc2 f72c0000.usb: dwc2_hc_chhltd_intr_dma: Channel 4 - ChHltd set, but reason is unknown dwc2 f72c0000.usb: hcint 0x00000002, intsts 0x04200029 dwc2 f72c0000.usb: dwc2_update_urb_state_abn(): trimming xfer length And the usb devices connected are basically hung at this point. It seems like if we're in host mode, we probably shouldn't run the dwc2_hostg_ep_disable logic, so this patch returns an error in that case. With this patch (along with the two previous patches mailed out earlier: https://lkml.org/lkml/2017/8/3/1008 https://lkml.org/lkml/2017/8/3/1010 ), we avoid the mismatched interrupts and connected usb devices continue to function. I'm not sure if some other solution would be better here, but this seems to work, so I wanted to send it out for input on what the right approach should be. Cc: Wei Xu Cc: Guodong Xu Cc: Amit Pundir Cc: YongQin Liu Cc: John Youn Cc: Minas Harutyunyan Cc: Douglas Anderson Cc: Chen Yu Cc: Felipe Balbi Cc: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org Reported-by: YongQin Liu Signed-off-by: John Stultz --- drivers/usb/dwc2/gadget.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.7.4 diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 0d8e09c..7fd0e38 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -4004,6 +4004,11 @@ static int dwc2_hsotg_ep_disable(struct usb_ep *ep) return -EINVAL; } + if (hsotg->op_state != OTG_STATE_B_PERIPHERAL) { + dev_err(hsotg->dev, "%s: called in host mode?\n", __func__); + return -EINVAL; + } + epctrl_reg = dir_in ? DIEPCTL(index) : DOEPCTL(index); spin_lock_irqsave(&hsotg->lock, flags);