From patchwork Thu Aug 17 19:03:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 110344 Delivered-To: patches@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp2577128obb; Thu, 17 Aug 2017 12:03:25 -0700 (PDT) X-Received: by 10.99.134.194 with SMTP id x185mr5912107pgd.210.1502996605863; Thu, 17 Aug 2017 12:03:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502996605; cv=none; d=google.com; s=arc-20160816; b=FNyY4ZothbqB7yr7K4t3wynyjc9gSmnskrJ5Y9RZM+Cf18bno0nAHgPfT3o7rM8PQR YgiJKPTkgIq+inoJP0Zh8bKp4iJPBMeymkI4imCguuKufvzLBG9+Vpo49NLbx/jM9/2M ZUCbs09EyCZtKjt5xLDnngipmaBEiztNcgHIUZcuPeuhAwU2EzR43e2iqicRDgSBh7dS x+czk2afUoNR5QBT3Wh8+YJdXfR8tnXzvzKVW/ibnTRCbcmXYZlvH9q5jY8+q0IkTXEn MONvLyKN5JHZGOADFV75Y9m731SFvjEnrVMcI2vROybpE7PWmPyxbXHNs4RCqf3oMIj2 nMSg== 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=Cn9DY80BJLmBMEEmZPwDQnwIevnpLmI2VuaEnuaplTo=; b=heJSeI++a3c5RCpGcc9HeTuw9FK3RCEBld8pXAOLMma2muAei0uA+lkJ9Ui6gFzicb m4E1DE8zhr7kmY6qScXTq7mjlJbIBQapVC2GL1GLJll5zamJfvrv8Yy4HDyDnHzw7neF cGTXi4tVZwDDHYGGqIuIuAuOkBypDub8Ot12u2GIqjulwCPhie0wyRCp7/ymNPiOyN0i G85YdCurzgxxy+w9FQru2WIn/Y2gsdoYrqRVI8ObgnYlB43wgoNM6DaULVaBeAssA7ay F250d5O0wM5HXq7wCtruS4CMq99lQeCzGOYc8qrKLbKjdtR1hlljaNFYTMtT95g9GUSh v7JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dQFrTCJG; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22c 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-pg0-x22c.google.com (mail-pg0-x22c.google.com. [2607:f8b0:400e:c05::22c]) by mx.google.com with ESMTPS id o128si2459180pfo.226.2017.08.17.12.03.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Aug 2017 12:03:25 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22c as permitted sender) client-ip=2607:f8b0:400e:c05::22c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dQFrTCJG; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::22c as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pg0-x22c.google.com with SMTP id v189so48512309pgd.2 for ; Thu, 17 Aug 2017 12:03:25 -0700 (PDT) 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=Cn9DY80BJLmBMEEmZPwDQnwIevnpLmI2VuaEnuaplTo=; b=dQFrTCJG0lKNk1YsUcxXAvYLtkbAYZ93el5ZhgdaJ4XfocRJwArsaVMN54QSue71WW TbcHLwfCFX7kfp5EkAIyVY254rKO02wR/nY0KWBp8As5/ojFilFukh8sA+wl+B5W38FV L+ANqXvEWbNPEzxTGYtzRy3U7PHtXHVFcBVv4= 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=Cn9DY80BJLmBMEEmZPwDQnwIevnpLmI2VuaEnuaplTo=; b=a6wIMJDPGb/rv9Csa6Q1dcxm+mP/80RlMMosgzjZMeu4jhY7T0CYsKcBfyZrUq0imZ oD5bL9o0hOMnNabbTNJyxaLi1DXfzET3AyZgSMlnMxpRzKSzoR6bBHqGymBakMjrpcPx FpYfX0V3CMagg25alk40CbaY/ASQ3lke5nSB67AEooBgaZQLoy8Skeck8f0PI2twTfx1 j6k1RaA9ug0YNg90PKCibuEezpAW68FuW3wGnPjJIgqRo28jtNtEFT3c7xhFdliPeWBA 7+oRL1bWoUeSxKPbrnytUqjWad2CnfeMBEYcNIGWFb4i0dthYZzafgvPMUbvmbQlQsO6 QYdA== X-Gm-Message-State: AHYfb5g9Ad9c2Prve+q7PnykGAZtc7Fif+uGiKd6NbqQPyYUjpb7nSqX zHCPpizy0zyyUdhyvlw= X-Received: by 10.84.176.195 with SMTP id v61mr6753025plb.271.1502996605515; Thu, 17 Aug 2017 12:03:25 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id r86sm9337806pfi.161.2017.08.17.12.03.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Aug 2017 12:03:24 -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: [PATCH 3/3] usb: dwc2: Error out of dwc2_hsotg_ep_disable() if we're in host mode Date: Thu, 17 Aug 2017 12:03:15 -0700 Message-Id: <1502996595-15316-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502996595-15316-1-git-send-email-john.stultz@linaro.org> References: <1502996595-15316-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 e6f2cd8..61fb76f 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -4006,6 +4006,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);