From patchwork Thu Dec 21 16:54:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13502392 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2079.outbound.protection.outlook.com [40.107.15.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7AAE58231; Thu, 21 Dec 2023 16:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="oi7ugUy/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OEcF/YonPq3jDRUnANhm+EKQ/ln1a/1is+8cjpWUdoXkFlLZ1ZTxWQfdcDoFrK7HYYJqyor4Ds+7X+CEJwrxt7EPwpu07SmwMmaqCIx4e4ctwy0z3agBQC5OrW+qmyfQW/TPXxb34jhl2BSqBQh6ikyM7jw+mhs8C6nKzRqjQd8T22t21HcFvhjukdqy9SCJT1qbvM9HLxbLFqWh7uTH7ndrf1hVV+H+xZbIDQQCm+nmV5QK8d9rHpnCbb2rnB9dHzQhisS428KXu1YLBXr54IBP7moCkWse6uNBwL435iRCUg5MVKZlOfWFVSYmD6h1NIgL6rJnYLersMlQEn8Wzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4gvRrEG/EeWuk2IIS1zOMeLsdsRDXnJslWsrdXPBCaM=; b=OWHNbnQCqkZJpUrVOrSXtsYsr1ZdKdyQAUXcVOAkVg1bHDxvnGG893xsn7MvQ9tQzfD0pY25LpFYRz6u/WhVrX1GarrsNCc6f+q8X2qGnMmH6on5KmGRasMSS8dxTZIDlrJtiFGfyxon3gLrZ8WQZKckc4uggTKqpmeG6dmUj8joDoW1bEsHIgEbzwchW6cRtPlg+EXRp0pt624vFH7F6gDqn9mBDO5hNau5KQl1Ga6hwjICFMULrqJBTpJYn9jLS96CrsMZ2R03GIs1jS+hwzGT77Bu+gu/+kGjCufdS6+U5SdKafcYFd/MrAIVsbsFU4tYIgE6/u+oAJhMsCTBKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4gvRrEG/EeWuk2IIS1zOMeLsdsRDXnJslWsrdXPBCaM=; b=oi7ugUy/hkuETF5phsElM0eXGocxmmPT7PgiGoGmNIsnMgF5Puvh1r8Jkegb7Wc1fKea4ZZ+uuF9G5HetIRj949loCHWzKZwHorRRCQO82PpNppCV6BZrL9wCoZ/wrFGIKEeUokiSPVcQGZfdHbfu8gVlLsYk0lTyDtP096NE4o= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by PR3PR04MB7324.eurprd04.prod.outlook.com (2603:10a6:102:91::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.21; Thu, 21 Dec 2023 16:54:44 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%7]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 16:54:44 +0000 From: Frank Li To: peter.chen@kernel.org, cugyly@163.com Cc: Frank.Li@nxp.com, a-govindraju@ti.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, pawell@cadence.com, rogerq@kernel.org Subject: [PATCH 1/4] usb: cdns3: fix uvc failure work since sg support enabled Date: Thu, 21 Dec 2023 11:54:23 -0500 Message-Id: <20231221165426.1590866-2-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221165426.1590866-1-Frank.Li@nxp.com> References: <20231221165426.1590866-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR13CA0226.namprd13.prod.outlook.com (2603:10b6:a03:2c1::21) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|PR3PR04MB7324:EE_ X-MS-Office365-Filtering-Correlation-Id: ea1e21f3-8d62-47be-2c5c-08dc02458847 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u6o+QV0ci53mpEVx8zIpVV2J7gf8hkmJ4H7ttjrSWj366/Fl2OmiX1wtn4763UuEOu0nb4GCSKm4VuzdGMSALKodNd069CfwkXFBwDxbqRg3GTD6yu+w/DEq7dDeKxjKhcxKoe3iHez4LW/6W5qmhFdhDNsq2XZ9oUmRVTJSfzIDV+SBjQF49bnKIF68coYevWwpzz5rve2vCjYJZU+BUjFpZCuOQD+kabks4lDivuyUXhvkentmJlodvtmzEuWAYiGmTn6nyZ2NBE3Gctm+oysuzUMsbsRYXzoVuBdK3dXC0mSfKPV8lH1cSPgEBO7eyTSoD3I+RZsvxiRR5TnhJ8y8Vona8xaS1h9ha2hv4yZiKDBesF1hxHE4U4BWv8alH+uPnFeAg9MgaPzydkFkhz66PDA5t7aTxnZKxob+yQSN+jJi00w95hxDpa8XIOfcmLe5ETcPW4jPUxJ0AZwBHofQKYFujeIM6YjMmsJtNCDIl/lzXCevCuT3GTo/1QT483a7mHVWwr5GXkX3chTBs+hbdGDcghcd45XF0ZEgT70FqRmJSQXULCep8rdr5ad7rJnis5PvHUC9wJgsUzHiQs1jUEGhUqyfR1n8XQdgPkMJRxxjT4VxsKoIYYFeGxjP X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(136003)(366004)(346002)(376002)(39860400002)(230922051799003)(64100799003)(451199024)(186009)(1800799012)(2616005)(6512007)(6666004)(26005)(6506007)(1076003)(52116002)(83380400001)(4326008)(8676002)(8936002)(41300700001)(2906002)(6486002)(478600001)(316002)(5660300002)(66946007)(66476007)(66556008)(36756003)(86362001)(38100700002)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aAmpPXrJx5RwyemkWW/TGDxiiBGJ40kWVn3IQzsJ88gZqBrViaD/uEQGyRTaas0UWLk6oIuxVXBFKeMjwNhE/mp2exlDxzgXPFrJlNeGmsgQjyvcpVvgH3bfb2cGI2bUGPl4bWrhh2brX07QDMnJ9wRgObdWsLwun0nGTjwV2a/hoAZQscXwhCSz+tvIIt/vkrNz1uO++WVRnWk0WzceDzJAKqkzM7J/7XSCN4MMCDuZtSbPRZaOOF4wkxYLjmUzIdN6DOmfsoorhKsqRclHOzoWsJXAF0T2RxI59dyPTEAeOpne3kQ1nMnNOFYmjtuOiS98Ahyie6ra0eFcWW33Z3XsLMvBuq0SYLlB3kcnpLbqtFGCVnX0C8yXH540CyooYsI3X5EnNzZa6Li9AiVBbBHJjoLzHNBqFw0/fUs8StR1tSfgM2yaka+wbnpyHsw8UsAr1EB5NVskNbkl52crjYvl+RkA3QdvFpGHQNwOzaZfVNrSjMOu5XKITStXlNhxna48lPm8fh5N27G127+6AAW7PMkP8fZh/goA9cmQgCb9+/UFEhnUlC7aGk/L6B2g2c6W5aaNzyhlnJKp8FUievijan2hPPudldJB4KFnjQCdSjrnxhiPPZN4G+9uyJ9j2oFR2EiJpGZUFTInImB81jSrJc6ltWiGpZxpRZWacmjLLvORq3+i8bIwGzzmN60NK97KUr5boyRcYVbkqMzD+uiMzmVyyo7/BnSMZW3t2wtfFUPd0wCDbiS+9+XCSI34mjBkj9r6t/oHUZyP8YSS11laayHmKtl9gRh19GVnw5bznby60vmPnlMrOSARQYkQri2FwNPRRjIDuBNBQuoqSoyrgRRbyghU3BJTFSA6uZn0hD1sLDJskteV6EzPjAP+9EMKL15NzISyITlqgCY9QxElBXaLpzAPcbQsJ4eP6b+DMQ/LNNnoX/v+QailYbMz1+lyN76R5nq8uVsDADxkyCIlp7qSrx+6t0Edoomc2RiVCmW3BP7NMdveOP+tKg+TXJyJvk3v99Z01a8UPhX64YirdatUC4f3L1emlNBQIWdP8WY1E35H8L4K2NSH54X5nN0LgSmukaOzMjF7CLAIlrQHhqWnAPS53W6Dmq+Cm1X4lDslDgNRmBKEwtsEtqiAmpJzA5DUC+BjJ1BI0dEIa7cXmPiBc67FL1BWMF9YjG5xvqcuya5HMadqiHeVLNxvM+5kIXXTbOzVT46wcxUsokSg711R1bwtPtjAcla1YJi7MUspaDnr/50+4DlsluucNpxTRlxWFtfFyaQKLfkcJO5IVHzJGKWI/hgWzkI5dYCaaCLnLIbt5ch8codPvLN0l7G9vOTv+ouL5kDnM0P2y5H+HMzujs/ICx0J0VqQaCCkw5nRivleFC5p9MHJblcsDFybSD79a2msU8vHdHbxOh68Ot/vSoWhDiffSuPUgj4szf1ApWuJCYINK+hGEpAbfOZiiSthhJfN6dy+M29Pzb2RIaMWfJQdsXfxqgBxxBEIA+VCIRzTrW2kClKM/IgoWiAZn1hXDNz8jOEd7jtZ5quoGHg0T0BlKyMZWBNfnQKyDrY5h3g7teRquZBk9ofC X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea1e21f3-8d62-47be-2c5c-08dc02458847 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 16:54:44.3656 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +MrRV8YM+gRM7FFsuNuigHc+Ue9a7rGJoKs3GmsCYd2ptwYThs7lip2k9JGrOfTuaqJoykKGqtUZKngyA8xX9Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7324 When IP version >= DEV_VER_V2, gadget:sg_supported is true. So uvc gadget function driver will use sg to equeue data, first is 8bytes header, the second is 1016bytes data. cdns3_prepare_trb: ep2in: trb 0000000000ac755f, dma buf: 0xbf455000, size: 8, burst: 128 ctrl: 0x00000415 (C=1, T=0, ISP, CHAIN, Normal) cdns3_prepare_trb: ep2in: trb 00000000a574e693, dma buf: 0xc0200fe0, size: 1016, burst: 128 ctrl: 0x00000405 (C=1, T=0, ISP, Normal) But cdns3_ep_run_transfer() can't correctly handle this case, which only support one TRB for ISO transfer. The controller requires duplicate the TD for each SOF if priv_ep->interval is not 1. DMA will read data from DDR to internal FIFO when get SOF. Send data to bus when receive IN token. DMA always refill FIFO when get SOF regardless host send IN token or not. If host send IN token later, some frames data will be lost. Fixed it by below major steps: 1. Calculate numembers of TRB base on sg_nums and priv_ep->interval. 2. Remove CHAIN flags for each end TRB of TD when duplicate TD. 3. The controller requires LINK TRB must be first TRB of TD. When check there are not enough TRBs lefts, just fill LINK TRB for left TRBs. .... CHAIN_TRB DATA_TRB, CHAIN_TRB DATA_TRB, LINK_TRB ... LINK_TRB ^End of TRB List Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver") Signed-off-by: Frank Li --- drivers/usb/cdns3/cdns3-gadget.c | 51 +++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c index 15463b7cddd23..22a31ffa69423 100644 --- a/drivers/usb/cdns3/cdns3-gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c @@ -1119,6 +1119,7 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, dma_addr_t trb_dma; u32 togle_pcs = 1; int sg_iter = 0; + int num_trb_req; int num_trb; int address; u32 control; @@ -1128,15 +1129,13 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, bool sg_supported = !!(request->num_mapped_sgs); u32 ioc = request->no_interrupt ? 0 : TRB_IOC; + num_trb_req = sg_supported ? request->num_mapped_sgs : 1; + + /* ISO transfer require each SOF have a TD, each TD include some TRBs */ if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) - num_trb = priv_ep->interval; + num_trb = priv_ep->interval * num_trb_req; else - num_trb = sg_supported ? request->num_mapped_sgs : 1; - - if (num_trb > priv_ep->free_trbs) { - priv_ep->flags |= EP_RING_FULL; - return -ENOBUFS; - } + num_trb = num_trb_req; priv_req = to_cdns3_request(request); address = priv_ep->endpoint.desc->bEndpointAddress; @@ -1185,14 +1184,31 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, link_trb->control = cpu_to_le32(((priv_ep->pcs) ? TRB_CYCLE : 0) | TRB_TYPE(TRB_LINK) | TRB_TOGGLE | ch_bit); + + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) { + /* + * ISO require LINK TRB must be first one of TD. + * Fill LINK TRBs for left trb space to simply software process logic. + */ + while (priv_ep->enqueue) { + *trb = *link_trb; + trace_cdns3_prepare_trb(priv_ep, trb); + + cdns3_ep_inc_enq(priv_ep); + trb = priv_ep->trb_pool + priv_ep->enqueue; + priv_req->trb = trb; + } + } + } + + if (num_trb > priv_ep->free_trbs) { + priv_ep->flags |= EP_RING_FULL; + return -ENOBUFS; } if (priv_dev->dev_ver <= DEV_VER_V2) togle_pcs = cdns3_wa1_update_guard(priv_ep, trb); - if (sg_supported) - s = request->sg; - /* set incorrect Cycle Bit for first trb*/ control = priv_ep->pcs ? 0 : TRB_CYCLE; trb->length = 0; @@ -1210,6 +1226,9 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, do { u32 length; + if (!(sg_iter % num_trb_req) && sg_supported) + s = request->sg; + /* fill TRB */ control |= TRB_TYPE(TRB_NORMAL); if (sg_supported) { @@ -1251,7 +1270,7 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, if (sg_supported) { trb->control |= cpu_to_le32(TRB_ISP); /* Don't set chain bit for last TRB */ - if (sg_iter < num_trb - 1) + if ((sg_iter % num_trb_req) < num_trb_req - 1) trb->control |= cpu_to_le32(TRB_CHAIN); s = sg_next(s); @@ -1509,6 +1528,12 @@ static void cdns3_transfer_completed(struct cdns3_device *priv_dev, /* The TRB was changed as link TRB, and the request was handled at ep_dequeue */ while (TRB_FIELD_TO_TYPE(le32_to_cpu(trb->control)) == TRB_LINK) { + + /* ISO ep_traddr may stop at LINK TRB */ + if (priv_ep->dequeue == cdns3_get_dma_pos(priv_dev, priv_ep) && + priv_ep->type == USB_ENDPOINT_XFER_ISOC) + break; + trace_cdns3_complete_trb(priv_ep, trb); cdns3_ep_inc_deq(priv_ep); trb = priv_ep->trb_pool + priv_ep->dequeue; @@ -1541,6 +1566,10 @@ static void cdns3_transfer_completed(struct cdns3_device *priv_dev, } if (request_handled) { + /* TRBs are duplicated by priv_ep->interval time for ISO IN */ + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && priv_ep->dir) + request->actual /= priv_ep->interval; + cdns3_gadget_giveback(priv_ep, priv_req, 0); request_handled = false; transfer_end = false; From patchwork Thu Dec 21 16:54:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13502393 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2079.outbound.protection.outlook.com [40.107.15.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5266F5823A; Thu, 21 Dec 2023 16:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="fnEX5ULk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IiMuEI0/9GDA2EZK/hkkuyNAjZjipIfTqD1RmdlMoj3dJK4jMAkpiHtsMwsHXlHy6DtOBgRHiISeZSJVC3dPYem9Qi3m9XttJGHmSMBed/7bcKUzeV6OI0Vyf8ik4cdsDenpFQ1+UU/4TT8NOOQiQpu9PFfyzaCILe3CJUDx2XfnuBtrnuTydSSBNW6fbLlL60952ZyNMEMlD5KTF3QCRNblZBpPRb9gcnlLoD3D8xqsdwMcKgYfqQBqbRRHNpFaBU+XfZODnuXzaFIDIfCyra0c5kUHXBpiQkDkd4MyKSqWgqTW7OZVoYcyX8xVSSWwuZDJDmCzrozyfK5zk2Q7jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=x+I4UWP/ujUsXhcyVDZML325GJfBB3qOZbGG/5f5phA=; b=Z42eA+BiJL+9U5JS72kUgYavKegMg4MEbGkKyQd525Nex/eO0dt1fs5cpbydBptfpqS+AoKreMJygMMSSxSuu51ei+zFTQ6Q56bJ+XkEnUMQ9+f19YXSX3m74wNT5a0EoEXpFgL2Rr7THZ2MqrN8VrCJUSGxHJPb8LPcMZxXb77j0Y/s4b3P55jPOsN1e7DAmOlWDBfauzv1+rOgicnYS1gZIEJK0t1Bc2/niob/p7RANUdRhRkSTUFxhI8Prud1sXra5+ELTXuIDeexzCkuYowYw2292Z0bTSJ0xFIeQD7erDYT4CxDlW5R05oPDSgTp04mTnxqCl7sSwBbXgKM8Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=x+I4UWP/ujUsXhcyVDZML325GJfBB3qOZbGG/5f5phA=; b=fnEX5ULkcl3M0nJABh+q/AdmrwTsKGuyebeoYdOe6ajRtwdQ3kZqtRkwjzi9x7/LGxRn+BiS0vDdBoqZrh9E8bU1oBFCd16Yb4A9CjvqmREz1G3LfTKGUSjxKLlWLt86fRKQYjFY2nCU4X+lKejus3SlgRW0FQmjvXHspVDI7Dw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by PR3PR04MB7324.eurprd04.prod.outlook.com (2603:10a6:102:91::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.21; Thu, 21 Dec 2023 16:54:47 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%7]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 16:54:47 +0000 From: Frank Li To: peter.chen@kernel.org, cugyly@163.com Cc: Frank.Li@nxp.com, a-govindraju@ti.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, pawell@cadence.com, rogerq@kernel.org Subject: [PATCH 2/4] usb: cdns3: fix iso transfer error when mult is not zero Date: Thu, 21 Dec 2023 11:54:24 -0500 Message-Id: <20231221165426.1590866-3-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221165426.1590866-1-Frank.Li@nxp.com> References: <20231221165426.1590866-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR13CA0226.namprd13.prod.outlook.com (2603:10b6:a03:2c1::21) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|PR3PR04MB7324:EE_ X-MS-Office365-Filtering-Correlation-Id: d534bbf2-0f7e-4c90-2c36-08dc024589ed X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0LsZJ1YuKpmjRyEW7tDVjBPZ/e6uws2Z3BPRp/p70/gOe7WzjDR88naaEwgOhJsRzfAntV0jpfOiENGfQenSgAj8nBZX+xd+6ZZT1iEg5lzYBcjw4DO8FfKeu568FQouiJHxf4lDMcpRzcrLJmMbgVHKc8mmABCJ4DSoq1vq2uH2mNoic8d4G+gMufK8edPyfj/RN+7Yku35tSjTOy9wN+aQOhSu3EKY8/XcJKlWgDW48orXIWM4C3tVOq0sUb5zBKm3FbNirC2PwtZPbbbUhfGBXQ4ZTt3AlfTEyXM2TIYNLZGUZAs6yqu6QcBIAi06Hzzg/29zZSgyLDAO/TfMiORVcLV6ZNxB1X24nTMFnJ7yTg6mjq9ViXKjycuw9ryzMI32GnAB9FOLIOZJIzJgSekVrURo3dz1fixEsE9iHetAPwVqaQ7F/kkP/FAHTewlP3dD0ixUoOmzTphf5zDLmrXtWB4oVF9ZvGqL6vFEExmkbjmUgVxZz+jaXKLCZcw1TBx76Ee+hGXMZVfZ933qCQHMJp/QqirlD/8idd6icHfplLLVOu+i3BNPOOZ5/DDpbRdS8dmEwif7Tn6LHOI27t9u2s3t9jV4ni7CgTZjfOd6l7koVZ2J0OiO4hu7ZmNo X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(136003)(366004)(346002)(376002)(39860400002)(230922051799003)(64100799003)(451199024)(186009)(1800799012)(2616005)(6512007)(6666004)(26005)(6506007)(1076003)(52116002)(83380400001)(4326008)(8676002)(8936002)(41300700001)(2906002)(6486002)(478600001)(316002)(5660300002)(66946007)(66476007)(66556008)(36756003)(86362001)(38100700002)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ax43GxcOrhyiZvdog5FUGWKr7Hs+lo4Ci/4K+VhBTrCk4sRZPnI3v6DFAqr2jkEuB3y4U09yUB5hONXAEinuHpRfdF9wA2ayj6Odc13qI+bWdBDHNxDoVRrAZWX+U/kleMJf+9LsN8fIQe/QebJ0WtVYA8iAu9xGnRz3vAxC/3UIyKlAGCsHvzpryFRT3Z7BwzpTHSMrvz3pCZwNOHiAQJcZ4izqaZMukXI8ZWB1ZI+EeYxZQyeLjBLrKGbiwT3pr4h3qRou9B69gBeIXGWte2VPO81RF4BgXP0V/eXjJT3z4H6fmVJ5Cfa0mDkyEWAOcS4Wf/azlOC/Y+TByXmyvLsKACHAqVsMAuXs3eouimcAQUgtjE1lSwpwXkYCXnS4U0BKo252G3P3TSQhwr+uCLVMRkpsOECTDbUU58Z5CnTA9DlwTRvzI9qHEIw1jdlB2q4xZ+OiduQvy19p7Q5I+JgH+9TVzOrU2Gf4QAVfuOw8BvTUUbBNAL3AHHhLNFMnLlwyMUnNnZpnu12HKc7i0dx7Crr/dCBSMKd54MoGhWwT/0UMNwPNTV1M+F0ozc/VZvTtqLVCsvUJtbnWRgTEFXT3OjfACUIhCRcFZVKqYHXDpG50/KLOZ35G+4pKkDmMY5i3Nutkj1nANjAVOH09A5UzmMyD3peTO5TKpGclH7enc8uU7PQN0tV8SpB/3VGL/NgXSYqbUrFF3NKdIHO5mnGE0tBx2IZpCGB3fbptDWDViG6OiOUYYPh77aStoOvPNrKinzDwd8OfNZWy9Sll9uR2GNEWBKd9Sk8nuU/ZEcYjdoe/sp3o+1ZbODhagy3W9LW5jOhdaRFkPUNXLxTIb2myUmeinoTh7Gdygw0dHaRBGNot3NLVkRFySnW2p5qPMhpHqSyOIDSddt1RFOHQFaCUQGyX5t5i6U6VAqwrveAsGGMnsEJ2aeVPVu5bBD73Z863ohLKSpy7w37CYigdfgv8BqX4oN1gsGC9m4qRjJwmIryFUqWVkLlQCnDfp+Mj9i3czwXkn9m3avQZtIZO7XCwgHg19mQh7T0dEWVPonoJ8cNjYytM+Ot2tzmeawGDh2qYSj8+yF0WBjkOlggN/fiZYWXPwlONcVRrd6vInFm++OrR0JKN4mkaeZXiNqxm2ExFxHmLuDKXqzHOCISNqDg7jivEAcRSzvFR08wtT9t/aYZedjJWXqPFdfXDein9odAQgPk/Fk49o4ROhyF3pkEqhv6/zkeZo4deCb+gf1iloFLtJ/HzgvE2AdkkzCA1Kgg8PJ9tpo+XSiWTxLdH5N82NM/hzEPGaa04enBCLYnbQ3ui4jGboofoQBxaGjXxTvUCDudcU+rDtMJB/B98mPWzb99Ual5ETfSsL7Y4YaWzvNsEsDwdkKA5/27Va0BUOqdMGFZPnO9WpXcEFcnpnEFGWIQUd6nKLCuV8nm9tRn/9N/ISe1EjzBgJapdHlX5O+7G+E8TeaEIs54vdJvoxL0hCWb+GKU20sOJ2L/w6RpWU2bjYBRlyZ5EaJzeXOr+MeHaMRYqcbvjs1nJaI6OPRwGTEpRPxtf5ySZE5waA/g6G8VoxpjtjIKo8b+3Nw/w X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d534bbf2-0f7e-4c90-2c36-08dc024589ed X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 16:54:47.1106 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: AP7mul0wHbpVrnMeczPmsSgu9UVf8Jg/o4ENPD7VPUw/8OkLSPHuHd4QJq+2K6/mdx8U2AAq0jotNPCaJTKslg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7324 ISO basic transfer is ITP(SOF) Package_0 Package_1 ... Package_n CDNS3 DMA start dma transfer from memmory to internal FIFO when get SOF, controller will transfer data to usb bus from internal FIFO when get IN token. According USB spec defination: Maximum number of packets = (bMaxBurst + 1) * (Mult + 1) Internal memory should be the same as (bMaxBurst + 1) * (Mult + 1). DMA don't fetch data advance when ISO transfer, so only reserve (bMaxBurst + 1) * (Mult + 1) internal memory for ISO transfer. Need save Mult and bMaxBurst information and set it into EP_CFG register, otherwise only 1 package is sent by controller, other package will be lost. Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver") Signed-off-by: Frank Li --- drivers/usb/cdns3/cdns3-gadget.c | 59 +++++++++++++++++++------------- drivers/usb/cdns3/cdns3-gadget.h | 3 ++ 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c index 22a31ffa69423..4c6893af22dde 100644 --- a/drivers/usb/cdns3/cdns3-gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c @@ -2065,11 +2065,10 @@ int cdns3_ep_config(struct cdns3_endpoint *priv_ep, bool enable) bool is_iso_ep = (priv_ep->type == USB_ENDPOINT_XFER_ISOC); struct cdns3_device *priv_dev = priv_ep->cdns3_dev; u32 bEndpointAddress = priv_ep->num | priv_ep->dir; - u32 max_packet_size = 0; - u8 maxburst = 0; + u32 max_packet_size = priv_ep->wMaxPacketSize; + u8 maxburst = priv_ep->bMaxBurst; u32 ep_cfg = 0; u8 buffering; - u8 mult = 0; int ret; buffering = priv_dev->ep_buf_size - 1; @@ -2091,8 +2090,7 @@ int cdns3_ep_config(struct cdns3_endpoint *priv_ep, bool enable) break; default: ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_ISOC); - mult = priv_dev->ep_iso_burst - 1; - buffering = mult + 1; + buffering = (priv_ep->bMaxBurst + 1) * (priv_ep->mult + 1) - 1; } switch (priv_dev->gadget.speed) { @@ -2103,17 +2101,8 @@ int cdns3_ep_config(struct cdns3_endpoint *priv_ep, bool enable) max_packet_size = is_iso_ep ? 1024 : 512; break; case USB_SPEED_SUPER: - /* It's limitation that driver assumes in driver. */ - mult = 0; - max_packet_size = 1024; - if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) { - maxburst = priv_dev->ep_iso_burst - 1; - buffering = (mult + 1) * - (maxburst + 1); - - if (priv_ep->interval > 1) - buffering++; - } else { + if (priv_ep->type != USB_ENDPOINT_XFER_ISOC) { + max_packet_size = 1024; maxburst = priv_dev->ep_buf_size - 1; } break; @@ -2142,7 +2131,6 @@ int cdns3_ep_config(struct cdns3_endpoint *priv_ep, bool enable) if (priv_dev->dev_ver < DEV_VER_V2) priv_ep->trb_burst_size = 16; - mult = min_t(u8, mult, EP_CFG_MULT_MAX); buffering = min_t(u8, buffering, EP_CFG_BUFFERING_MAX); maxburst = min_t(u8, maxburst, EP_CFG_MAXBURST_MAX); @@ -2176,7 +2164,7 @@ int cdns3_ep_config(struct cdns3_endpoint *priv_ep, bool enable) } ep_cfg |= EP_CFG_MAXPKTSIZE(max_packet_size) | - EP_CFG_MULT(mult) | + EP_CFG_MULT(priv_ep->mult) | /* must match EP setting */ EP_CFG_BUFFERING(buffering) | EP_CFG_MAXBURST(maxburst); @@ -2266,6 +2254,13 @@ usb_ep *cdns3_gadget_match_ep(struct usb_gadget *gadget, priv_ep->type = usb_endpoint_type(desc); priv_ep->flags |= EP_CLAIMED; priv_ep->interval = desc->bInterval ? BIT(desc->bInterval - 1) : 0; + priv_ep->wMaxPacketSize = usb_endpoint_maxp(desc); + priv_ep->mult = USB_EP_MAXP_MULT(priv_ep->wMaxPacketSize); + priv_ep->wMaxPacketSize &= USB_ENDPOINT_MAXP_MASK; + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && comp_desc) { + priv_ep->mult = USB_SS_MULT(comp_desc->bmAttributes) - 1; + priv_ep->bMaxBurst = comp_desc->bMaxBurst; + } spin_unlock_irqrestore(&priv_dev->lock, flags); return &priv_ep->endpoint; @@ -3049,22 +3044,40 @@ static int cdns3_gadget_check_config(struct usb_gadget *gadget) struct cdns3_endpoint *priv_ep; struct usb_ep *ep; int n_in = 0; + int iso = 0; + int out = 1; int total; + int n; list_for_each_entry(ep, &gadget->ep_list, ep_list) { priv_ep = ep_to_cdns3_ep(ep); - if ((priv_ep->flags & EP_CLAIMED) && (ep->address & USB_DIR_IN)) - n_in++; + if (!(priv_ep->flags & EP_CLAIMED)) + continue; + + n = (priv_ep->mult + 1) * (priv_ep->bMaxBurst + 1); + if (ep->address & USB_DIR_IN) { + /* + * ISO transfer: DMA start move data when get ISO, only transfer + * data as min(TD size, iso). No benefit for allocate bigger + * internal memory than 'iso'. + */ + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) + iso += n; + else + n_in++; + } else { + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) + out = max_t(int, out, n); + } } /* 2KB are reserved for EP0, 1KB for out*/ - total = 2 + n_in + 1; + total = 2 + n_in + out + iso; if (total > priv_dev->onchip_buffers) return -ENOMEM; - priv_dev->ep_buf_size = priv_dev->ep_iso_burst = - (priv_dev->onchip_buffers - 2) / (n_in + 1); + priv_dev->ep_buf_size = (priv_dev->onchip_buffers - 2 - iso) / (n_in + out); return 0; } diff --git a/drivers/usb/cdns3/cdns3-gadget.h b/drivers/usb/cdns3/cdns3-gadget.h index fbe4a8e3aa897..086a7bb838975 100644 --- a/drivers/usb/cdns3/cdns3-gadget.h +++ b/drivers/usb/cdns3/cdns3-gadget.h @@ -1168,6 +1168,9 @@ struct cdns3_endpoint { u8 dir; u8 num; u8 type; + u8 mult; + u8 bMaxBurst; + u16 wMaxPacketSize; int interval; int free_trbs; From patchwork Thu Dec 21 16:54:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13502394 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2053.outbound.protection.outlook.com [40.107.15.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CAC1634F8; Thu, 21 Dec 2023 16:54:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="ONmXltIa" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=di20RUglnkTR40FVPLINJiUKyI0tUGoY4mXMB0rKT+Qu93PcHExbkebEJx8rKrEEAOIAbv0/e3mfcZ0n7FVO/zj+UjwkvbDS7pjD4Xe2uggfSMw/gOSUsgUgSX938dz+LQYDuC7rpfxK4q/0nt5GiP7oI148Mrj/GW5SdcauNAVD3d4hHQQvQf6nsO8hWgpjVAXQEojfBsIIzhMFDojSDDuazrbb8Gm5FxdWRkv/tZ+3zCZi/TeWWBMJQfQwCZyCcPkhbbTgjo/rB078V9GfvUNKfE7trPMBm/a9+I48V9fJu6n4evLCk6jVnchLJhIqEaXU+7nt9ZmwAWyLGBk9Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1uU/DgeUPYPON4N4JAteu/Ha75T2xugBeu8V8eh6toY=; b=iarZ9iICei29MyyzmRC4Fs7YIfKU6G2SesDb+2PmwvL8fwljDcsemUZLPRPJgBjAqgoMpBEYIy/c2d+NNA1ezJ9VDUIVf+T8MWdnZy5vT2fb9WWErXBT3+40h2R5+YY48Gf+tUgSb7xP1xlIyBMMJusWV1VsRiuApyW3apg1vFw0+0gQn25QzSAc2amIiqVrpFmJZI2OBuV4cXwUsSgK8Dko51yb898EmSpRqldJdtpkP7f5ivnt9Gk5x4vwiA9QKnJzrwdo9XIJ8rbI+9TEI8quFu0Xf2GRJrpBbPFn9k0HkDBnh+G/MEP+co0yqd+QmnwG1kV4YxADt/pkcgGhgA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1uU/DgeUPYPON4N4JAteu/Ha75T2xugBeu8V8eh6toY=; b=ONmXltIatheBfEKmaTmTngg/2qeGGGOc80OCZurpiTw9630ASqN3fjqUy35jRBAUL+iTGu44RHMtGHkueJTrzBOzUmdjCybNilARqb4VNiV5bQd+EZNJiHt8Qh07jmdIf0PFtLx3zb6tTKn94PGKf1hgUKWGJ+cfIzanyULTPA8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by PR3PR04MB7324.eurprd04.prod.outlook.com (2603:10a6:102:91::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.21; Thu, 21 Dec 2023 16:54:49 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%7]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 16:54:49 +0000 From: Frank Li To: peter.chen@kernel.org, cugyly@163.com Cc: Frank.Li@nxp.com, a-govindraju@ti.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, pawell@cadence.com, rogerq@kernel.org Subject: [PATCH 3/4] usb: cdns3: Fix uvc fail when DMA cross 4k boundery since sg enabled Date: Thu, 21 Dec 2023 11:54:25 -0500 Message-Id: <20231221165426.1590866-4-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221165426.1590866-1-Frank.Li@nxp.com> References: <20231221165426.1590866-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR13CA0226.namprd13.prod.outlook.com (2603:10b6:a03:2c1::21) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|PR3PR04MB7324:EE_ X-MS-Office365-Filtering-Correlation-Id: 5c8d98d5-cf49-4643-2ba5-08dc02458b93 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WE2zLfTzEZMwScuzu+NVdlE5v9zOFvqLR7mySFaUqZgcS0gLhgqCc94Xqsn43MYvp1AE1obpLdHBj27ysEPdEpRpBthtIQV1yEynQQbyFipaIC0siosYQ3UtI0f5okOrqeydgW7I3wYJLiiAVeYT0BQ1YWIz3Nlj/2oHz4OoHYKAdw5GCMmF5BDmI2JU69/yxDDXWpI7Xj1fUqzjzsdME8GaLKG7zQv1yAvx4/ichRCH/VCI9xLxcVEDkxAs0LPOFca+WTiKGMM7WuDOSMaoxfxNHuptYRI6VjWUpgEIlV4QkYtEsUgOjKMUTHnVVcXYb1QNBIS/Hc5+2UCZUUVOT41DkZiH/purfU1ptiI0JfP1O9bc4jm9W+vFO21aHrv8EYgjlrVrGor+x1fWwBsN+tMHNaAw+hF6SF6w0OyH8IOzeMKlNQeWrGLaVo75egrV23G7Dh+DsPL/pzQLazPtNhYWCfo3FFJ0FcObtizoApy0A800E8g5WLK60EbOyMLFOog4EwO+AhRv801cnvphqDh4nxHrNLLea+vvernLhszzJADyRZYYx/Qz3ZNMFnzVLSRpXut3kBpYTZudnghjlWpwXCU9+/IZkosTLAD9QjKVFJqHGgMtXcwrpln263Fx X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(136003)(366004)(346002)(376002)(39860400002)(230922051799003)(64100799003)(451199024)(186009)(1800799012)(2616005)(6512007)(6666004)(26005)(6506007)(1076003)(52116002)(83380400001)(4326008)(8676002)(8936002)(41300700001)(2906002)(6486002)(478600001)(316002)(5660300002)(66946007)(66476007)(66556008)(36756003)(86362001)(38100700002)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Y8jF0os8liuFVHaGnXzg3B0qfiiYY+zaf/8/GUF/xfKqNGqIn13wSILtPv8VeA+dX+GwhR3bUOpNGfs5nofxf2hWhgj9Snbn0bYQOB0lFvVTjj9yv489E6HTDoTCLyeSmkt1DgCBCnoo5MLQy9w8jlbq+gawsWM96OI/i6X6Cpt0wFVXwLo79wFgRL+9sh0En1r7hR/b79WpzE5WwjN1raFQHE9zSNp9qnTv3v6/+UhpLbddPHGASesCdeoXFlkCPuBLJiuO3gUqisefuLhTSJFP7DvjYEqcNEHcZo4mnPfGjd20zjpcrVH5ELhhuCydfK5oYIjnxhsCy8JitRcTZEI2zDsgH65n3fNlIU2YSPidsOLy6D79Zsr24/uvEqU5CQRbxAnyLQzlTb7xwAOVmdXcyYt2zd9AhV0HQ1cCazclp8quECe+o1tb+I19uG5Uv3Qw9EcOYKjPSNSZFjvH1+silKyVi1D41rD9oA7G3fRcYgK7qq1h4fixffwWk38NZCR7f0Pb2rUKzL9zRuT9p60fjpG/0qPdmzlcJ0Rsd7im2AHY2U09ibVMMY6nvZhA/VrGJw/CXc7gT8qRF6qDBI1OPndoUps8UkZDpokJZkeDhEn1G9ef2HiJtAdvoULRn1ISurvXTJR8Hhb7lcXC+5qpT0Ya3AOCpikGeZlzmBUXPh0W6w/h4adBzB25CiE4dLrZN+mNtaHKpfx03/x/sdc3VQRCxxq4aoY17alX1RtrXdqpxA+e8CdVFPSrbZfjoj4aFZXtaYy8PA1CzNirOYpn+d1pM7ajwe0ciAUxzHSSqqm0quwaj/fSo245oUBnBXLIt2Y+i4qyp3Cm6Ij4hjlUgK3x5plgiIA4VGwJ+8hntJwzaAjRPUonhDP0CjyrrRrxUB7z1lun8GSiDXDIZOeMNcd8qExWWVctUcpLkNCDv8dBYNo2IBglDk8OCF70gWLY7/bW8QqKNxgf04BZLWsiigi+CwsbzehceDDTm7DulAeNjnQhqQ1bFsFPF+x8ZljHHxCIAG1AOxEbRiZuRquzoE0fuKUHay/YpqlSraSii+14cJiIvhSwl2ahr3/ffFUE74Gf+rinYRtaSCy7uf3I4CSFfMxeYCNMk2f7spHxEQHuD5jPieDMFPFVX5StgJM2TDspVED/Fq3JM0AEAEyCrFjz2EiuI8KSK6SVf1zNuEvc2jnbD8Ej/TlQ/EpDV3rN8hJGXbk0JADSd/9fYv1dWBFkiRMWLedWlTQddM3l6rTQt937NcuMr1b/vmdBKh2+Ci/l+hiQXeFdM/KnQM+q7E6E8iC92MP0X2xCw6pWpPkC2P9Uugea03ngvT+dXvzPIUP4SGg6N/c8ps6TlFWQ9jZHsEp4IWvE1PRg6JDfQ3aneo0bPcq3RJ5G74LQh/iCsOKrkjxY/qdG/L96H4qvMjUZjBgRGcfQwuxzpMFC0bJEoSDBzSkq0aY2lItss7hjxv/XpMcs9uEBb1ZiQH2Z581tOOhmEXjWCmuljuUOMNYyweHOgUyw8ipaNrhRJ7K/N3ZSWSdnjCeT3saAZ5+cFKXrHCM3yCh4ewSryKw7W9/6fbRAsex8nU0NLOL/ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c8d98d5-cf49-4643-2ba5-08dc02458b93 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 16:54:49.8727 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CbDQy+yb43jLakY7y5XMSYg7UeOVIF9PHEIQHyjYGoTC3tj63RL29haW6u4vKmPdzjY+rUbM22P3kNAgYFYRNw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7324 Supposed DMA cross 4k bounder problem should be fixed at DEV_VER_V2, but still met problem when do ISO transfer if sg enabled. Data pattern likes below when sg enabled, package size is 1k and mult is 2 [UVC Header(8B) ] [data(3k - 8)] ... The received data at offset 0xd000 will get 0xc000 data, len 0x70. Error happen position as below pattern: 0xd000: wrong 0xe000: wrong 0xf000: correct 0x10000: wrong 0x11000: wrong 0x12000: correct ... To avoid DMA cross 4k bounder at ISO transfer, reduce burst len according to start DMA address's alignment. Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver") Signed-off-by: Frank Li --- drivers/usb/cdns3/cdns3-gadget.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c index 4c6893af22dde..aeca902ab6cc4 100644 --- a/drivers/usb/cdns3/cdns3-gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c @@ -1120,6 +1120,7 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, u32 togle_pcs = 1; int sg_iter = 0; int num_trb_req; + int trb_burst; int num_trb; int address; u32 control; @@ -1243,7 +1244,36 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, total_tdl += DIV_ROUND_UP(length, priv_ep->endpoint.maxpacket); - trb->length |= cpu_to_le32(TRB_BURST_LEN(priv_ep->trb_burst_size) | + trb_burst = priv_ep->trb_burst_size; + + /* + * Supposed DMA cross 4k bounder problem should be fixed at DEV_VER_V2, but still + * met problem when do ISO transfer if sg enabled. + * + * Data pattern likes below when sg enabled, package size is 1k and mult is 2 + * [UVC Header(8B) ] [data(3k - 8)] ... + * + * The received data at offset 0xd000 will get 0xc000 data, len 0x70. Error happen + * as below pattern: + * 0xd000: wrong + * 0xe000: wrong + * 0xf000: correct + * 0x10000: wrong + * 0x11000: wrong + * 0x12000: correct + * ... + * + * But it is still unclear about why error have not happen below 0xd000, it should + * cross 4k bounder. But anyway, the below code can fix this problem. + * + * To avoid DMA cross 4k bounder at ISO transfer, reduce burst len according to 16. + */ + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && priv_dev->dev_ver <= DEV_VER_V2) + if (ALIGN_DOWN(trb->buffer, SZ_4K) != + ALIGN_DOWN(trb->buffer + length, SZ_4K)) + trb_burst = 16; + + trb->length |= cpu_to_le32(TRB_BURST_LEN(trb_burst) | TRB_LEN(length)); pcs = priv_ep->pcs ? TRB_CYCLE : 0; From patchwork Thu Dec 21 16:54:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13502395 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2053.outbound.protection.outlook.com [40.107.15.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E1F463503; Thu, 21 Dec 2023 16:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="IasY44lk" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bP/H7UlzxF2QmcfAx8HdmaIjpxKVtdslBtOpdyrRjsqt/NxJCmnfxmgvHq3uGLDLu3PXHro8H6L0g/0Yct5PwjnW91bfzpp9hd2h1cs1xrzMBAZQnORevcZACiDzS8LVFsAAAM8dUyiBkh1L9PRnqJhAaxZklDvecOZLCcdsw8d7TNeChcYG1Bcb7x6bqWzPDRzSH+/dgjtrRrHzeTCUuqtQxXJ77XsmALxthH6bFfSyCamClIGjx3ad7bPvzl0QH2ti1OF4Xpb7soSbEYw8FwKFbZ8Grth0Vad9QjaOmaP0ppowoQHAJo8rWBwThP+eQGtuXPuTyOyEhxr0fhGMMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=IqLzhXm7w+Z4S953PqAan6WN230SCZ/ZGpCHh5sp2NE=; b=FsT2V5f95TOnV2QCJnYIxocodzsasSUfeK1vxMooCruyNC6+FZV+3gwKR8AmU/ujlg8uQJuTWjPuaKzknSd4p86DtRV/MQKy0EvVob/hll/mnk9xxhnDyvNh7s/tqnxniz32sUFl28nJQdsoaAXeER9fZfatPSjmum6lvBTHedPC43WzgJzp7ylhoAbHxsRdwUBAQKEZGYkcrKIoHbDBRRrIBuGmxZG9b6if7/Y0E0/EiSApMyNg2JLiykkL9oBunKTVdkCwuCkrZCLJNtXAblfcExObg1yLo6G0ExtYv/FiNRDrZVBkaeJFGk7UY/DXbRmBLsnTiZ3iYDO379YCCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IqLzhXm7w+Z4S953PqAan6WN230SCZ/ZGpCHh5sp2NE=; b=IasY44lkS26oNEmdNqlNRwsIJPplF4Efo762T7UvDqCTKpFny8f1VEAinPIxEkCrJmfVAhR8J2FjX6rwhmC5YEVVRllI4/9MSYnuAeumUFaZwOCs2vUFUGmhJ6UCj2p/BnTkt0J5qWpH9j347h2sw5EzfgXYiwjhZZlSrLmZmD8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) by PR3PR04MB7324.eurprd04.prod.outlook.com (2603:10a6:102:91::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.21; Thu, 21 Dec 2023 16:54:52 +0000 Received: from AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40]) by AM6PR04MB4838.eurprd04.prod.outlook.com ([fe80::95f5:5118:258f:ee40%7]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 16:54:52 +0000 From: Frank Li To: peter.chen@kernel.org, cugyly@163.com Cc: Frank.Li@nxp.com, a-govindraju@ti.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, pawell@cadence.com, rogerq@kernel.org Subject: [PATCH 4/4] Revert "usb: gadget: f_uvc: change endpoint allocation in uvc_function_bind()" Date: Thu, 21 Dec 2023 11:54:26 -0500 Message-Id: <20231221165426.1590866-5-Frank.Li@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221165426.1590866-1-Frank.Li@nxp.com> References: <20231221165426.1590866-1-Frank.Li@nxp.com> X-ClientProxiedBy: SJ0PR13CA0226.namprd13.prod.outlook.com (2603:10b6:a03:2c1::21) To AM6PR04MB4838.eurprd04.prod.outlook.com (2603:10a6:20b:4::16) Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM6PR04MB4838:EE_|PR3PR04MB7324:EE_ X-MS-Office365-Filtering-Correlation-Id: 4927bfe6-e06e-4ad7-0454-08dc02458d32 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vd5K+vbCdtN8PTC7YdHoWxWVNlDokVYUEnJi7d2Q1vRoVJJ9TfJUlLleLSt3KvnwkEisD2nIHhAKmYa6CSaYhoUhn30/Qriwf17SBXRb3YD8brgY3CFWmQOv9EajRcMpo7jBlDsKi6cRHG92zOl/oIN5/7MAD0XsQ7bbG87oeTDo2m+tyHaBllYhjA3PpoFpe9taiurrmBqlJo38tJnyE9y16DfdrBaXzybDhbMu6RxXTeJ+ArNaxKkktHptOGOnSNJ+Re3zUaGzxIIS4BmWrJaO0zYSeIMPA1oYTEwaIvrJJb0iJOS2sxHNzoQy8egVU7taP2675CCACwlwQgr1LQaWn5jmVhyeIBlFJJM54yiauHfgxpVTk263rzkDt/oVtAIyBBR0KDzUAgXDlJlX2Q1j/s9WePWyrP44TtVHC/sk3Z9vFLXzUTsLRRk4lLY7HybF5YujonAd0iSVz5mVxoQl3MXdniIomFSzalI/J2BR1jZo7im8FP2zK0f7yx7TF4ZSSw/WDPfcGlohWPl5QdsqkEym1VGh44Fa8+Zhxs8gw8jRO88byDx+09QWPcXuqM/hNpJ4t1MfpTLCD9MOfwiS+c0HCYXoLjOu1VVws3he6k/jZlsv3edzUEFDSReW X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM6PR04MB4838.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(136003)(366004)(346002)(376002)(39860400002)(230922051799003)(64100799003)(451199024)(186009)(1800799012)(2616005)(6512007)(6666004)(26005)(6506007)(1076003)(52116002)(83380400001)(4326008)(8676002)(8936002)(41300700001)(2906002)(6486002)(478600001)(316002)(5660300002)(66946007)(66476007)(66556008)(36756003)(86362001)(38100700002)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fj2Sab4oPmLafOSZ6T45riIbVP1QZ7RLKkHqmIgtTmtsTfebH6SBmv17DzCdvZPcchx0v+EhRUeWUJbeOm/bwKIyQZTX7h/ggJjxPFyUEALal7irsY3OGcE5P2InlsXhSyuNifcPAEP64urKN7+KI1w/V2kFBWYgtMfXntjYvVTRz7e8mELqxuIZrt7mO2ABrU+LJ7dVDVAC+xIEcKE1GcD7sf2XOr2QHaMOULvJTIo2OCTSsedQYInVHnXniJRh3XkfijL0pViYfi22OZAGxi6R10ZEr6KwWzKjGgDfhjxl0AhEnJ+8b1u/mK/IdX7UrFHZtcHcA5T8ZoKEiiBXnmY0e3J+TRcC94uMZ+gZmwWkWIQNlpPXrxHldmvjmYumh4w7LcCG9isg7SIW0QrMmOzHCCjzu8ZP6uRaGhDSy3jsRMyauZuXLYuBOkIV2m359cQd6J+8YEd2bV4A/ROr4EGcerAaUaQHdzaS4mykti8GybtTAaMUONIZfAJ+O7U1FszChtzc3fdlelwN9gjyDFtWjDjosy2DM1f2Z+ubF0u6xalu2rxCToj05QBsvoqHR+xUCce2+2fv/TJyNnc0nfALrEIOCbpIbKi+j+cfLSkXmlF/NNJhn99VvzJ2g3Brs1oeWa0EV1AWxab8USCeez6LAr+klKsdQX4dA4YrEyNPdAIo265BclT5EQ2lDbPk5BUVGDc0K9pKsCs+YjiABgV4bOhJRd+SWxASiIx8d5zUZ+JWwe7fIHeBJmTWb7BPJs6Z6DZgS6MpGULwdVFFTOJcD30qDwMD2a0i3Ehi/uoy78A1m47HEq/03eoMDouuquPuCgowYO1XwgfvIh6zllpfInCeC3V5k15peXw8H0zLl/l3wKzoSv9BABqvc303gTJp65Ht6SsJ4HfZUu0CWcIWJy8R3PAxpwzhI6NLW2dJj++EPNEnD0UGazy2LPmd7STEdTSJ4S5hkF1A9SE/W7mMPaykxYzeCBgTzCVvsR5Rp6zTtGq+PHKm6swSD1pNhA/M+2wEZ7BebNOQRIB/+4XG48cggeKFFGxVy/np2V6qs6Mpm0CcRUWCnz2N6zWUfLAGxWgVXo2ZS99RFVe0X2yez1lkGxg+TlLEjw8S6p8n0LTMmJPKssPxi5XRe16zTP8RCQCXBEzNPb6vnieTOGpvcoqSKbteySzbGCrGx1eH2+5rQF92HQgMuslQWAPGwovhaayXX8aTZD4vxXX5vKNbHJ/P9aBcJhHoYOIzMGFfVNbU6fjo4sVtX967atxHXAjZhgYWulXLtbtbmc1Lj9OW1Co7GPBYyv3brcf5/bdxKT6Ku9JzvAhnfv09SNKMZdKskjS7knkSg0fMWltp2lluG/e9/4FHiK10pfrUxJZGjYQLbtsUiTPC5Be6EtpbcB/QydCgbnSMyYwYvtX97EHHhvF3MiAZ4DdU/dMge6zSQRqnrEnPUCR25J4mpkNu+6YY9YjUbiJl80qiRRawVsqfk/qxh6t+BQNI/hce9JpUVmoHe0clSdYaCGWaH99Vsbw0bD5HtCEcwK9nfXLwXOK6cC8foswuZA6EjljakgiwnOQDvtuwMM39WuhMZhNP X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4927bfe6-e06e-4ad7-0454-08dc02458d32 X-MS-Exchange-CrossTenant-AuthSource: AM6PR04MB4838.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 16:54:52.5966 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Zbfeu7dtY9yy8jjzuRx9ymsZAHCth4jlcnTtRb+gdDhKGNdzeVUG3icyoLgF8slVBEfVH27DuSJMktXZLkll0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7324 This reverts commit 3c5b006f3ee800b4bd9ed37b3a8f271b8560126e. gadget_is_{super|dual}speed() API check UDC controller capitblity. It should pass down highest speed endpoint descriptor to UDC controller. So UDC controller driver can reserve enough resource at check_config(), especially mult and maxburst. So UDC driver (such as cdns3) can know need at least (mult + 1) * (maxburst + 1) * wMaxPacketSize internal memory for this uvc functions. Signed-off-by: Frank Li --- drivers/usb/gadget/function/f_uvc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c index faa398109431f..cc4e08c8169b4 100644 --- a/drivers/usb/gadget/function/f_uvc.c +++ b/drivers/usb/gadget/function/f_uvc.c @@ -719,13 +719,21 @@ uvc_function_bind(struct usb_configuration *c, struct usb_function *f) } uvc->enable_interrupt_ep = opts->enable_interrupt_ep; - ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep); + if (gadget_is_superspeed(c->cdev->gadget)) + ep = usb_ep_autoconfig_ss(cdev->gadget, &uvc_ss_streaming_ep, + &uvc_ss_streaming_comp); + else if (gadget_is_dualspeed(cdev->gadget)) + ep = usb_ep_autoconfig(cdev->gadget, &uvc_hs_streaming_ep); + else + ep = usb_ep_autoconfig(cdev->gadget, &uvc_fs_streaming_ep); + if (!ep) { uvcg_info(f, "Unable to allocate streaming EP\n"); goto error; } uvc->video.ep = ep; + uvc_fs_streaming_ep.bEndpointAddress = uvc->video.ep->address; uvc_hs_streaming_ep.bEndpointAddress = uvc->video.ep->address; uvc_ss_streaming_ep.bEndpointAddress = uvc->video.ep->address;