From patchwork Thu Aug 17 19:03:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 110342 Delivered-To: patches@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp2577033obb; Thu, 17 Aug 2017 12:03:21 -0700 (PDT) X-Received: by 10.99.101.132 with SMTP id z126mr5912584pgb.64.1502996601696; Thu, 17 Aug 2017 12:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502996601; cv=none; d=google.com; s=arc-20160816; b=l/X2XUNnI7oSsZ4fwbTK3alOhwcheKbyabQIeDcC04kO2W+JOkzpczNY4Y28fUq1/L eyuVBW5NLe+N+Z3pojXTT6T/PHQmsj4TJ2BRS6SiT4K2sM62KfksoOEucHk0sth62U/X kfJzxMQfyBxs5RSm/RC6csgES7BVw2h8ktKx7Q5d85eYR67cKlKV25C51YruO3I7rJr8 ++QEN9hECBi2jPSMiChHmr4PEc6TBF3ZFAkJzteD48yaLvZVrUH7L6/Nlr61dhekgurR WmeiSj3AbESfXwyPIA++gced5h12DXI1PHTlG0iIwiSrhstx4wtK/UQeegm0YDjpatlQ Hojg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=c29vbxC3j1E7I8DBLoD//Exs53JKsggjaCVeKmVsiKQ=; b=Fi4FLiU43OwfIiHAT3jsJndMbY+jBK4k7Bs2qSoD6MBUezj43duGgZ6wARQ9J5N5fD +0l4s1U8EAAPzCnQ2aRMXOQHPh9ezoEwRafWCpo/Iq3wLcHg66m6VewxaiWvIO8KgD3y cNZMhUpnoGRs17uy3HloWz6TFsJoHBA0F30FSOLld8YKbZ5I1h1eeKavkGiFbGmEyE6P MUuDMvNwM/Pic/nIe9LxNAXvE/iWtVYnzQ79Dxn5FyUVnbifaBK2L6447CxnCjkZ5P4y aQFX+g2mCS2YeF1qZAkKZtVDT3kFIu5SzQBxJqfL0EfDWjyJg0Qw+1YRWLjS20tV2g4O QYGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HVZaGl8d; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::236 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-x236.google.com (mail-pg0-x236.google.com. [2607:f8b0:400e:c05::236]) by mx.google.com with ESMTPS id u15si2649284plk.465.2017.08.17.12.03.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Aug 2017 12:03:21 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::236 as permitted sender) client-ip=2607:f8b0:400e:c05::236; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HVZaGl8d; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::236 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-x236.google.com with SMTP id v189so48511214pgd.2 for ; Thu, 17 Aug 2017 12:03:21 -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; bh=c29vbxC3j1E7I8DBLoD//Exs53JKsggjaCVeKmVsiKQ=; b=HVZaGl8d4LyKjgtz1XZFnCebAPaLyFBp4CTfhMFjoIB/8EhZwRNsEPJgtGHEvwLTej Ym3xD5Q1l2cxeCaZzz1gPg8CxuUSCdDFGQtHEsBd5bq4sJJNS+uStcU+uBVpDPcLSe1v 5tSv858CZPuXbqkhe5RuE4i6gsZeg6+j0K33s= 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; bh=c29vbxC3j1E7I8DBLoD//Exs53JKsggjaCVeKmVsiKQ=; b=KvBvj/TVwSjY4ti1Aso5p5ACZIFqwRdzA3Ql7vUT1pWmmtRiO3a7/m0Y0JCROcbjGW LxeFHHCBTwgLUfhNiqMrYCoOcTDrXNZIszqdKuWXOh+JcWhIHMh3bQoXolDdakC9wfta /8gacbQeQ4ugKNIYmmtu6FhXzq1ncjsdMsrgIMkvD+9HXyKUHxUE71AYx/SQZXmQZXvv IoFUkzRjwKZ5WfFhjA/ZB9Fgo1wiYK0nqLWIeCIQzRyk0RfJrI9RtB0IQWGae0ilZmq0 8xQ7JG/Istb4GwcIIsi7JJ6U3ibzYms9VwURk+OjhaxfIm4byoGU/RMyvRsvPMAdr0ZH 4CmQ== X-Gm-Message-State: AHYfb5iOdFmj+yV7/bwLXRDBlOVwvBT/lQ+TRLxPZhjZTO0R6WhpUEgY 86n8OW4HVbQKFdzYDu4= X-Received: by 10.99.107.72 with SMTP id g69mr6072874pgc.85.1502996601275; Thu, 17 Aug 2017 12:03:21 -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.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Aug 2017 12:03:19 -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 1/3] usb: dwc2: Improve gadget state disconnection handling Date: Thu, 17 Aug 2017 12:03:13 -0700 Message-Id: <1502996595-15316-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In the earlier commit dad3f793f20f ("usb: dwc2: Make sure we disconnect the gadget state"), I was trying to fix up the fact that we somehow weren't disconnecting the gadget state, so that when the OTG port was plugged in the second time we would get warnings about the state tracking being wrong. The fix there was somewhat simple, as it just made sure to call dwc2_hsotg_disconnect() before we connected things up in OTG mode. But in looking at a different issue I was seeing with UDC state handling, I realized that it would be much better to call dwc2_hsotg_disconnect when we get the state change signal moving to host mode. Thus, this patch removes the earlier disconnect call I added and moves it (and the needed locking) to the host mode transition. 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 Signed-off-by: John Stultz --- drivers/usb/dwc2/hcd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index 740c7e8..9fd84a9 100644 --- a/drivers/usb/dwc2/hcd.c +++ b/drivers/usb/dwc2/hcd.c @@ -3277,7 +3277,6 @@ static void dwc2_conn_id_status_change(struct work_struct *work) dwc2_core_init(hsotg, false); dwc2_enable_global_interrupts(hsotg); spin_lock_irqsave(&hsotg->lock, flags); - dwc2_hsotg_disconnect(hsotg); dwc2_hsotg_core_init_disconnected(hsotg, false); spin_unlock_irqrestore(&hsotg->lock, flags); dwc2_hsotg_core_connect(hsotg); @@ -3296,8 +3295,13 @@ static void dwc2_conn_id_status_change(struct work_struct *work) if (count > 250) dev_err(hsotg->dev, "Connection id status change timed out\n"); - hsotg->op_state = OTG_STATE_A_HOST; + spin_lock_irqsave(&hsotg->lock, flags); + dwc2_hsotg_disconnect(hsotg); + dwc2_hsotg_core_init_disconnected(hsotg, false); + spin_unlock_irqrestore(&hsotg->lock, flags); + + hsotg->op_state = OTG_STATE_A_HOST; /* Initialize the Core for Host mode */ dwc2_core_init(hsotg, false); dwc2_enable_global_interrupts(hsotg); From patchwork Thu Aug 17 19:03:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 110343 Delivered-To: patches@linaro.org Received: by 10.182.109.195 with SMTP id hu3csp2577084obb; Thu, 17 Aug 2017 12:03:24 -0700 (PDT) X-Received: by 10.84.229.136 with SMTP id c8mr7154551plk.351.1502996603969; Thu, 17 Aug 2017 12:03:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502996603; cv=none; d=google.com; s=arc-20160816; b=cpAlHzpnhjTJA+URDTPvGTuvStUwnogIExfk79mJLwqolvoh2XBeeHAG/adbO6l3Zm Mt75/HlxKVKeQ7Q7+MFq2MiuWvIheKiYPPvg5W3ukDsMe62Ct86Zxn4GJ17ARzJqt0GX MJCLv6RIWDmgFC6kc5KuhzRD+iQx+G7GyJDWUDEEKnTcVZlQisLphM/OylTJh58biqNW xkAraz2Xu1EvOVX3hphU6V1vptkbOLHhbMpDRgHFsxDAL942LFrIk1lJVnxw0RvPoVK3 kRB+8AX4LR1y5ICnJsibOLDI1XusOfyxkTtletvKXyQnEPys3A4UVO08hInRNS1FPFaU 2ALg== 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=MOYhtf8xm7G+kwlTTcgfr6EYFQuSq3W+p/U+sLVvR8I=; b=sy1qIb1TTu8iirEmXcozKksJEXjHqU5IyC4eETXlSaae1p2tmDNqWTEc1sbEQiWPYz yuHmX+C3D+/+hI0pCtq129JKPeTrze/7NVd2MVco3Xqhoi/flJ/szuN4j93ft5aKx3xM LCCmak61m76w+Ck6mX+H+4CPAykMIrZg8PIKyrEEM3grF80o0F+hH8e9AgjD7tveIoG4 Yfx3UxzpwePdgW99KYgriAeIKz74pPtbSNS4REiPKTVeVwFlymNeyoRK0cu3RDt2rB3F x6W+jtssNUwpTZG09Ps0QREU5UStrOXiFrPpzl/YSFbQo3hlqSAwrrzQhWcNCoJZBRXX Mehg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F0wGwkxx; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::236 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-x236.google.com (mail-pg0-x236.google.com. [2607:f8b0:400e:c05::236]) by mx.google.com with ESMTPS id p22si2640658pli.1022.2017.08.17.12.03.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Aug 2017 12:03:23 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::236 as permitted sender) client-ip=2607:f8b0:400e:c05::236; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F0wGwkxx; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c05::236 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-x236.google.com with SMTP id i12so48663995pgr.3 for ; Thu, 17 Aug 2017 12:03:23 -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=MOYhtf8xm7G+kwlTTcgfr6EYFQuSq3W+p/U+sLVvR8I=; b=F0wGwkxxsiXvTpb1RO/uX6ZRTYeaM/3eTaKdW0iAUIyIBBWGzJC3Sx7sYz+eKbRgim o7+nTStcesuE4Re+pbFHr2K5x96Rbi0VpBfzUXQtky3h3RL7PEK8EFo88WRS1c53cyIY gC/caz4IrO5ofL7JlL5ipu9MuPvkyJnER9WU0= 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=MOYhtf8xm7G+kwlTTcgfr6EYFQuSq3W+p/U+sLVvR8I=; b=RL8/SDeoIEkKeNPMKHkoY16szANOawJ7Z2Eo7RoKDW7q6VZxhWa0i/QkkfCrZKh84g 7OVRTtNFEfB6xzuJa87qavwjlZGvvkACJXWLX7AO1gvt2vN9go+lpzpzCVZCuROzE0JM cEBVtGqglAolFRPbAB4xwNEq6gIu/OJq0NTswT1ALh9ZRryb4ixuad+NGJU7VwKW4N7h 0uCaoHzf1bfJixJ4HI5/qHeJf4B3n2n4LdDTaGnQH8NrXdOcKhjM2BT2y1C0ZlM1N1kH Cl8psnZgC7akclLURiAsXfhDrXywyuJeijtzuBH4KbxcF9R3rTK6XTAxAoAtP316OTiT ofXA== X-Gm-Message-State: AHYfb5hcQglONTENyC8EMNI/nnb4Ydu8rfZqvqIe3wUgrbOfFjz2TAzM XYzfVuqHfJzLceghh7c= X-Received: by 10.99.4.9 with SMTP id 9mr3002473pge.70.1502996603671; Thu, 17 Aug 2017 12:03:23 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Aug 2017 12:03:22 -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 2/3] usb: dwc2: Fix UDC state tracking Date: Thu, 17 Aug 2017 12:03:14 -0700 Message-Id: <1502996595-15316-2-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> It has been noticed that the dwc2 udc state reporting doesn't seem to work (at least on HiKey boards). Where after the initial setup, the sysfs /sys/class/udc/f72c0000.usb/state file would report "configured" no matter the state of the OTG port. This patch adds a call so that we report to the UDC layer when the gadget device is disconnected. 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: Amit Pundir Signed-off-by: John Stultz --- drivers/usb/dwc2/gadget.c | 2 ++ 1 file changed, 2 insertions(+) -- 2.7.4 diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index c4066cd..e6f2cd8 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -3202,6 +3202,8 @@ void dwc2_hsotg_disconnect(struct dwc2_hsotg *hsotg) call_gadget(hsotg, disconnect); hsotg->lx_state = DWC2_L3; + + usb_gadget_set_state(&hsotg->gadget, USB_STATE_NOTATTACHED); } /** 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);