From patchwork Fri Oct 11 05:45:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddharth Vadapalli X-Patchwork-Id: 13832092 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 81D0CD24479 for ; Fri, 11 Oct 2024 05:46:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type: Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=tv0D3m9QqlL2V3O1Ly4Bj2ftcITzo4LxkkV37gOOOVk=; b=CXYOsFGODGl1ptxCLYQdNAqveW GPvWvg4jSDKbOnr4iDhqN7U0HKTpFJ+wG8aGwjJQQgyYC6BaLRlwN+DEasWCQvt5w3QlGLFn4YD+Q pALZCBKQoZijdcJBznTZzpWAl1mFlOww6QNrCVRl6EulA7IWLMXfgsvL+hL0LoXgFaOHqurDVLlB9 2d06C868bIg9r2zg1XKLG8HvjAE+sY/aXSHNAacKrBR9EVsL0HByZV+unL/aMBV2igA/Z8eMf2cct nDnjOixGHBed2hUhBoRYR9dsRLPbzx/yXK5C1U4gWXftAYXkPxiS0HtExhgBJlYDD0CdnU8lQdbYh xJmguTmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sz8UB-0000000FLFf-44VV; Fri, 11 Oct 2024 05:46:47 +0000 Received: from fllv0015.ext.ti.com ([198.47.19.141]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sz8Sl-0000000FL0T-0lcY for linux-arm-kernel@lists.infradead.org; Fri, 11 Oct 2024 05:45:21 +0000 Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 49B5jAaN100941; Fri, 11 Oct 2024 00:45:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1728625510; bh=tv0D3m9QqlL2V3O1Ly4Bj2ftcITzo4LxkkV37gOOOVk=; h=From:To:CC:Subject:Date; b=BFg4Hjdc8gZ3Ju0LwF0VoUDTw1QiUXBG+36bvtBY5OSdqvWljoQe5qcWgQVNDBciL 7zZGAHhDju+c/rRZRzl+GosEDVaB8oHtm3nvxJtVUCTvMbX2EjbzD7nhn65UFtuxI1 2OutxfDIXhrNPPTxlX6PPFK0D1cwJng6UCLd7PWk= Received: from DLEE102.ent.ti.com (dlee102.ent.ti.com [157.170.170.32]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 49B5jA1e028069 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 11 Oct 2024 00:45:10 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Fri, 11 Oct 2024 00:45:09 -0500 Received: from lelvsmtp5.itg.ti.com (10.180.75.250) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Fri, 11 Oct 2024 00:45:09 -0500 Received: from uda0492258.dhcp.ti.com (uda0492258.dhcp.ti.com [10.24.72.81]) by lelvsmtp5.itg.ti.com (8.15.2/8.15.2) with ESMTP id 49B5j6Dj045606; Fri, 11 Oct 2024 00:45:07 -0500 From: Siddharth Vadapalli To: , , , , CC: , , , , Subject: [PATCH] usb: cdns3: cdns3-gadget: Fix cdns3_ep_config() by setting ep.maxpacket Date: Fri, 11 Oct 2024 11:15:06 +0530 Message-ID: <20241011054506.2810565-1-s-vadapalli@ti.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241010_224519_412427_A1121E91 X-CRM114-Status: GOOD ( 12.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The function cdns3_ep_config() calculates the maximum packet size based on the Endpoint Type and the Gadget Speed and stores it in the variable "max_packet_size". This value is then programmed in the USB Controller for the corresponding Endpoint. This may result in a mismatch between the maximum packet size programmed in the USB controller and the maximum packet size seen by the UDC Core via "maxpacket" member of "struct usb_ep". Additionally, since TD_SIZE as well as TOTAL_TDL are calculated in cdns3_ep_run_transfer() on the basis of the maximum packet size stored in the "maxpacket" member of "struct usb_ep", it may lead to incorrect values of TD_SIZE and TOTAL_TDL when compared with what the USB controller actually expects (max_packet_size). This also applies to the calculation of TDL in cdns3_ep_run_stream_transfer(). Fix this. Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver") Signed-off-by: Siddharth Vadapalli --- Hello, This patch is based on commit 1d227fcc7222 Merge tag 'net-6.12-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net of Mainline Linux. Regards, Siddharth. drivers/usb/cdns3/cdns3-gadget.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c index fd1beb10bba7..e89bd248e81d 100644 --- a/drivers/usb/cdns3/cdns3-gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c @@ -2145,6 +2145,16 @@ int cdns3_ep_config(struct cdns3_endpoint *priv_ep, bool enable) return -EINVAL; } + /* + * The Endpoint is configured to handle a maximum packet size of + * max_packet_size. Hence, set priv_ep->endpoint.maxpacket to + * max_packet_size. This is necessary to ensure that TD_SIZE and + * TOTAL_TDL are calculated correctly in cdns3_ep_run_transfer(), + * and also to ensure that TDL is calculated correctly in + * cdns3_ep_run_stream_transfer(). + */ + priv_ep->endpoint.maxpacket = max_packet_size; + if (max_packet_size == 1024) priv_ep->trb_burst_size = 128; else if (max_packet_size >= 512)