From patchwork Mon Oct 23 21:32:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 116883 Delivered-To: patches@linaro.org Received: by 10.140.22.164 with SMTP id 33csp5100885qgn; Mon, 23 Oct 2017 14:32:59 -0700 (PDT) X-Received: by 10.98.49.135 with SMTP id x129mr14303634pfx.315.1508794379595; Mon, 23 Oct 2017 14:32:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508794379; cv=none; d=google.com; s=arc-20160816; b=CzJAmtX2wTGJj5ImpDTltXEsONNgu7PmgVAWowEpa69W5100dHOpouJGduQAI48hdb QcUgRt36zXXwfAQIcPLhGZoA2789mx6sst78kVsTnU6+S1ZyJQ+us2zzPW3fmRMtOLcf r2NxUhvsGBHWpVrCCqgg9PiSTwVg3VCOKUCdC/GLm/8fjqFCpCgq+zj2Mv0gfQa+z0tz 2EIlc9MNZcVaUKAb2Xn2uXk+tXjnC/zqehFoGwM1Ihi5eayvj6fofrOEkuwI78EKCjKn muqqMmrfdFtXn45dtQC/BcxXb4YCntl8eLClf9+Hyry/H8YlLZFGLSMKzdGflMhP3opQ ElvQ== 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=loVuU1UqdmMrTK+5BAYNKFKPigJBJ6IV0x8xa9ER6WE=; b=OgAP+5IWjMbF3oOjjWsPSi7h8cnCrqClpuhBnsYeAGI+ULMEt7JuHH56mlGFuQu+qg PyYsS+/J2vQXfgn+kkL4vYs1yo1q4ihiGNDqyXoQZG9HXRJ03W5KTG1DTAkhLsnFAgIZ TP//jnt/1/U1zXEzxfkZ2vm37QwyugZLQvfDKmcj6+ScbMD5mE/Bbn+6l5ZVJ7UoS/+6 3s9P9gdrw2cxzLTCd121HDKVuOIIxz/w/6JLJqrQR7BLUUxre7Z4ALAXR05cRW2B/bPl ZeaxTnub6SulpNtKlP/lFKAd7t9keuRLvc86QsTwtvMe0Jz6vsBdia6YHN2YN73jVRGq FXZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QjZ28vYC; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 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-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id w13sor1866044pgc.93.2017.10.23.14.32.59 for (Google Transport Security); Mon, 23 Oct 2017 14:32:59 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QjZ28vYC; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 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=loVuU1UqdmMrTK+5BAYNKFKPigJBJ6IV0x8xa9ER6WE=; b=QjZ28vYCB2omMpjysctSXEzggMwso/KMRhw6S5UsyOjiSD9sWcTIO4dWpaidPZcB4V SOwWv6QlCzV6MW6kdML4/Rh8ycpMKj/I8SqDiKC0/AcLME7XIfB6y6BmhiTYx2M+Ur49 e999AKaETXddg+r3S4gFuVvFlO63j+oY2MH8M= 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=loVuU1UqdmMrTK+5BAYNKFKPigJBJ6IV0x8xa9ER6WE=; b=VvAyNDNzM1V4OQ6ahwIi9doOuPHHzhJLU1Ass8Mm0vMqOoFj9QBNYwW/YDtX9EM6VL 5/EfNyF+WG+kh55MdNkVznsmnmIQMJ1jmq+PWy0NymL8LmlbrJOM9qjJ1HxyJ3TQdi4T /h36wD/zO8QRCf8YhxnzHl1kV5Bi5bZpQVwdoItsTvfJfSd7uCZohiLPogqLpr57w4mA JMACji8IVUUeFlEdNmKBILyi/dJ4xIlqe6Ve9tkLWRqxMLVTVj/EV5wjt6uW3D8FiSXH izt6j6E6rfP0FkQmh19lO9j49Y47RnRK/LZ05I2MrpGxR5BNqj7U5wMnb0xHukUlBTyO uIlg== X-Gm-Message-State: AMCzsaV/kH9cYgq/jKswNEVkk1fbp22XEXdV6glXpGK9yBnF2QMCmaIm qjZNL5pOoFSmUqp0m9YuXxG7qmms X-Google-Smtp-Source: ABhQp+THH7eqIcGEpfGChOnr2KuECtp4xWl419OJ7S50bHgENLz8APIKO60NbBBedl08a6UZPvnKJg== X-Received: by 10.101.80.4 with SMTP id f4mr12660138pgo.432.1508794379228; Mon, 23 Oct 2017 14:32:59 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id f11sm4518766pfd.82.2017.10.23.14.32.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Oct 2017 14:32:58 -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 v2] usb: dwc2: Error out of dwc2_hsotg_ep_disable() if we're in host mode Date: Mon, 23 Oct 2017 14:32:49 -0700 Message-Id: <1508794370-29982-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508794370-29982-1-git-send-email-john.stultz@linaro.org> References: <1508794370-29982-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 previous patch in this set), 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 Tested by: Minas Harutyunyan Reported-by: YongQin Liu Signed-off-by: John Stultz --- drivers/usb/dwc2/gadget.c | 5 +++++ 1 file changed, 5 insertions(+) -- 2.7.4 Acked-by: Minas Harutyunyan Tested-by: Minas Harutyunyan 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);