From patchwork Thu Sep 10 09:11:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11767171 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 044C692C for ; Thu, 10 Sep 2020 09:13:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C11DB20795 for ; Thu, 10 Sep 2020 09:13:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="NgIkZCjm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728207AbgIJJNJ (ORCPT ); Thu, 10 Sep 2020 05:13:09 -0400 Received: from mail-eopbgr40061.outbound.protection.outlook.com ([40.107.4.61]:49482 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728971AbgIJJMb (ORCPT ); Thu, 10 Sep 2020 05:12:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h/2f1RD4Jo4iBdQYq4RCc9sZmhfi/bsMT7IFFrIHoM0QhNJNpqguMVZYk8kaA21g9EmPXOZORpMQpkztRrLnBniP3Wi6StrZ2eMUG70uPzIrix7e4qq0k1vDdezgR5zmMjqZP5JnQIG6EjqIfOxbc3sZuUBMhUCHLCrctZA9mI6l+BSvVbH0CCY4SkzhijB4Ukh94X8aebxQmKtQxrKkzFzRxVcC0Hun/jdxZfv+DVt2Qx13ZB2pHex95njCOfkCuuryg1yoVJDl3JFlDH1co7CqATplzQ9uv3h18bckzhUuXWW4g+0y/ZZv6MxD+Bw13y5pvaqBy47smOjfBcQOyw== 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-SenderADCheck; bh=Fhd1nfUR/aM26kdw811nX6X6ELDjEG3KUoF/PV/N8Ig=; b=GkeA1znK7FI7OPqjSrnYe1BUUNy4jVFNiTuONwG+vnP2LVQtGDz1+d33Uy8JzPUmN61+bW5x1/fPrNbgvHdPi2cTFrhaEwh4XiOcFrgYchcmV2MW2KXm9KGBbGvRk4/3YltyJBE55Didaf/5dFiAmmQvNautTggmEmwNgZ3rQqGS+Wb7p0woRio3MeLZQdypXZPWpEltSK9WwlrdaJ77he6P3uKNyCYFAlk9bBXNmeZKFEABBd23nMFI73nRTt3DasgZ3pJvzxId0RyxbOlPAQ2bZktWPHuM0boYWa4WbTF5C9lUtes0P3cCMCDZlyUS0DjmtAMO8wR3qxSOOIGZZw== 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=Fhd1nfUR/aM26kdw811nX6X6ELDjEG3KUoF/PV/N8Ig=; b=NgIkZCjmnPsnGntmfvFFiWCJUOD4gsM7GMSafOnvKoKeaX1oM6iwbPs7I3IWJJaRNlrC19reiJaRPqea/l6hJeauku+5YCTvY5UephFJJ81F5jYu3ui2inoJpUYEmyJiOaEfR1Y2Ypk2M62Vh06decmgyLuQjdKFZ8s9aga5/WM= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM6PR04MB4168.eurprd04.prod.outlook.com (2603:10a6:209:43::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Thu, 10 Sep 2020 09:12:16 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1%3]) with mapi id 15.20.3370.016; Thu, 10 Sep 2020 09:12:16 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, pawell@cadence.com, rogerq@ti.com, gregkh@linuxfoundation.org, jun.li@nxp.com, Peter Chen Subject: [PATCH v2 1/8] usb: cdns3: gadget: using correct sg operations Date: Thu, 10 Sep 2020 17:11:23 +0800 Message-Id: <20200910091130.20937-2-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910091130.20937-1-peter.chen@nxp.com> References: <20200910091130.20937-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:12:13 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.66] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4a687e53-3d9d-4cab-4736-08d855699cba X-MS-TrafficTypeDiagnostic: AM6PR04MB4168: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:255; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wxQqiPUl/cyIeOzdffzUQRuw8MEko/mzgcuYuy9ITkHgph1/QVu/byhOhCSgMs6bABocAuSPtuAI2TYMmlItXAvE02PjRxbZq20dWy2qxAxAnlrUnZZA1PtxS8CLUiFrgdsFNnAo3ehu31wyPdf5DBcS9DLa6uD0nw5FUDc0Ei3xVQ/yF3R19jnQLyrInyHzui9kECR6OKIpY9T/BSR5y/NZ96QZjv7VsNIuscBw0pi3z1+1LfUBam64NOMB5BZfZBRn9M65RQOCQocmCo959q4Jatc5bgii0cMHu50IpzVx9/Qhsb0T6GMr14ho2vl3 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(136003)(366004)(376002)(4326008)(6512007)(83380400001)(186003)(6486002)(16526019)(36756003)(66946007)(66556008)(1076003)(8936002)(66476007)(52116002)(26005)(478600001)(44832011)(6666004)(316002)(2616005)(2906002)(8676002)(956004)(5660300002)(6916009)(6506007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Fs8JacUkdoF7MPJcGKaz7fLyLqu+uBACW4RBfApdR3Q/QcWJ8sCwgj6I6i/71xCru3Pk10BTAwUOiRmJB4zCxedgDvNLB/X4Smi22g81wesVVcSBUNomxzzPdh5fbjTwCYuUUppcfoftOoyTXAqUi8SSNpupuHks6caE+xjEcQ1v1OiV/qWpIIGfUkD507ck+6jL0SBzwsqIiKW5A4eeQH9VJlttqWBaDd1bp09UCrgXrOaj1QUep6IUsXbl+yv6cBlUgjazxpdAXw8zBRkcOutMVvgHXvLi9X3Ba1FA8tr+J5/DbQvUKd7ZHzbThCZ8DTrErZ31u/NxJ4328OPUhDyc3B7p09tJ8Nf95+o80JLwRTZE/D6AQns6CLcdkHJHWkyQM/tFHSpXh4P6F4LjVStJBj6O0x2Z9dVtirp1ulMYw4EarouQBy3kNHrizX0Ln6DBU6GGslgDmVfP8ZAWQgnWI2CuhPmk/7m7M9QYbZ1L7uvSWutB2/6C5kgnFUsCu/o9IlOeoqHD93JeLDn3M8gFAVY5uRowA6PQLqbmdX4JpK8FUAHA3XxFtSZJoHiensmN5UU9aV8Iua6gKj/vKFv9JvInO/zMV8CuKwX3hK4l3v/+w9i3Xquj7n21LUAorLNY6Rn5oMmgqpAoiwyEQg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a687e53-3d9d-4cab-4736-08d855699cba X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:12:16.4117 (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: fKxXRVp6p7I5eSfwi24PZYo6IyGcJ4+YPab8UgYYi7dolzzC5RMB6A5WTaKSP/N0xqW6L7FuFGkDL2B6LhjcDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4168 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org It needs to use request->num_mapped_sgs to indicate mapped sg number, the request->num_sgs is the sg number before the mapping. These two entries have different values for the platforms which iommu or swiotlb is used. Besides, it needs to use correct sg APIs for mapped sg list for TRB assignment. Signed-off-by: Peter Chen --- drivers/usb/cdns3/gadget.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 2ea4d30e1828..2d6dd6896937 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -1098,11 +1098,13 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, u32 control; int pcs; u16 total_tdl = 0; + struct scatterlist *s = NULL; + bool sg_supported = !!(request->num_mapped_sgs); if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) num_trb = priv_ep->interval; else - num_trb = request->num_sgs ? request->num_sgs : 1; + num_trb = sg_supported ? request->num_mapped_sgs : 1; if (num_trb > priv_ep->free_trbs) { priv_ep->flags |= EP_RING_FULL; @@ -1162,6 +1164,9 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, 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; @@ -1171,13 +1176,13 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, /* fill TRB */ control |= TRB_TYPE(TRB_NORMAL); - trb->buffer = cpu_to_le32(TRB_BUFFER(request->num_sgs == 0 - ? trb_dma : request->sg[sg_iter].dma_address)); - - if (likely(!request->num_sgs)) + if (sg_supported) { + trb->buffer = cpu_to_le32(TRB_BUFFER(sg_dma_address(s))); + length = sg_dma_len(s); + } else { + trb->buffer = cpu_to_le32(TRB_BUFFER(trb_dma)); length = request->length; - else - length = request->sg[sg_iter].length; + } if (likely(priv_dev->dev_ver >= DEV_VER_V2)) td_size = DIV_ROUND_UP(length, @@ -1215,6 +1220,9 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, else priv_req->trb->control = cpu_to_le32(control); + if (sg_supported) + s = sg_next(s); + control = 0; ++sg_iter; priv_req->end_trb = priv_ep->enqueue; From patchwork Thu Sep 10 09:11:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11767169 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03D2192C for ; Thu, 10 Sep 2020 09:12:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CED8B20795 for ; Thu, 10 Sep 2020 09:12:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="FuP6cLoZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730082AbgIJJMl (ORCPT ); Thu, 10 Sep 2020 05:12:41 -0400 Received: from mail-eopbgr70080.outbound.protection.outlook.com ([40.107.7.80]:35972 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727830AbgIJJMX (ORCPT ); Thu, 10 Sep 2020 05:12:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gh/RCexH003wLdyNDyFBuKy9SNvk0M3KRv3cR6MHZeNL6khvFpfw+6bcvx+33I1yTEebSZb7357bXbuUx51DST/+Q5niPW9VrlRmMVOZR0oFP/Xiqj7PgeJ4j2YPlegIqDdkNu+592BeXbVpL1ZpRaMYtAm6bAuE1pgAyB51cLACWSHMH3Wtr0Awh+cmtiaAGRiBpq5qoN+Tk6Swo+tZEzYTrlKxwFyp8zDX4NvepOmVLBAHMLLDo1t7agomMkCnIyCAMvpdfw2X/hbVeihZfNHn+Mdu8ZRObSeZfJUOHJlc2jokosYNJg7ubWV9Pp16OxYqtbUeTqRrwGpZcaaftg== 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-SenderADCheck; bh=266tlUmODVkdkh6EJmvdr3/HwYf9TNVafTHakNqFGFw=; b=GOBOr1YIRP0+7A3nmgSx+pMJNzBbAekpLjagWx6EUlwekfy2GjNSi7gijRN407ur0xPudSWmhzxTuKQ9rcrUnIshKb9+X0SXkZAM4LH1csr2fa/1gaZkFgQuaUdBytIYD26Q8/Jzp6AgoQlkysI7ElPdLcCyHrngCTFR3PFnHUKHKX7/mvXSpnOtMuIdtgyrdTR8ScXxkjnfAO4KOre+m8MhLjf568ZMy39oGP+Z1+/U9D1ENvvTiMcCCgVZZIl9ryVf6PhCnMjkwJhJbIjCJfOmPBmN3h8acwYiWGOIMvaDl0wD5F1ulsQeOYqAVf5BI7uHyVBhP2rLh8/0iQrZtQ== 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=266tlUmODVkdkh6EJmvdr3/HwYf9TNVafTHakNqFGFw=; b=FuP6cLoZuTCXrPEWeiM1pKzIKSWIJQ1Z5zQAEy+QqPS8pN4oOOR0DKpR/PuWBsxE5AUtWfSvxryf3sWM92goBcXGXF3SUF0/64L7SMrlv8t3LLMumCVgwgL7AWJIvEMOIMPzdO0vndGXzZxc94CTqqlwoTI4My0+LqT3U0pLcok= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM6PR04MB5368.eurprd04.prod.outlook.com (2603:10a6:20b:9c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16; Thu, 10 Sep 2020 09:12:19 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1%3]) with mapi id 15.20.3370.016; Thu, 10 Sep 2020 09:12:19 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, pawell@cadence.com, rogerq@ti.com, gregkh@linuxfoundation.org, jun.li@nxp.com, Peter Chen Subject: [PATCH v2 2/8] usb: cdns3: gadget: improve the dump TRB operation at cdns3_ep_run_transfer Date: Thu, 10 Sep 2020 17:11:24 +0800 Message-Id: <20200910091130.20937-3-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910091130.20937-1-peter.chen@nxp.com> References: <20200910091130.20937-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:12:16 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.66] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fda2ea5f-cae0-48e5-b54b-08d855699e6b X-MS-TrafficTypeDiagnostic: AM6PR04MB5368: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:383; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XlNJANJCZYKl3dPvGZi7IyZFCxIS8PBeoUpxBosxOiekWFdoRs99upTC+H4Q6fqEIRabakSDn6BRmQV0AXDqlcBlI2F4GL0M73K02Pm62C4y2sNpod/AeeV7DiOpH9P14rGGh0ETVZyotzBt5F/gwJmr6JF/ImHpiegmzzqWTUXtes2od+CV52uwfMD5HSQ/tXjfmqPD1kBKc/rePMSbMEkeEqmTG9BSoSNyZAqrh79a0FudHoxchNJMgLPeWMfZpv/XpvwH/IKvng0/IEgDh5GwpTFmocbi9Nf321y6dFf+b4smADQwdfpKyIQLyPz2p/rnZVRXcPNhWbOpLozu4g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(346002)(376002)(39860400002)(396003)(136003)(366004)(36756003)(2616005)(5660300002)(66946007)(66476007)(8936002)(956004)(83380400001)(66556008)(44832011)(316002)(52116002)(26005)(6666004)(6916009)(2906002)(186003)(16526019)(6512007)(8676002)(6486002)(86362001)(4326008)(1076003)(478600001)(6506007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: hxu0pTOGi0V4OUDIG9TRnHgIpLid9gfh2MVz+U9CeBMfIV+iS8ZLg7h6icwWQqRiNVg9WVebEwpH0Ukd4B3BCobcS1ub4DBbFLO+bTdcbfSBcXDBJT36FCQkU+i3Z20psDhr7xdLN7GMdU2B6nqRhhoHFzzmx9E7zID6q4IYFj/NPOWQAYSlBk79KQcuL9eAX+aeZ8BvXqQksVjGJ3e4bYf4X3LBdZ5WFefCqhmlO8nV2+UbfA8YbJXh0ns7EUGLtySwbQ/X0yJvaax4m10GxWrpDrGeT55fq0l0I5crCDwf2B389ueos6DLfSFpi3A+NF20gD+9ACoRnVpFxDiqmO1hsNDb/qxW0aDNY9OWr6ihmI9ZbvibfcKvpOdL2rQZNgE/Xv6Bh3BTXQ7M1MEf/pgxjLcuaqt3pOrkEws3oFxT/I/Nl3sB33xGYAPZRdZ5z5ETGGWyttebDwQH9/0JiieGwdti4foPc+PsYGEz8exCBOrUu0YEn3zkunafEAk2S2OXYW2NhA4AOxYoKdSYfV/FyWSpa3YSczHOgv0dYkiWUxHJR3xbWeQGMoSIW+0bAo6EFdevU8FXBLxb1ekXGkgUfDV4w3jP1VxkbCeL2+vQC4BzsRvGJhmMQrqehe4gcJgxf2NelfVi0lnz1kyuRg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fda2ea5f-cae0-48e5-b54b-08d855699e6b X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:12:19.2363 (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: 7/tav9tsPAq65TuRcsnmLQtUOqqp1blrutLADDR6WlQsvy3/B6jHmsnpRTblMQCwSj3+2o5KvpEXaCKiFBn6ig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB5368 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org It only dumps the first TRB per request, it is not useful if only dump the first TRB when there are several TRBs per request. We improve it by dumpping all TRBs per request in this commit. Signed-off-by: Peter Chen --- drivers/usb/cdns3/gadget.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 2d6dd6896937..d8eb5b1717f8 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -1090,6 +1090,7 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, struct cdns3_device *priv_dev = priv_ep->cdns3_dev; struct cdns3_request *priv_req; struct cdns3_trb *trb; + struct cdns3_trb *link_trb; dma_addr_t trb_dma; u32 togle_pcs = 1; int sg_iter = 0; @@ -1130,7 +1131,6 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, /* prepare ring */ if ((priv_ep->enqueue + num_trb) >= (priv_ep->num_trbs - 1)) { - struct cdns3_trb *link_trb; int doorbell, dma_index; u32 ch_bit = 0; @@ -1266,7 +1266,22 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, if (priv_dev->dev_ver <= DEV_VER_V2) cdns3_wa1_tray_restore_cycle_bit(priv_dev, priv_ep); - trace_cdns3_prepare_trb(priv_ep, priv_req->trb); + if (num_trb > 1) { + int i = 0; + + while (i < num_trb) { + trace_cdns3_prepare_trb(priv_ep, trb + i); + if (trb + i == link_trb) { + trb = priv_ep->trb_pool; + num_trb = num_trb - i; + i = 0; + } else { + i++; + } + } + } else { + trace_cdns3_prepare_trb(priv_ep, priv_req->trb); + } /* * Memory barrier - Cycle Bit must be set before trb->length and From patchwork Thu Sep 10 09:11:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11767173 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E712C92C for ; Thu, 10 Sep 2020 09:13:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C2602207EA for ; Thu, 10 Sep 2020 09:13:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="lEz8yxG4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730181AbgIJJNO (ORCPT ); Thu, 10 Sep 2020 05:13:14 -0400 Received: from mail-eopbgr130043.outbound.protection.outlook.com ([40.107.13.43]:44418 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727075AbgIJJMi (ORCPT ); Thu, 10 Sep 2020 05:12:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P9N9vnTkuGXeL6TDxDlrd8T90gPEZbba2+RRkkX1I/pbMqEyOQsLA0+ymvLdU/zWOgHlMM06iiMYqUKgq48UCUT5zcKj2YajCXJ+rVyLGKFLLVEwZw91UxkK2hG0sWCT+kKjdlhUGO/Sj3nIt8bZibFfUeunPcVbbPJyMULMcKE3pAkSSaa/pLNjlWgnS5WjIzkjBuX8u6uCCnX8ynxmlQB81H4CP+Q0jLlvvLAtRliPLTsKs5jXgXJMT+GNNdzfErwQpS9olYHRBn8JDiyVggfeJAAka6iGGf9F/rIpeihUbGLW2FUxX1DW4XvHA7NL8k0kOWLB1ST11ZYO2/Ukzw== 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-SenderADCheck; bh=Kzhd1u38yKj1pgHVDsxh4YBmcOqFwJKaOu8dAmxUddE=; b=bcHiXs2yI9NGqBPGK0BJrNvZfjatQE/FBH1SHPUHpNZiVfSmdo1NCixLbdMB3LovbHDn4tUo7HyMYSJTn7CTN4PrqivpsitytySL4KNuG7LD39LqfWZvGYRj7WgG8ulqdrIl74mvd/VixtfbYCTcZODjW2Q2q8Qry6w18yYDRlgZT5nkjZcyeEwBqboe0nNVvIvTnAnpE3YHQvsN7NqcD+8g2qqee37oFgRL+aZ1BupI/3QNFal11/3QuF8TEhmzhepTLt7QDoB0naQbYJf5d+N0/Vhu9mksQyHbGk+/KaoBWF0P77wLWjnVa4pSg8SJy5GiL3RyHIJ0Pbe6Z5GrIQ== 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=Kzhd1u38yKj1pgHVDsxh4YBmcOqFwJKaOu8dAmxUddE=; b=lEz8yxG4Pl54abfILuQdbNwsCytVDqTDmWNlaQBrgnwiSEJC7QrZqMlM7kSYY70JijWU71H2c0ZGQ+jjmgUhcfuca4zuhHOKAkRHt0jV51pFXwfztMgb59iJ7hT55P140+LfPC3M4gYiJ+pyuRLEf6DF1xAYbaP+XL7UfnA3PrU= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM6PR04MB4168.eurprd04.prod.outlook.com (2603:10a6:209:43::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Thu, 10 Sep 2020 09:12:22 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1%3]) with mapi id 15.20.3370.016; Thu, 10 Sep 2020 09:12:22 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, pawell@cadence.com, rogerq@ti.com, gregkh@linuxfoundation.org, jun.li@nxp.com, Peter Chen Subject: [PATCH v2 3/8] usb: cdns3: gadget: calculate TDL correctly Date: Thu, 10 Sep 2020 17:11:25 +0800 Message-Id: <20200910091130.20937-4-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910091130.20937-1-peter.chen@nxp.com> References: <20200910091130.20937-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:12:19 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.66] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b1f1c657-d90f-4cb0-712e-08d85569a01d X-MS-TrafficTypeDiagnostic: AM6PR04MB4168: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SeQ103sh05be4JD4YGnVeHkV5cnV4IB4xpM+1ue5iWx3ZWWYuQ7/fQwKWugudTVM1s96RHBWebGBqgXX0rnrE83KtkHG6+iLFM7PWx9fZwOP7tBhxSDgmHi+xzmYC+5ZIy8hdIXVY43pI1T9AAAjtry7CHpL2DZRItr8R3B1Jc7CvrODatckoICjJfZLt10Sa5LK2bvytbtthm3i+sKwK3XnttLxu9KPAKtAUSpDOs/pTdZYlhdcVI+FK0F/JFG8v9kkwNn19pl5VP5EcjHbK0EQ3orGtK4zNoOAXw0bj6z83dlKh1uGf5KWOaeC5wV391Q4QCxVgQd8DRlmJoiG7A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(136003)(366004)(376002)(4326008)(6512007)(83380400001)(186003)(6486002)(16526019)(36756003)(66946007)(66556008)(1076003)(8936002)(66476007)(52116002)(26005)(478600001)(44832011)(6666004)(316002)(2616005)(2906002)(8676002)(956004)(5660300002)(6916009)(6506007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: J/jGpAPGuyXFzHFznsCTH0/zehqQFoKmOwMyr7/2/dC1Wo46RqZfv0iMYexSqwGdJno2YAjBFtcpdGnpzQ4hlpf7skWilZCFe86LMok+yucW/td4qOxhJevAM7IJXS4/rzhJWeuJKsISplCsLG/98jdSzTm2oVKWyaOhmto74bz0ubM2td5k3SQRWI458i8Zu4QraaLsw9+oSEuHmMZ6ZMh3rW29R1brl2tOIknBqw+ghC4f0PvPgzUBSi/kuCv7Sm8/DM7+XErUwid46kFpCfqYCUUbjocIw3KH33fMV+bAimo8tx3dcaVVaoEba+IyFjmkMlYgcifckGGmnKoJX9P0mjMDTUGp0emRNj06cK4Hw/naaNKULaSx81CaUSWR1Ia9Dj8YzEbcapARJZtPFmbhQhfftOOw+1A2cpEQTBZXlC0i6UNC35bHHaLI+y1xwgyGG+8UonXTBZgH2topLXOfIhpbxWmuk0Zcd+dv0Q/CsIuSvZ3p6vzIGhatmkzje4xFfB0WQ4rreOUUL9j/Huc6NymU+7HjTpJZSmYCK2pF19MOMlZlfe4b8ZOZK66OXvV7HurCH+g2nbccu30ILpPKPW94Dbp3NDk8AlXdc3IaM+PQ32vXKeC42dq1lSaNh+WhG6e7NnuX3IRMTEp4vg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1f1c657-d90f-4cb0-712e-08d85569a01d X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:12:22.1187 (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: F0QaFyMXa33bpjq9O2eabERu03In15NWAjeq1kwKj90r7osnISBE2pQ/T0Vj+stI5S6NSbs1JanzWGXgicR2nQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4168 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org TDL is for TD length, so we need to calculate this value for TD (request), but not for TRB, the TDL value is only needed to stored at the first TRB in TD. Signed-off-by: Peter Chen --- drivers/usb/cdns3/gadget.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index d8eb5b1717f8..f1626df65255 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -1101,6 +1101,7 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, u16 total_tdl = 0; struct scatterlist *s = NULL; bool sg_supported = !!(request->num_mapped_sgs); + u16 td_size = 0; if (priv_ep->type == USB_ENDPOINT_XFER_ISOC) num_trb = priv_ep->interval; @@ -1169,10 +1170,17 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, /* set incorrect Cycle Bit for first trb*/ control = priv_ep->pcs ? 0 : TRB_CYCLE; + trb->length = 0; + if (priv_dev->dev_ver >= DEV_VER_V2) { + td_size = DIV_ROUND_UP(request->length, priv_ep->endpoint.maxpacket); + if (priv_dev->gadget.speed == USB_SPEED_SUPER) + trb->length = TRB_TDL_SS_SIZE(td_size); + else + control |= TRB_TDL_HS_SIZE(td_size); + } do { u32 length; - u16 td_size = 0; /* fill TRB */ control |= TRB_TYPE(TRB_NORMAL); @@ -1184,20 +1192,12 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, length = request->length; } - if (likely(priv_dev->dev_ver >= DEV_VER_V2)) - td_size = DIV_ROUND_UP(length, - priv_ep->endpoint.maxpacket); - else if (priv_ep->flags & EP_TDLCHK_EN) + if (priv_ep->flags & EP_TDLCHK_EN) total_tdl += DIV_ROUND_UP(length, priv_ep->endpoint.maxpacket); - trb->length = cpu_to_le32(TRB_BURST_LEN(priv_ep->trb_burst_size) | + trb->length |= cpu_to_le32(TRB_BURST_LEN(priv_ep->trb_burst_size) | TRB_LEN(length)); - if (priv_dev->gadget.speed == USB_SPEED_SUPER) - trb->length |= cpu_to_le32(TRB_TDL_SS_SIZE(td_size)); - else - control |= TRB_TDL_HS_SIZE(td_size); - pcs = priv_ep->pcs ? TRB_CYCLE : 0; /* @@ -1228,6 +1228,7 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, priv_req->end_trb = priv_ep->enqueue; cdns3_ep_inc_enq(priv_ep); trb = priv_ep->trb_pool + priv_ep->enqueue; + trb->length = 0; } while (sg_iter < num_trb); trb = priv_req->trb; From patchwork Thu Sep 10 09:11:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11767175 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B689192C for ; Thu, 10 Sep 2020 09:14:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92D2E207EA for ; Thu, 10 Sep 2020 09:14:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="JIx/WF81" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730150AbgIJJNx (ORCPT ); Thu, 10 Sep 2020 05:13:53 -0400 Received: from mail-eopbgr40061.outbound.protection.outlook.com ([40.107.4.61]:49482 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728443AbgIJJND (ORCPT ); Thu, 10 Sep 2020 05:13:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vl1QAt1craqjJejf2PPwEP2X2ZaR7smpMbh5pDNULfhkH7Tu7QFL1kq01IuetQav9rSX6HLhf5Vx1gdsHPxxDZmBxxbKXo8zctx536r4vEynMHC9wTHq2Un53p8Ko7ItjLEhjmy5Qn6PL7fGEmYFdNAExhbFh7blGazb4I0eXU2qJDAI0Cgr8OZ3tqQaFyNIowf3G6leLGsZilzDWqYCZovWcdlUAJftTZOnNE4/KwWxArP84BvUxOkb6lr0TNlMXimeYWVuh7BkaZ9EDnIuFNW8SaBs4rpKXkjcywJUEhaV05ERYo8W+PhNktd+odCb7IrUu1NiEUGr7irNu9KOgw== 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-SenderADCheck; bh=W4TZoScKIhA3wHDVBEv8t+9wFAZ8+SpzlYPT4lZ01TU=; b=K+22WNJAtSM967OJlvxhdcfpflrJvTCA2PD5NZ923qWk8ix+TGgWksQe+YAQIB8NLimheOS3qt0hfag5FDuCSUlq/hzn5KjRY+wW9rWIPrjprtfm7H7UKG3wAlZhTEei7MsICcyx2mzEos7HlNIXD1vMYffgsiu4Zgr87zXron85JzLJ20GlX1IuX33TarlSgVdp4DqSJatDu0VpufgN6ZR49lnD9GAVgrKkOoLrRG4M2SMW6YRUl75F+fdRCcVHn3agZjHVummELSuirgH/2pCDA+o+VBPGH2v9XS2RE1EuZ+5oaJbwImtyi8tUEQyW+M4Yu3vS9fGAECiFCTBt+Q== 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=W4TZoScKIhA3wHDVBEv8t+9wFAZ8+SpzlYPT4lZ01TU=; b=JIx/WF81EgLQyOdXDQc0tuD4Fm91cCKeWbuS4sFUC5tICQZoaS+NgqQMXf6/N4f+wNoR57dxa1OgMBam+0JZDk36W+/nOEaKRA3egiN+5HpHqRPXFJbUu37z4MpaZtZ/3spnQDIlrcd7AgS1wXF4Y2eLoS6XOslRzOTd2a8AE8s= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM6PR04MB4168.eurprd04.prod.outlook.com (2603:10a6:209:43::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Thu, 10 Sep 2020 09:12:25 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1%3]) with mapi id 15.20.3370.016; Thu, 10 Sep 2020 09:12:25 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, pawell@cadence.com, rogerq@ti.com, gregkh@linuxfoundation.org, jun.li@nxp.com, Peter Chen Subject: [PATCH v2 4/8] usb: cdns3: gadget: add CHAIN and ISP bit for sg list use case Date: Thu, 10 Sep 2020 17:11:26 +0800 Message-Id: <20200910091130.20937-5-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910091130.20937-1-peter.chen@nxp.com> References: <20200910091130.20937-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:12:22 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.66] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 78376ace-9890-481d-203f-08d85569a1d3 X-MS-TrafficTypeDiagnostic: AM6PR04MB4168: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:327; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AAnWt20YAS6ok4HbPwlzaixkoFfa/DVIPJrpuIhYIaPhuZUS3fGcZRCgakDU7bKjx1n3MtfoYk3j1TrI6tETMcXPtPXB+wjdZCmIHv9IGDE8SiEF4ovVpP22ovS2qIaqkHkKn+URu3+5GqsOe5hZh2Wrvj5FM/wXBjcZsA/WM23voNUxvNbnI7O47c4vtKVPa3RHOUXv872jGc9IFsySert6eVTD0BI7wG8fFbwhfpT+B/Ps1cm+lakgFh50zz33JWf0yu8ALbr6unECYjvSlvWlIUJl7HpE7xRjLDJuh9PLgHrQcAOw+bq0zkQbW1xpInKTN6W9Fknz/Pp5A2UAaA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(136003)(366004)(376002)(4326008)(6512007)(83380400001)(186003)(6486002)(16526019)(36756003)(66946007)(66556008)(1076003)(8936002)(66476007)(52116002)(26005)(478600001)(44832011)(316002)(2616005)(2906002)(8676002)(956004)(5660300002)(6916009)(4744005)(6506007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: vMRnL6mxk22qRSQxDUUhSCV5xvbjSdGzn0SCEzx4FPOhj8dOR8AuZ+Ix9g2WKpFP+uLcINptXniM0Mm2lr4f8mcN1uFtS/fEehuwun/sge1dNDxYv8Lhl+AxMDip+BGqY/3S7ByQXr7gUsfXEcOKbnxYZvThLgCqpUjC0rsD+InWvYvio1JGTIcjAxgPRgQ7u4FGrLySUeSdMMtKgTgAV2vj0EcAGRO/NBrPdj2cXy22lpfe5lOyQlLqqSFv5iWSDG2euheMVn3BspFKq9mo36F6ma5GZmlQMuX72q/XIipgb5fxrNvh3hz1TLixgap0olLXi04ttl/EspGmw9AbSqnHEB1h9V4qlp58nqD2v43Lil6Nnz4yguVnHrwVzDK8VvkFIYMkGuKKw3PQVynj0eMGcP1TEJZXmPm3tCQdePveLwogCERfBB123JvN7YMTyGiC0qILPg74UEXMlBlKcgdtAZN/WMaK1KAtb71+oKdy9MlpX/Qa/peJ1wchJzkPx/NvUbU8qMpqJUaE730mWZGcKtTnOg2HIA4PdSr0u8X8LRTSpy5aAJgLTazSs3bNp+76SS82+obPa1y1YmqX58T2ZtXqeZ2e2nHS+n5F5OvWqNE84lxMOycKVQaY5Sb2iSUcoPZjMxzeRpsNeup3dw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 78376ace-9890-481d-203f-08d85569a1d3 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:12:25.0717 (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: a/diTPMN2jnaA6Pw4DIls55LHs2QQm3e/E328q3ezpGowcLNirkzy85db7Kb77vQTWTQJq3MIwYpRXRuujUktA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4168 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org For sg buffer list use case, we need to add ISP for each TRB, and add CHAIN bit for each TRB except for the last TRB. Signed-off-by: Peter Chen --- drivers/usb/cdns3/gadget.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index f1626df65255..1df4ee2857e9 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -1220,8 +1220,14 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, else priv_req->trb->control = cpu_to_le32(control); - if (sg_supported) + if (sg_supported) { + trb->control |= TRB_ISP; + /* Don't set chain bit for last TRB */ + if (sg_iter < num_trb - 1) + trb->control |= TRB_CHAIN; + s = sg_next(s); + } control = 0; ++sg_iter; From patchwork Thu Sep 10 09:11:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11767177 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90D5592C for ; Thu, 10 Sep 2020 09:14:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 547A020882 for ; Thu, 10 Sep 2020 09:14:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="fGqlE5y8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730165AbgIJJOJ (ORCPT ); Thu, 10 Sep 2020 05:14:09 -0400 Received: from mail-eopbgr130043.outbound.protection.outlook.com ([40.107.13.43]:44418 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730177AbgIJJNN (ORCPT ); Thu, 10 Sep 2020 05:13:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LK1GVfr7yjpbI3zIFLp/6KI88YuzLIsWQwzk6xKmb33xUqK7GOAup9aaEccfWJjUqUznFDhZ/iIieKtTuqM5JLr/pSVOqEDd/qTioRih2IYK6+bZFUQZ8GTE10/EkDCovATy8T1rcar+iketGcUMw/8nfH/DB8Dd/I69F48bPMKhNzL7kR6HYiP4ntQL9fRBZu7t8AAUzbJoIbWdBkc4/muJwtJlbw0f5bo5ywwZvAdjY/A/c7v9noKkUmzyZHUeqElsAytGLoi+QvrAkBrh7JPHy+GfowYvmTrYI/v3JxJx/wwi11cGGVxclUgPgyxqjtrCDlrKSE7W4VaBlW92+Q== 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-SenderADCheck; bh=gTZmjZWNMZCjHBPHg0BPqkvhJxm5r5BxUflKtKkFW+0=; b=nqibcxjh2DDWqtYQP/+Zxac2JlmEHZf6fHhXw6SJJ2aD+4Mlspw8++gsstWHtKpuo7TFJRHmiuNNJ5OweGFF5BDm5Y0cfVrXRzdOESQS+647akQcVkVKotrtDLeZZvuPtgDHSmBHC0PmR6RGHuKMDiUF0txD/o54tEtDovnf1dIwegvC9U9TGA7my24RKmlwEsqP+SdmS7FPGeljVkpK/h0TOK9tDEWZPgVSoM0sScstAyQAoSGYMM/qouqncb5VXuQfQsmlWxcYLezPtj1QzoY1tjAuXVHG7N4i26sttnrV1BiYhJd1BzXAzS6zp42HxaUDxpO3wrLv97EN6Iukbg== 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=gTZmjZWNMZCjHBPHg0BPqkvhJxm5r5BxUflKtKkFW+0=; b=fGqlE5y8iSZbHzYf2QUsRxAOnHSL0rispQxJ5czz2urBeqOK8vUXziPll8CNsEFTueYCcj66GEcyI/gdDXOJL6w+bE2OsnAMwf3YQQ90+V94b8GEiQy09tkQUH9yZ3fuAlEZa8d6XQxt/YrLLWgLpxxFDKuHQLj6Er6t/yyzFt4= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM6PR04MB4168.eurprd04.prod.outlook.com (2603:10a6:209:43::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Thu, 10 Sep 2020 09:12:28 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1%3]) with mapi id 15.20.3370.016; Thu, 10 Sep 2020 09:12:28 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, pawell@cadence.com, rogerq@ti.com, gregkh@linuxfoundation.org, jun.li@nxp.com, Peter Chen Subject: [PATCH v2 5/8] usb: cdns3: gadget: handle sg list use case at completion correctly Date: Thu, 10 Sep 2020 17:11:27 +0800 Message-Id: <20200910091130.20937-6-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910091130.20937-1-peter.chen@nxp.com> References: <20200910091130.20937-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:12:25 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.66] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8697f3ec-050b-4579-8567-08d85569a399 X-MS-TrafficTypeDiagnostic: AM6PR04MB4168: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NVCEm3jBslzA/baqy4xxGhkCE4GHiDM4VPrIq7wk/mNsTnnAuasRbsCWow1LH+AAdwDocyVL6tyGSwZIVEaF9w6Osq64usdFikBLq+MIuWbdeJEjqHlVDYIfOhAOpNV/cP8RoMrYm0jmr6q4p300K73TFsT08P7o74ORHkr40ztFhNEBT5L5ACdVQZOfhvv7gVoPxPEFzPoLFa7bXyB3aqkfeIkMfnh4Lg9wV4oRJcLhCfxKRqZ5T3Nw/lH+tfF/Pc62MQ0PoVfr8XzBWRDPwh1XCglqbu4RkYwxDyBam+aDRcFj58zrzbJfY7C6nLDDNf3xtFK/24BOOv/mmnLY6A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(136003)(366004)(376002)(4326008)(6512007)(83380400001)(186003)(6486002)(16526019)(36756003)(66946007)(66556008)(1076003)(8936002)(66476007)(52116002)(26005)(478600001)(44832011)(316002)(2616005)(2906002)(8676002)(956004)(5660300002)(6916009)(6506007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8CIbcb7BRfzyNwEdKNuxh+ahLj9q+Nb9FEJWwZwxvlLqtvBJWytpeE6bQiRRr14GvjZi6wKv1qXk07B/VMgUgNHxiWOnMRCpeq9MGLrQk74TvtWBvIe0Uy1TPo28JjIQgpZIhqy7c2awpiVKW0K/RBMKEPhE73fNvLi/npRYW6u8EncQuUnIYvajVhrTScGn92csFtjTumpFFgWFMDV11xZ1vCnSGnG07LwSQ80sIxY5G+yd99wct4wUxmviykOqRgkc1kRa2kbtezxabIz0faVBMkfeJ49DcXrgZnnh02upYQPVGgqEjTWvDrHZcjXXe/r7Q42/p/D9wQQJuOPBrvppKhP/CInBVs2bRq1Z5o7gP5dCQpfCx7Bd1uv7swH3Jc7mLS5BKfsFoMgcY8ccebrw+Va3IO7FQTTIyb3RHBFsVofxPfGGV1I97LIMwFgUcGXYzk4KDCNCxiUZvkqQkKLFzjo3HJJefQh7ftD9FxNfS2BEJhg9iz00+0XHrJI5W3eq+f1SYnPKLLzrNnH9qzxGECt9i3bByKAWZcuTj51HcLshEXAZ1SKoTS+r1ABVNFHhAWk8QUq5v9R4QdO9K0nVvfqz8RKo6cR6sYZfzh8XbtlCIL6aubwmGZdAiAcWQtt7W81T/tW9EjaMcn4PKg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8697f3ec-050b-4579-8567-08d85569a399 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:12:27.9521 (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: dJB7MnhSjfHF05EME+DAakGfghrUIZ7U4L48QIZO7YafDci9YC6autBlwqUB1nQQBI0SalaSG0zrih0gyHmeeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4168 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org - Judge each TRB has been handled at cdns3_trb_handled, since the DMA pointer may be at the middle of the TD, we can't consider this TD has finished at that time. - Calculate req->actual according to finished TRBs. - Handle short transfer for sg list use case correctly. When the short transfer occurs, we check OUT_SMM at TRB to see if it is the last TRB. Signed-off-by: Peter Chen --- drivers/usb/cdns3/gadget.c | 85 +++++++++++++++++++++++++------------- drivers/usb/cdns3/gadget.h | 9 ++++ 2 files changed, 65 insertions(+), 29 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 1df4ee2857e9..a5dbe1a01050 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -817,6 +817,8 @@ void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, request->length); priv_req->flags &= ~(REQUEST_PENDING | REQUEST_UNALIGNED); + /* All TRBs have finished, clear the counter */ + priv_req->finished_trb = 0; trace_cdns3_gadget_giveback(priv_req); if (priv_dev->dev_ver < DEV_VER_V2) { @@ -1240,6 +1242,7 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, trb = priv_req->trb; priv_req->flags |= REQUEST_PENDING; + priv_req->num_of_trb = num_trb; if (sg_iter == 1) trb->control |= cpu_to_le32(TRB_IOC | TRB_ISP); @@ -1361,7 +1364,7 @@ void cdns3_set_hw_configuration(struct cdns3_device *priv_dev) } /** - * cdns3_request_handled - check whether request has been handled by DMA + * cdns3_trb_handled - check whether trb has been handled by DMA * * @priv_ep: extended endpoint object. * @priv_req: request object for checking @@ -1378,32 +1381,28 @@ void cdns3_set_hw_configuration(struct cdns3_device *priv_dev) * ET = priv_req->end_trb - index of last TRB in transfer ring * CI = current_index - index of processed TRB by DMA. * - * As first step, function checks if cycle bit for priv_req->start_trb is - * correct. + * As first step, we check if the TRB between the ST and ET. + * Then, we check if cycle bit for index priv_ep->dequeue + * is correct. * * some rules: - * 1. priv_ep->dequeue never exceed current_index. + * 1. priv_ep->dequeue never equals to current_index. * 2 priv_ep->enqueue never exceed priv_ep->dequeue * 3. exception: priv_ep->enqueue == priv_ep->dequeue * and priv_ep->free_trbs is zero. * This case indicate that TR is full. * - * Then We can split recognition into two parts: + * At below two cases, the request have been handled. * Case 1 - priv_ep->dequeue < current_index * SR ... EQ ... DQ ... CI ... ER * SR ... DQ ... CI ... EQ ... ER * - * Request has been handled by DMA if ST and ET is between DQ and CI. - * * Case 2 - priv_ep->dequeue > current_index - * This situation take place when CI go through the LINK TRB at the end of + * This situation takes place when CI go through the LINK TRB at the end of * transfer ring. * SR ... CI ... EQ ... DQ ... ER - * - * Request has been handled by DMA if ET is less then CI or - * ET is greater or equal DQ. */ -static bool cdns3_request_handled(struct cdns3_endpoint *priv_ep, +static bool cdns3_trb_handled(struct cdns3_endpoint *priv_ep, struct cdns3_request *priv_req) { struct cdns3_device *priv_dev = priv_ep->cdns3_dev; @@ -1415,7 +1414,25 @@ static bool cdns3_request_handled(struct cdns3_endpoint *priv_ep, current_index = cdns3_get_dma_pos(priv_dev, priv_ep); doorbell = !!(readl(&priv_dev->regs->ep_cmd) & EP_CMD_DRDY); - trb = &priv_ep->trb_pool[priv_req->start_trb]; + /* current trb doesn't belong to this request */ + if (priv_req->start_trb < priv_req->end_trb) { + if (priv_ep->dequeue > priv_req->end_trb) + goto finish; + + if (priv_ep->dequeue < priv_req->start_trb) + goto finish; + } + + if ((priv_req->start_trb > priv_req->end_trb) && + (priv_ep->dequeue > priv_req->end_trb) && + (priv_ep->dequeue < priv_req->start_trb)) + goto finish; + + if ((priv_req->start_trb == priv_req->end_trb) && + (priv_ep->dequeue != priv_req->end_trb)) + goto finish; + + trb = &priv_ep->trb_pool[priv_ep->dequeue]; if ((le32_to_cpu(trb->control) & TRB_CYCLE) != priv_ep->ccs) goto finish; @@ -1437,12 +1454,8 @@ static bool cdns3_request_handled(struct cdns3_endpoint *priv_ep, !priv_ep->dequeue) goto finish; - if (priv_req->end_trb >= priv_ep->dequeue && - priv_req->end_trb < current_index) - handled = 1; + handled = 1; } else if (priv_ep->dequeue > current_index) { - if (priv_req->end_trb < current_index || - priv_req->end_trb >= priv_ep->dequeue) handled = 1; } @@ -1458,6 +1471,8 @@ static void cdns3_transfer_completed(struct cdns3_device *priv_dev, struct cdns3_request *priv_req; struct usb_request *request; struct cdns3_trb *trb; + bool request_handled = false; + bool transfer_end = false; while (!list_empty(&priv_ep->pending_req_list)) { request = cdns3_next_request(&priv_ep->pending_req_list); @@ -1477,20 +1492,32 @@ static void cdns3_transfer_completed(struct cdns3_device *priv_dev, */ cdns3_select_ep(priv_dev, priv_ep->endpoint.address); - if (!cdns3_request_handled(priv_ep, priv_req)) - goto prepare_next_td; + while (cdns3_trb_handled(priv_ep, priv_req)) { + priv_req->finished_trb++; + if (priv_req->finished_trb >= priv_req->num_of_trb) + request_handled = true; - trb = priv_ep->trb_pool + priv_ep->dequeue; - trace_cdns3_complete_trb(priv_ep, trb); + trb = priv_ep->trb_pool + priv_ep->dequeue; + trace_cdns3_complete_trb(priv_ep, trb); - if (trb != priv_req->trb) - dev_warn(priv_dev->dev, - "request_trb=0x%p, queue_trb=0x%p\n", - priv_req->trb, trb); + if (!transfer_end) + request->actual += + TRB_LEN(le32_to_cpu(trb->length)); - request->actual = TRB_LEN(le32_to_cpu(trb->length)); - cdns3_move_deq_to_next_trb(priv_req); - cdns3_gadget_giveback(priv_ep, priv_req, 0); + if (priv_req->num_of_trb > 1 && + le32_to_cpu(trb->control) & TRB_SMM) + transfer_end = true; + + cdns3_ep_inc_deq(priv_ep); + } + + if (request_handled) { + cdns3_gadget_giveback(priv_ep, priv_req, 0); + request_handled = false; + transfer_end = false; + } else { + goto prepare_next_td; + } if (priv_ep->type != USB_ENDPOINT_XFER_ISOC && TRBS_PER_SEGMENT == 2) diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index 52765b098b9e..9f8bd452847e 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1030,6 +1030,11 @@ struct cdns3_trb { * When set to '1', the device will toggle its interpretation of the Cycle bit */ #define TRB_TOGGLE BIT(1) +/* + * The controller will set it if OUTSMM (OUT size mismatch) is detected, + * this bit is for normal TRB + */ +#define TRB_SMM BIT(1) /* * Short Packet (SP). OUT EPs at DMULT=1 only. Indicates if the TRB was @@ -1215,6 +1220,8 @@ struct cdns3_aligned_buf { * this endpoint * @flags: flag specifying special usage of request * @list: used by internally allocated request to add to wa2_descmiss_req_list. + * @finished_trb: number of trb has already finished per request + * @num_of_trb: how many trbs in this request */ struct cdns3_request { struct usb_request request; @@ -1230,6 +1237,8 @@ struct cdns3_request { #define REQUEST_UNALIGNED BIT(4) u32 flags; struct list_head list; + int finished_trb; + int num_of_trb; }; #define to_cdns3_request(r) (container_of(r, struct cdns3_request, request)) From patchwork Thu Sep 10 09:11:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11767191 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 63574618 for ; Thu, 10 Sep 2020 09:14:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 32F16208CA for ; Thu, 10 Sep 2020 09:14:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="q7q/9I8z" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730150AbgIJJO0 (ORCPT ); Thu, 10 Sep 2020 05:14:26 -0400 Received: from mail-eopbgr130040.outbound.protection.outlook.com ([40.107.13.40]:39234 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726738AbgIJJNo (ORCPT ); Thu, 10 Sep 2020 05:13:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a17Ex0q0emqt4keJ8rjXEnk8XebDzCnVVZbpnNJWyzdGRE1fXo+hc/c0kUcl1mJkn7PnTPYvpB1ZEVa3NPwgG2IZCalU3GZ3UkyT3RFQNSeWtptfjEm/DWQfMoVY1dfsTqxBwikcxNoewpKszybrCMTrypAINwhama43/1rn34Zq1sJGzZ6fQWF9RF//d7V6cHkxblExhZtNCMwYO+lsQ+kcOBMcR3Jke91e9rYOYzjF4cMiPg/yXF+VYfqyxSOW95Vwa3+ZnmbkzyryMJ33WBWlqGyksT+6e+CBnfAT0sU566rf5f2WuTwPxNz6MgcDl2bsnxk6GQpAqFEqt+/M2Q== 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-SenderADCheck; bh=+1DYJey45iW5UvrCSV7H6WNoTSWl+d8AeIaPUjDCyog=; b=aou7O9oCQr5uOlY3Xfi9BBQLdQ9yorfBEyv3d2gFICciOG6iIRzUvWCLySBe39iQD4if3GlwXdHINvXGY1y7V/r9jlXmKg1DqyJiZTKVABz38egdgi+wIYMAAdSQ57PMzsOho/s7smnJAU+vyhLG8NFj7txseT650bsb2QcLm0LolifPZOsFbbN5ktj9M0rqIc9XvIhFuNzL/PBDH+OfNIHemcy6Eic5wRwdKWLhxm/atEAtReQ+V+O+2UUfhUWtuW4Z9aJ3bYSjQRk2xUPclgafAhV+FZPoamhc9UhNGyEz8csRQUUEnRHcTb4sQdvtdWQw15KpHKyHbR4j74hC3g== 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=+1DYJey45iW5UvrCSV7H6WNoTSWl+d8AeIaPUjDCyog=; b=q7q/9I8znjf2xntCVQNlebyxK4XZCi++7zCiAnPZFLFKDbtxOIMcfIX41NqezT1OfB9gYcVX0OjvjyKOK3pgx8HdqfdqQcAtNM3ozB09DpcbUxjKkdj/EiHtI0x+tW5WWmSYZPDXzRHYK1ufRe7eNoXeRk7jebs9eZRsYSz3kY4= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM6PR04MB4168.eurprd04.prod.outlook.com (2603:10a6:209:43::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Thu, 10 Sep 2020 09:12:30 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1%3]) with mapi id 15.20.3370.016; Thu, 10 Sep 2020 09:12:30 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, pawell@cadence.com, rogerq@ti.com, gregkh@linuxfoundation.org, jun.li@nxp.com, Peter Chen Subject: [PATCH v2 6/8] usb: cdns3: gadget: need to handle sg case for workaround 2 case Date: Thu, 10 Sep 2020 17:11:28 +0800 Message-Id: <20200910091130.20937-7-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910091130.20937-1-peter.chen@nxp.com> References: <20200910091130.20937-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:12:28 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.66] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1172249b-2a1e-418c-d668-08d85569a54d X-MS-TrafficTypeDiagnostic: AM6PR04MB4168: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1360; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RKry5EGhmHjKC+B4BmdSL78Punl0ShoXKU2omTVJygA+xlVroroVPzPdYvtO52nv+I+vxd5JqEPr2dWGo/LErgcfBsycREiQH5duT9UfaYUHN0tpRqCn4QH1mh6D8Q6KOqJA6JPHr2u9P0XlOmxnQXCt+JNmoPWXM69F71ZqP2U43SuV40l0Cz37KiqCBLxFj+yjLu8iDkrUMLzD/n+i+TwJsw82L50ktyqnuuu1yuZyaUxeBc+hc7yD1JLXH/Cvaitmi9rnBxSF5jJmrq9QeSdVVqxHkoWEEFL3KdAspG5K58+vLeOfx9NV2xKFo2Vwm5NAhBn+rkNKP//kLvhd3A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(136003)(366004)(376002)(4326008)(6512007)(83380400001)(186003)(6486002)(16526019)(36756003)(66946007)(66556008)(1076003)(8936002)(66476007)(52116002)(26005)(478600001)(44832011)(316002)(2616005)(2906002)(8676002)(956004)(5660300002)(6916009)(6506007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: A5PvE2l8qHMQ2eFOG//xTFPXaNIsuSgjlkmHziX15fVEZKTptLI6w4SIAca3PTjiW90q89gTN1hbW04v81KLKxlsiaGCPftzJs9v2ERQDyG/UM498fg4xA+F9DB05lsgrmQ5sG++0lA3Dp6R6BzR5NmyN+pt+HMq3kDhBqnvFeL6cj5BvW4vxi9owiR1j9n9pYUtKnflRdrk5i6VSsYJASlFeTBbw1r98jFyeaYjjXTHNz5dq8Yg/e7tL7vUYI1dzYqoLxZdbAOoOwq65nK2AUzeU+fW6pQ+D2lPkvHF11/5/TJfTWMCdW5VnjQkwKfWtmzyidsJi9xTjDlyruGtk/I2269X5343lIafKJpfj8w4X3mBBAi+Dd4EFjctsAdlofUDRziHGGuU8zKRJX+IaQ0qwZmPnQWM+Rx8Py6Qgtqm33qN+rVqlMoamB6DRq0IxhKT/C7uDfpWUQpGmq4jP/iM7N8xbwbqp/lYMvHv+cy4k4KzEAwh6x+i7B51mf22Y31mu4kYSTojJ7gzKpf3AMjeHKdzMsnxiu760lO8Z4M1+toR+3juquZmXxeRxTjJj8vYs++e90BYu/JpwkLh67RrR9mN7oXoLwv6FimyQBlLv/wuY03fCeyQBoubVzOB7gpBqxvUv+zjzxR827KdhQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1172249b-2a1e-418c-d668-08d85569a54d X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:12:30.7806 (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: 4ZTWBjW5v1CgTDnK4c8qzF0WjPnG2oEVHk19swqvlGCbAI5vkslE/+zdIiTGlR7gu14BFOuRZCiw4nqqw4Sbnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4168 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add sg case for workaround 2, the workaround 2 is described at the beginning of this file. Signed-off-by: Peter Chen --- drivers/usb/cdns3/gadget.c | 44 +++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index a5dbe1a01050..e2c12212dba4 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -462,6 +462,36 @@ static int cdns3_start_all_request(struct cdns3_device *priv_dev, (reg) |= EP_STS_EN_DESCMISEN; \ } } while (0) +static void __cdns3_descmiss_copy_data(struct usb_request *request, + struct usb_request *descmiss_req) +{ + int length = request->actual + descmiss_req->actual; + struct scatterlist *s = request->sg; + + if (!s) { + if (length <= request->length) { + memcpy(&((u8 *)request->buf)[request->actual], + descmiss_req->buf, + descmiss_req->actual); + request->actual = length; + } else { + /* It should never occures */ + request->status = -ENOMEM; + } + } else { + if (length <= sg_dma_len(s)) { + void *p = phys_to_virt(sg_dma_address(s)); + + memcpy(&((u8 *)p)[request->actual], + descmiss_req->buf, + descmiss_req->actual); + request->actual = length; + } else { + request->status = -ENOMEM; + } + } +} + /** * cdns3_wa2_descmiss_copy_data copy data from internal requests to * request queued by class driver. @@ -488,21 +518,9 @@ static void cdns3_wa2_descmiss_copy_data(struct cdns3_endpoint *priv_ep, chunk_end = descmiss_priv_req->flags & REQUEST_INTERNAL_CH; length = request->actual + descmiss_req->actual; - request->status = descmiss_req->status; - - if (length <= request->length) { - memcpy(&((u8 *)request->buf)[request->actual], - descmiss_req->buf, - descmiss_req->actual); - request->actual = length; - } else { - /* It should never occures */ - request->status = -ENOMEM; - } - + __cdns3_descmiss_copy_data(request, descmiss_req); list_del_init(&descmiss_priv_req->list); - kfree(descmiss_req->buf); cdns3_gadget_ep_free_request(&priv_ep->endpoint, descmiss_req); --priv_ep->wa2_counter; From patchwork Thu Sep 10 09:11:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11767193 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8CE37618 for ; Thu, 10 Sep 2020 09:14:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67BEB21D6C for ; Thu, 10 Sep 2020 09:14:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="qn43HHcR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729449AbgIJJOc (ORCPT ); Thu, 10 Sep 2020 05:14:32 -0400 Received: from mail-eopbgr40061.outbound.protection.outlook.com ([40.107.4.61]:49482 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726847AbgIJJNy (ORCPT ); Thu, 10 Sep 2020 05:13:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T0aYqAUJ1Zd8CN+GRSdg+xL0SD0LZ9nLTJpuu2ov79m44A3B/4q3BYmrmd7015P90fSlqUyzoHVSw24vLt4qi/HOuWR77CxWghlBwsjI1kqf6pkZ8r39Vg/7nUkDkZcpWH7x4myF120XeCpV0Mdn3rbGNoRnRsnE/8MHy6rXaRqQMDYEk9kxirPj1u417gI8Iss3Hqat82s9aayAXyaJmMKavNCI4iFBnj4rUMKeQukCVb8Z1SxWMvkZBR0+BmLQ+ucfH7kUkHmsQObJIhYHlHuVLaBbkcLg84oK3jreWlne4Qn8pUgZYh92pJVmN8N1B3JFembYInRCf6D6BhcVmw== 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-SenderADCheck; bh=20UMUvYcOTfXzDTccHSiMZloHtWNpfoflBsj8t1KCz4=; b=WqW3AW9z0GQ3qEYLvUdirvJ6xLqPyLD7Sf0g8GFkgifalQOLtD7IUYUw2yBqSUApBEeWGJgMXrFbYcJxrWOhdpPSOCjXgiNHnrPmrpXO5EC3Cywi1Kh4GC/A4PW0g8sdPZPaAEm+qm9dFGhzsGlfOcAaRWraCafuKKyvo3QGVhlC7EJwEcGddgsSMZkY5QFqtO7b9pPdDc3810ul8AW2wJ7LlL2/MDSm773y3rSHXM/n77c+q+zR5342y/InELVFxaq856zd5rZ98SVqeGvzMgEYrKWIgdFvnvIv6lUo5MnKX15IHEtDwDxiOGb3E6PwszuGHjJp1OUet6ZgdTsZRg== 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=20UMUvYcOTfXzDTccHSiMZloHtWNpfoflBsj8t1KCz4=; b=qn43HHcR8JRdyzcD0IeVUlDQBTUoTii4NbQI4YEufoWL9qjZYVutlpv8hPSjlOq95TpR9gu7EsJs9eNA5fI8F5LigWRECW80AlK1Q42RDkhzrC4b54HSqq7tLemEOtrbE6J0KiGjVFw/is73znoIzqVGUiog0jNBtYkj1u3Nk2o= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM6PR04MB4168.eurprd04.prod.outlook.com (2603:10a6:209:43::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Thu, 10 Sep 2020 09:12:33 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1%3]) with mapi id 15.20.3370.016; Thu, 10 Sep 2020 09:12:33 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, pawell@cadence.com, rogerq@ti.com, gregkh@linuxfoundation.org, jun.li@nxp.com, Peter Chen Subject: [PATCH v2 7/8] usb: cdns3: gadget: sg_support is only for DEV_VER_V2 or above Date: Thu, 10 Sep 2020 17:11:29 +0800 Message-Id: <20200910091130.20937-8-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910091130.20937-1-peter.chen@nxp.com> References: <20200910091130.20937-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:12:31 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.66] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 87657771-b5d4-47c9-3aaf-08d85569a6fc X-MS-TrafficTypeDiagnostic: AM6PR04MB4168: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1824; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EYC43CkcB5cCiKLw5Jh227O2ht0T+zH5rukVkxtCtzfmqpIcqq3CYd2whrF64m0uoptzbDah7ckBKA3v6Dl9iv84o3QrgYdJJrL+HFq+E+lvu1kQQHtw6BZ+430MiIgYxhwaM3TzITyXB5aFJo3O5MWBpNq362tmo8wZEt3O4k2Oe4N/rJ6SSmHFbB7nYhpMCbTklugxPKkMHt8JgEex/fzJ/IbF4f8fAiLNOms7UG6iVsv0o42MCfibfiQPEqOCstKvJ6IfI4qrA/0u6qbcjGLG3gH9/1QIZvTxjUE14s7lB7vTGHrCumx/596GRfCh X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(136003)(366004)(376002)(4326008)(6512007)(83380400001)(186003)(6486002)(16526019)(36756003)(66946007)(66556008)(1076003)(8936002)(66476007)(52116002)(26005)(478600001)(44832011)(316002)(2616005)(2906002)(8676002)(956004)(5660300002)(6916009)(6506007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UkZ5ZDP3pW83BUUoTmNgLkGQHtT3QE9KIGMNSwiJOvHs0SUuSk7Zhw2hbIGEKWhw6JyeU5aRL52VD7l7d4goz560i6nu3ejKPGIyYJQ4XERrHdR9a5BapjX1c0dlh2woyvTVd5RsSk5+zcbuosam//JF729quqKyFNomngKho6Ru8bLuTxr4R+aHay8s44dMYPSurO2x8stpnpXBQfLO6/ThhMYYq+QJvYo7Mjf7Vv+1dyqw4eV5otlVvLPvoMnD+WKkbJ7f77PEBs/Dw+3pGykFNH27inKmmLVtDxc2XtXuqjt9iEgjlwn8yu+yTnZ4xS2wPzqz+G5S1SdcqyrhVWLeSs/YCxWkBamyNzFnNljLs2INa4a6HCRXDbn3cI1/mj0Isl9XXMZOrXgBvTOgt9lcXMOrSvP/Ezwp5JoOXFb7Q3AyHhqJpN5cwnxSgIBbHpuyjf3Sg/Skx0KMahwai5TgcPjR98vVPFSWM6oe7VJY20Pz17IzDwULN2wm8twp3Sp0GWlVcAyuUGS13ufHEtoArXVQzsoyJ+QNE9Ut1662B1B8yoy0Bm2A10oX4D12NkDUaET1dwe2jPxkAJzMeZS2L/DjWYpdxyOQw4lTes2MgccRP/PaNbKnxOQQj8V8mfyrmTvKPHLLM3Y4S0fWjw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87657771-b5d4-47c9-3aaf-08d85569a6fc X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:12:33.7406 (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: NmaymI6SlsTiarTurKbLoRZX4/LclrEuEWZ4ZPcOMGivjd5loV+axAwhI6+LBuhy40j0QbQGeokXoNWePT6Fuw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4168 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The scatter buffer list support earlier than DEV_VER_V2 is not good enough, software can't know well about short transfer for it. Cc: Pawel Laszczak Signed-off-by: Peter Chen --- drivers/usb/cdns3/gadget.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index e2c12212dba4..90a66bdc30ba 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -3160,7 +3160,6 @@ static int cdns3_gadget_start(struct cdns3 *cdns) priv_dev->gadget.speed = USB_SPEED_UNKNOWN; priv_dev->gadget.ops = &cdns3_gadget_ops; priv_dev->gadget.name = "usb-ss-gadget"; - priv_dev->gadget.sg_supported = 1; priv_dev->gadget.quirk_avoids_skb_reserve = 1; priv_dev->gadget.irq = cdns->dev_irq; @@ -3199,6 +3198,8 @@ static int cdns3_gadget_start(struct cdns3 *cdns) readl(&priv_dev->regs->usb_cap2)); priv_dev->dev_ver = GET_DEV_BASE_VERSION(priv_dev->dev_ver); + if (priv_dev->dev_ver >= DEV_VER_V2) + priv_dev->gadget.sg_supported = 1; priv_dev->zlp_buf = kzalloc(CDNS3_EP_ZLP_BUF_SIZE, GFP_KERNEL); if (!priv_dev->zlp_buf) { From patchwork Thu Sep 10 09:11:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11767223 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A093C13B1 for ; Thu, 10 Sep 2020 09:15:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F5A8206BE for ; Thu, 10 Sep 2020 09:15:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="BBPhLKRR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730077AbgIJJPa (ORCPT ); Thu, 10 Sep 2020 05:15:30 -0400 Received: from mail-eopbgr130043.outbound.protection.outlook.com ([40.107.13.43]:44418 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730136AbgIJJOM (ORCPT ); Thu, 10 Sep 2020 05:14:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i42lLiKkIOmBs/0BjmxBSJaROz2MIfUNzCDOlWLeulNftCSnfBsKjuohE3cOoLOIeppMV/rXOmiv7o1wobXClbNvlHaaCh6TIgtSKlIvvLQR/LcptpVMykWEbk5jC3QTSYjJCAz3+cBB0HDudM/zCXpLSFi2eGAFfMBS59frEfcCRis9poXM1VoduyBWKUr7A4OuhAXZKNFW+t9XHppFQxT8n1sbQ2+Baf9MX1SJijrVzLnhscQ0pfTxT81DCouCclrLRVkJ59aQxerUYjOFcf32+XIQVYUpFiLDQr/XNhpRyGIsYdZ4XTsf63+Xu7zsPjuPoPdDEp4KIm/ZO76ycw== 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-SenderADCheck; bh=TpZdgKq9DZl2AjKkEUrsMJ2D2ENEjCvSEhJf02WL91M=; b=DngewARLgZKl6U10iKpmmrzM+pq00I06fbVDY3EQ5HapNwTZ0ocZMezPf16b61MK2LwaFnM6fnAgU3saeSuhzDwJcWj3jnru06U+z+5RRNTT+mMfzI+J2ieUEzqIxYnQnit8cI7yXjPe9cVwcVWv/dmFI6w7rmaZx1TRcup/JeWbGLwYsj/H+l4rQ8+yqRYzgcnKfFgJfSc3ESL7XfsDgssGF34Wk1KgovhMDBtoRXEXsiqSsLbHDpVTBv5eVy1qrSQ9W9qbhHZVADY87cbRDT21Foe8Kbz4HeR926N6qC1gERci+yG4W948yVHE9QK2o3dDgTg7jLaef0K+wcCZug== 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=TpZdgKq9DZl2AjKkEUrsMJ2D2ENEjCvSEhJf02WL91M=; b=BBPhLKRRqKQCiB/+Ue0pAjn0lNARQ5Kba/w7WzkaBv9aGqR85g7Y/i+0KylxdgfDkQNoVcbkOhkRVJmkDkQkYZFtop1DKqzgXXWw18fKCjnUzLw3OqVlmhrI1BzpqK6I2cehvKCOyq67OlLirrJjv77nJQ8BI/SosJIkzlyB9JM= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) by AM6PR04MB4168.eurprd04.prod.outlook.com (2603:10a6:209:43::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.16; Thu, 10 Sep 2020 09:12:36 +0000 Received: from AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1]) by AM7PR04MB7157.eurprd04.prod.outlook.com ([fe80::1023:be8d:40c:efe1%3]) with mapi id 15.20.3370.016; Thu, 10 Sep 2020 09:12:36 +0000 From: Peter Chen To: balbi@kernel.org Cc: linux-usb@vger.kernel.org, linux-imx@nxp.com, pawell@cadence.com, rogerq@ti.com, gregkh@linuxfoundation.org, jun.li@nxp.com, Peter Chen Subject: [PATCH v2 8/8] usb: cdns3: gadget: enlarge the TRB ring length Date: Thu, 10 Sep 2020 17:11:30 +0800 Message-Id: <20200910091130.20937-9-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200910091130.20937-1-peter.chen@nxp.com> References: <20200910091130.20937-1-peter.chen@nxp.com> X-ClientProxiedBy: SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) To AM7PR04MB7157.eurprd04.prod.outlook.com (2603:10a6:20b:118::20) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR06CA0134.apcprd06.prod.outlook.com (2603:1096:1:1f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.16 via Frontend Transport; Thu, 10 Sep 2020 09:12:34 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [119.31.174.66] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ee0cd50d-963c-436f-c04c-08d85569a8c4 X-MS-TrafficTypeDiagnostic: AM6PR04MB4168: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vFPgQW5a5m0GovzM6uN9aTBgoxVdrEp5E0n0X8xlIdQ23E01NypWLZ94ylmYdT32MIEh5FTrP24iard4WCXaKcVpGP2YjcjxH3bUoBmU51VS5PsRTaCrDXxV3odRd4YCMBauEpUZwMaGngxcE3jtlFysoDhBGbpDlTLaWpoXN2ZGIToTcL5DvCpFrTOdphjz7YD0bgs+LEC/vlHw6xQ0n8acGzhmcQFTrlR+HCKoKA1y8pwqThWXceo3ZWfwk3Oh3wF698mJ/D1VaVNX5zTz2Vj5aaD+egvd9lgHpd7cPmpg1Sgr3U/goEb1hAeXhpq0d5AsWC17RkpUqZIDKFvm4KPDFWhgwEcRWHFOeZ6stMiXtGa2I9t0prLchyNpGqJcJwehjNBP4Ce+YA8LHHKTZA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7157.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(136003)(366004)(376002)(4326008)(6512007)(83380400001)(186003)(6486002)(16526019)(36756003)(66946007)(66556008)(1076003)(8936002)(66476007)(52116002)(26005)(478600001)(44832011)(6666004)(316002)(2616005)(2906002)(8676002)(956004)(5660300002)(6916009)(6506007)(86362001)(161623001)(147533002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: WRKA/O4gcxXeTRCJBWFLw50z+V4f36F3X1ioNL0ha/EqpjJ1O8tvpng4s+m6k87EmPBeWvIsyNK3fUNnezjqQqC9WJt5E1F4Px0v8ABuLKCLpOmkfA0bKskBWbiZCpNvrsvZczsxSg74nUcIXP3TUB3xB3QJXv3o7bRifk2Zub0DHewa4qfZw3fDy72pFlpiVLfH2qaWqGyOYEEk7vNe2KdnVL3DOHbO80+uQ6QL88wuqM2G2WxwsLQ27sbftGXtprGrDkkpNOARNIwxE70iwi5qCzEA3IdETeCBiE6XZoEXbhfG/uu0HYcaqs0HcA+boTTQQTqPj1hKUSNOD+OgV0FVTRFz1IhKCu4U2uk61dKQ0iz24AdomOrgPmifZww4GYk3El1NYmHE7IkaZRWVe1q+1+sjLdVbF23JXzEVvkdOuIt9iEYVAWvlYIYrkrVPzxHOO+/CTyLPoln3I+4LMMhIIDiDmJFgTcjBd+0O7Kq8TktxQrV+KgFxzpTZIeLcqCfauPTXR5TReDOKu0jQpSP9zmdgzvNEV5w2VgbWiVTk8JK8CB0UGIH7kcQWkzjCY1G97/QecV1xMPu1sBji5kSmAJoGBENeNakN1WzDWCjTGq+gt1CCibo8JQxKg2EbC+APwwdhmgZyHQ//IEJ2ZQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee0cd50d-963c-436f-c04c-08d85569a8c4 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7157.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Sep 2020 09:12:36.7206 (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: w7abVB0rFuW29LxrFB8xXtdxzKdFn0LDSb6xUrDxmVjmnTuCj6/aXHqYtHqI5iFsOJzWBlc1MocRXF8ipmiHQg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4168 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org At Android ADB and MTP use case, it uses f_fs which supports scatter list, it means one request may need several TRBs for it. Besides, TRB consumes very fast compared to TRB has prepared for above use case, there are at most 120 pending requests, the date size is 16KB for each request, so four TRBs (4KB per TRB) per sg entry at worst case. so we need to enlarge the TRB ring length to avoid "no free TRB error". Since each TRB only consumes 12 bytes (3 * 32 bits), we enlarge the TRB length to 600, it leaves some buffers for potential "no free TRB error", and only increases a little memory cost. Signed-off-by: Peter Chen --- drivers/usb/cdns3/gadget.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index 9f8bd452847e..1ccecd237530 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -966,7 +966,7 @@ struct cdns3_usb_regs { /* * USBSS-DEV DMA interface. */ -#define TRBS_PER_SEGMENT 40 +#define TRBS_PER_SEGMENT 600 #define ISO_MAX_INTERVAL 10