Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1837229ybl; Thu, 19 Dec 2019 03:56:53 -0800 (PST) X-Google-Smtp-Source: APXvYqz5TIxtYacuZaMycpaArKEtvGdj3eTQq073u1smG6s3IqW9j8/HVF4umiLzWKSjQJoQccpr X-Received: by 2002:a9d:6b06:: with SMTP id g6mr8411176otp.93.1576756613205; Thu, 19 Dec 2019 03:56:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576756613; cv=none; d=google.com; s=arc-20160816; b=Kmxp3nK1AURm0hcbMR6/hSYqr6YIhfDAtVl8uWOm7EsnzKfvQxYwx28D58fiCd1th3 jS1+4egCaNqbsSLMzu1t4sSjkini06ZiIt3yWrUdkLjIGpPvf3gSORUeMUXN0JzD5ZaN OVLCXmTjpR88m6Gl/I2r06jMH2rBFo73fqZPU32kbvQ+mySB6T9yXOntj+BYdY5RKcOY kq6zzdedqbT4VBApF8t5rjFDIrxtDUn8FMMrmPthVFowsJ3zvmlX42y4xE6T1dp6q0a5 VCJflYWR12LvrQ5Yrrlu6LUkyLDo6nI5SrQoAFoJvTrbrGIXXJ6pwrTlmnmMklcZ40bC x7iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=UdeCVyht8cwXu07Ro0l/4x8RkihoZZOLJTRxBmSNRro=; b=VgqlYJsrkm4yK3tQOoallJqi/hwZ8PeuOED0Ct6nHeW0P7e+AMqzeDTzscvy11oJDD NfPkM6tzK8wdOK93Z6oMBf+elyIoAjNnHgezhk0jO058LorGoCZ5V6SeRphUV7AXAHfT VYv4t4nSYEr3pmzEGzL8F2zd7VptKnGIRk6QD/yX6bprxj1c94quvT1bZ51EAzUp/cxA HVfHKzaBA+6VOYvb0jjIDpBXeK8jIxrjhDkO3Q67NINBT5vRm5FNSIRllgHc8PIDryFf ghSrIJWnxoNMUmoCKXtfnjD94S5UKXRFXtortFdWWmKiInMA45D2/63/oCuaGO4vn8HB e7xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@metanate.com header.s=stronger header.b=wACAMuy2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=metanate.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r14si2754446oic.12.2019.12.19.03.56.40; Thu, 19 Dec 2019 03:56:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@metanate.com header.s=stronger header.b=wACAMuy2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=metanate.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726960AbfLSLyh (ORCPT + 99 others); Thu, 19 Dec 2019 06:54:37 -0500 Received: from dougal.metanate.com ([90.155.101.14]:54058 "EHLO metanate.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726877AbfLSLyc (ORCPT ); Thu, 19 Dec 2019 06:54:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=simple/simple; d=metanate.com; s=stronger; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject :Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=tmKdpt8FfuaV6nRnJAttHNQVsa8S40+mibR855aHQJg=; b=wACAMuy2aD0a0GYTT1d2De4df5 Osp+Jt0hP6KqVmVaP4NXmXxS2prRPv5FjUW8XIudomRk3VnUCQBbpXyPbFQ0kkRNrxVnjTqwpOsGj oUY5SoF3GZ05cXNgDxNhpVSFanqqcroaox+vRe0JFXequ5RRDnm5nun2VViGeOHXXyShM6uD9erSI jXtWi2fPTtVooOUmTtXLaI/Y88p+GxN9lz7HSQOLmy9ykBdtC6Cr3dSTtv8ribR4ifiLkCWJe/Ead +lIjqdjyybE0XhlRRLRwiQTpuOkd0Xf8sEopsR0K/GRH6DlG4lmSq7haV+BoxWTIVlrf/hIjLLSO6 2ws5Curw==; Received: from 188-39-28-98.static.enta.net ([188.39.28.98] helo=donbot.metanate.com) by email.metanate.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1ihu4j-00024T-UX; Thu, 19 Dec 2019 11:34:38 +0000 From: John Keeping To: Minas Harutyunyan Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, John Keeping Subject: [PATCH 1/2] usb: dwc2: Fix IN FIFO allocation Date: Thu, 19 Dec 2019 11:34:31 +0000 Message-Id: <20191219113432.1229852-1-john@metanate.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Authenticated: YES Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On chips with fewer FIFOs than endpoints (for example RK3288 which has 9 endpoints, but only 6 which are cabable of input), the DPTXFSIZN registers above the FIFO count may return invalid values. With logging added on startup, I see: dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=1 sz=256 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=2 sz=128 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=3 sz=128 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=4 sz=64 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=5 sz=64 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=6 sz=32 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=7 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=8 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=9 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=10 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=11 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=12 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=13 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=14 sz=0 dwc2 ff580000.usb: dwc2_hsotg_init_fifo: ep=15 sz=0 but: # cat /sys/kernel/debug/ff580000.usb/fifo Non-periodic FIFOs: RXFIFO: Size 275 NPTXFIFO: Size 16, Start 0x00000113 Periodic TXFIFOs: DPTXFIFO 1: Size 256, Start 0x00000123 DPTXFIFO 2: Size 128, Start 0x00000223 DPTXFIFO 3: Size 128, Start 0x000002a3 DPTXFIFO 4: Size 64, Start 0x00000323 DPTXFIFO 5: Size 64, Start 0x00000363 DPTXFIFO 6: Size 32, Start 0x000003a3 DPTXFIFO 7: Size 0, Start 0x000003e3 DPTXFIFO 8: Size 0, Start 0x000003a3 DPTXFIFO 9: Size 256, Start 0x00000123 so it seems that FIFO 9 is mirroring FIFO 1. Fix the allocation by using the FIFO count instead of the endpoint count when selecting a FIFO for an endpoint. Signed-off-by: John Keeping --- drivers/usb/dwc2/gadget.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index 92e8de9cb45c..911b950ef25e 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -4059,11 +4059,12 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep, * a unique tx-fifo even if it is non-periodic. */ if (dir_in && hsotg->dedicated_fifos) { + unsigned fifo_count = dwc2_hsotg_tx_fifo_count(hsotg); u32 fifo_index = 0; u32 fifo_size = UINT_MAX; size = hs_ep->ep.maxpacket * hs_ep->mc; - for (i = 1; i < hsotg->num_of_eps; ++i) { + for (i = 1; i <= fifo_count; ++i) { if (hsotg->fifo_map & (1 << i)) continue; val = dwc2_readl(hsotg, DPTXFSIZN(i)); -- 2.24.1