From patchwork Thu Oct 22 00:55:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11850055 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 6A8F561C for ; Thu, 22 Oct 2020 00:55:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1E237223C7 for ; Thu, 22 Oct 2020 00:55:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="jwf/Z4HN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2894509AbgJVAzv (ORCPT ); Wed, 21 Oct 2020 20:55:51 -0400 Received: from mail-eopbgr140040.outbound.protection.outlook.com ([40.107.14.40]:38030 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2894507AbgJVAzv (ORCPT ); Wed, 21 Oct 2020 20:55:51 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e1R7Q4k4KykH+xMcA5QI0uIKTegSCJEpqn+ateVb3WMaOVFEBXCQ/c8XavPKyFY+qlnRYBeMg4UdQC1tpIJxpOJwF1e7IS0p+Kim2RsRhW8RURVEKr3OKP5LH86uJdKWOl/Z+GCLr1GQ27OXSsJpQ2zea40hpxqskTIQj9eVNTokxJevxC02JA7Gm2jRwb/p/WkF/HKfH3wtEPGoNB1gfQThAuTgzyxsy/FqINp78PoO6rtosCnwRlEhdcZK8dfnT/OhBCqWnaiaiT30AVhjOFKmq8BeCQKkkra0nT7+u7tzDmB6OgxZssJs4422GYWZOECuO7F/DFsFAG5kLXpW8w== 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=C7c5HR8HrM5+fxmEUM/dMcKRr94cLeohRWQzk4Rt9BQ=; b=F+VjxsjkXiUDj7IR/kKwOqqrk7zILcy9xN7Pwxfo32Sjv9rSl9uykrA0zUdJ0H6TB/+C7kJyMFsZM+T/mrUAnCgliB2O4ZJ2gcpb4NaC2xFv2K6LQ1yV1M15rF+MZaOAUKqAvLKvxGEys2JGXD7nEZR6sU7U7IqCp9kPRQ7hZSAJ+l/zd/if0gQGqOFOc0bkNiMwU1aKznBvx3Orub/68NivYFXIyhKJXokB32rVjjfZi/B7O15ZNz7ivWGpXxOm+eHOprJCt5WisMZlBzkXc99B0+L0ftznk2ycchEmvynUSse94406Che5iWTG2s44bmjOBSEiVtHufgXWz5yrXg== 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=C7c5HR8HrM5+fxmEUM/dMcKRr94cLeohRWQzk4Rt9BQ=; b=jwf/Z4HNLF0Fp+Zz3/NnG7Pxie4ZyobdRO42VhycoKdDZfY9d2JTWsbK79rF8vMrPJ+2Dvt1uVlfgjt30ZBqFWOMKKt0Sd2UzXPlwdQSj5HgHeH308x+scEUpdoxavRuugCUAEit+uZYhAEBr7MvgKjvOYeJbFgCwCn3wI6Le4k= Authentication-Results: cadence.com; dkim=none (message not signed) header.d=none;cadence.com; dmarc=none action=none header.from=nxp.com; Received: from AM8PR04MB7300.eurprd04.prod.outlook.com (2603:10a6:20b:1c7::12) by AM0PR04MB4355.eurprd04.prod.outlook.com (2603:10a6:208:5a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Thu, 22 Oct 2020 00:55:47 +0000 Received: from AM8PR04MB7300.eurprd04.prod.outlook.com ([fe80::b902:6be0:622b:26c2]) by AM8PR04MB7300.eurprd04.prod.outlook.com ([fe80::b902:6be0:622b:26c2%4]) with mapi id 15.20.3477.028; Thu, 22 Oct 2020 00:55:47 +0000 From: Peter Chen To: pawell@cadence.com, rogerq@ti.com Cc: balbi@kernel.org, linux-usb@vger.kernel.org, linux-imx@nxp.com, gregkh@linuxfoundation.org, jun.li@nxp.com, Peter Chen Subject: [PATCH v2 1/3] usb: cdns3: gadget: suspicious implicit sign extension Date: Thu, 22 Oct 2020 08:55:03 +0800 Message-Id: <20201022005505.24167-2-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201022005505.24167-1-peter.chen@nxp.com> References: <20201022005505.24167-1-peter.chen@nxp.com> X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: SG2PR01CA0102.apcprd01.prod.exchangelabs.com (2603:1096:3:15::28) To AM8PR04MB7300.eurprd04.prod.outlook.com (2603:10a6:20b:1c7::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR01CA0102.apcprd01.prod.exchangelabs.com (2603:1096:3:15::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Thu, 22 Oct 2020 00:55:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 523d89ee-dd4e-4688-0474-08d8762536a8 X-MS-TrafficTypeDiagnostic: AM0PR04MB4355: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sUsvT2Zbd+1H/Szh3S1Nsc+bkEMsi2QTun/DDCBiGqwFrMFiMMFyuqRGpprEkANn/VK3Vo3XmGCWQalOBMF5T6XW2m35pzUhxwNIi0bx1mGJuCApbIBPHT4I6EwnW9/nD+NrepiwylGaQqglSex1L8bQNfqxHYfmx1bto1OhaZCbaFfFabjImKgGTy+atkHNFmcpgNOjeZ9jbbUN/3+k5ztweC3VvfuBHLxnOgkSYjHeYYnE8kJ5JtBusRR1VRR5viRCGt8S4Pj/Vr3gHuaJp9YJV6dZNHhatTKsdtHZ1bs9KPjOIrtBteZkJkMcjAOJksj4O48oALp0qBW9mx4Kwg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM8PR04MB7300.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(86362001)(956004)(8936002)(6486002)(2906002)(66946007)(6666004)(66476007)(66556008)(5660300002)(1076003)(36756003)(316002)(6512007)(44832011)(2616005)(16526019)(26005)(478600001)(8676002)(52116002)(83380400001)(186003)(6506007)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 8k6gFfySE6UBSYiHEva9gyx0KYBVueHQPR5v3ztE4jbOSUq8jaDAZk9Z8H0866tMdZTMLBY7QY5dx5eeCrDKn6DBq5ZX84NUGYmsjaCxgnNP/tq4qIVmFUMHLQqSPeuJxF1kiScuFzYF8igDtUKoERrTVrEa6QLUTM5EauT0Ly50QAZraZgln68Nt/GjQzdjiioE5XkuieBB4TblXn60daJ8J9q7g9QFjkJzzLfvCMSnoMvOpUh+YjavN3amT5jqE0zbIa5oMYFgpikq3SASmEu6YSnh/mXA/BWst2hrkbAlik9emp9x5f72bBC4fEgbNt6M60+UWzW2vc/naqrt29rZNGSoU633tbFOuSZ/7nUL5VXSujiaRY1tZQ+AukoYnaTN5PRWJ2Re2pBsASI0ZoME6n332yrEwTBxBDub+J+R3D01STCRata1oT2G6DmuERYiF6cY+c8HgOSig/AbGV8GYzCnoAqsrVOs/hM31nAA0+ypAegMMLvdsEWtMXlQF2xnbHxvxOdD9SnVUpGZ+wYaXdh9GdSdP4axUdrwTLPC/XElliq3dhbM//ro0B5Bz36q0tG1NYlKXkCFUqU4Shc7ahLLb8Txn5Ayc3N+QGXJfMIwwJz5tVkeoNlpOFD2WvXWYuQTupIGHt6o3f5kUg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 523d89ee-dd4e-4688-0474-08d8762536a8 X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7300.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2020 00:55:47.8541 (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: 3C+THhtQTSgZ2D9K8ys+2HnPZ1yLyxtpjRM6KFfxDO9kd2Kug/273wfK6iAz/DcETbk29NzLXdvZTzBXXQ4xPg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4355 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The code: trb->length = cpu_to_le32(TRB_BURST_LEN(priv_ep->trb_burst_size) | TRB_LEN(length)); TRB_BURST_LEN(priv_ep->trb_burst_size) may be overflow for int 32 if priv_ep->trb_burst_size is equal or larger than 0x80; Below is the Coverity warning: sign_extension: Suspicious implicit sign extension: priv_ep->trb_burst_size with type u8 (8 bits, unsigned) is promoted in priv_ep->trb_burst_size << 24 to type int (32 bits, signed), then sign-extended to type unsigned long (64 bits, unsigned). If priv_ep->trb_burst_size << 24 is greater than 0x7FFFFFFF, the upper bits of the result will all be 1. To fix it, it needs to add an explicit cast to unsigned int type for ((p) << 24). Reviewed-by: Jun Li Signed-off-by: Peter Chen --- Changes for v2: - Move position of explicit cast to unsigned int before ((p) << 24) [Patch 1/3] 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 1ccecd237530..737377913788 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1072,7 +1072,7 @@ struct cdns3_trb { #define TRB_TDL_SS_SIZE_GET(p) (((p) & GENMASK(23, 17)) >> 17) /* transfer_len bitmasks - bits 31:24 */ -#define TRB_BURST_LEN(p) (((p) << 24) & GENMASK(31, 24)) +#define TRB_BURST_LEN(p) ((unsigned int)((p) << 24) & GENMASK(31, 24)) #define TRB_BURST_LEN_GET(p) (((p) & GENMASK(31, 24)) >> 24) /* Data buffer pointer bitmasks*/ From patchwork Thu Oct 22 00:55:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11850057 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 DE775157C for ; Thu, 22 Oct 2020 00:55:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9C15223C7 for ; Thu, 22 Oct 2020 00:55:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="lpu36HI0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2894512AbgJVAzz (ORCPT ); Wed, 21 Oct 2020 20:55:55 -0400 Received: from mail-eopbgr140089.outbound.protection.outlook.com ([40.107.14.89]:31714 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2894507AbgJVAzy (ORCPT ); Wed, 21 Oct 2020 20:55:54 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kWHIcmVu8CHuNWdL2jCS/sijhilufKEcw5wtYuXsJqaOHZKc80J6QWlURfxI24aiFqwyH9gquFoDpIcnQh3MwPJ868EEGYh0KLL4LMxopVYscqz7FWsm4u5UvtQJUzU/4k8bOb2uhmby91ZN1/M9/8ux16xo7gSGOBHhflv1XaDrUrua+ILzQFQKW5TgdQao853bt4Y7NYywGQe3mS/GGGPgSFE4MLCbDAb7ebKfkgdsogU8NRD7Sh2ZxuA7Hij/E3kbjMKgIZ9MS0RMX59rn0ksTTFG+uR71kgjQRPrkLxmZ67n1efs/Y7DyMSr2Fi5FzDg+zjPudzx8Ttxgxn2pQ== 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=vCETu0MmhegaGIC5cmmkurT+73lcQtLVZQe6ABQDNv0=; b=I/f95ndPn9qvI5Nqbd95/oTpf0fTFGLmgH6gsxYXYq9t4YjSt3eZiy7VZ0jbnxHiUriZjVWM7E89PKCZgQtkt5pGky3TQPrlIEI7RJy7s0Y79QMaM6W6jm0Zmzx6V1ewvb96s/oVZemeemxvVfgrKgaZ12HbGUvs51EPMUuWUJc0tfyB4NMs/HuefyrO8gWG+PjTTolwt3l62mNdXAbYvLCmMtwL9hm3MfoTC15PdcTAQ0BTCsjK+UiU+trrytM3r61pIKqa19NR9CUslptGRJnKiiEX4nXMKMFHfPIEygfLg5oc4BEN5lc1/rrBxwpOk5hBM0psehTVX/U9Tk7iTA== 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=vCETu0MmhegaGIC5cmmkurT+73lcQtLVZQe6ABQDNv0=; b=lpu36HI0J73cnNTtWDae1TBomN6hapiBNCqXbTuW9mD/wOkhTZFj1HX3lyhfUmr8+u8VNuRnw9xgZ5Nc7hM/cV7I0++5hBevB7Q3b7YwvGvpFxhF725XMgPtenZ1mt8emwjaF8HwkkKJIwrSuhihBKRjqHof062vL32ooaA8yec= Authentication-Results: cadence.com; dkim=none (message not signed) header.d=none;cadence.com; dmarc=none action=none header.from=nxp.com; Received: from AM8PR04MB7300.eurprd04.prod.outlook.com (2603:10a6:20b:1c7::12) by AM0PR04MB4355.eurprd04.prod.outlook.com (2603:10a6:208:5a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Thu, 22 Oct 2020 00:55:50 +0000 Received: from AM8PR04MB7300.eurprd04.prod.outlook.com ([fe80::b902:6be0:622b:26c2]) by AM8PR04MB7300.eurprd04.prod.outlook.com ([fe80::b902:6be0:622b:26c2%4]) with mapi id 15.20.3477.028; Thu, 22 Oct 2020 00:55:50 +0000 From: Peter Chen To: pawell@cadence.com, rogerq@ti.com Cc: balbi@kernel.org, linux-usb@vger.kernel.org, linux-imx@nxp.com, gregkh@linuxfoundation.org, jun.li@nxp.com, Peter Chen Subject: [PATCH v2 2/3] usb: cdns3: gadget: own the lock wrongly at the suspend routine Date: Thu, 22 Oct 2020 08:55:04 +0800 Message-Id: <20201022005505.24167-3-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201022005505.24167-1-peter.chen@nxp.com> References: <20201022005505.24167-1-peter.chen@nxp.com> X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: SG2PR01CA0102.apcprd01.prod.exchangelabs.com (2603:1096:3:15::28) To AM8PR04MB7300.eurprd04.prod.outlook.com (2603:10a6:20b:1c7::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR01CA0102.apcprd01.prod.exchangelabs.com (2603:1096:3:15::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Thu, 22 Oct 2020 00:55:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b0a66eda-817c-4ad6-18fa-08d876253875 X-MS-TrafficTypeDiagnostic: AM0PR04MB4355: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nwHacmOo31CM2LgWS8a38aUa2Y2xoME4VwgnYco5lzbyaa5SU/k/qcXgUzB6zYlz+Tu5OrF9+Mt3B9Db8gERayQE1WDYGyOAbXjhtjWNKeP89mcLe3jLKe15Mp/NCmH+VqDhI7sMP+tEywC5eBfFEnrgCYr69jcbQXAKwMNVYRUu02If6N2shB3TdJz1MwyaqEwY4JbR1Mz3lDttM7JaD3+Zm3zYiVqe8AUeDJwuth5xs5jK51J4ZnK+QNJTw67G9//fxQDwzNMZmgFmiE2Ke3cLF2V2Ax1ngp01+N6eWH3vIu29GZZOGL4yAaCW6wx+Q4a+QOp18Siq0ufNVIv4vA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM8PR04MB7300.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(86362001)(956004)(8936002)(6486002)(2906002)(66946007)(6666004)(66476007)(66556008)(5660300002)(1076003)(15650500001)(36756003)(316002)(6512007)(44832011)(2616005)(16526019)(26005)(478600001)(8676002)(52116002)(83380400001)(186003)(6506007)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: BYTIXSTRuqYjNjBlb4tcJqIxMQqtc/NTieZBz7p2aO/J8na9K6RoZrAv/OMMThM4zNO2mNVBO5oiLORwAi6SSh3hh8QANUHdZ0qUZ5suoUvHNrgYNyMefNJHWTK/drx9epKXjFhaPbgi+5GvpkS7zvE2lx1vnK1/j5ROaIMCLGfHlSPEsZgj4zf3XQJDK71pEzm1fzACn2zJOzzz2yYh2Gj4VYam6jFoFDLmODTu/9jd/nvSYIWRtdCkCfK80XxujQhyGIdkL1XeEg/FcCMuJtRCNHTS15/djtbOoul0uFrkpRtI+NZPsn1zC8iBvLuxroPn2INZPDnA9GlrpSRFwbxxt1SL1nzIhOmlE9n2DRwr1fJAaiSsozzAQNr1GfAcxuTefdwEzj9PuZHvpCT3qzJ8Q5zA/Mr3OP2/Ij1jMF2izBkxLzmBE7zEapM6KZ6S1A8gf22Kq9OLYMleMH8KCzjzzEP2CFO3DQF6rKYflox42vjo95Q2APzlLishOt/bRZuu9r1wvIC5EwRaYBwkC9LV4UXDa/0Wguh6H9VxCEfY2WqT/r2eqZTITGANG216rz7fjiiXxSEftOIPX1elJvSJPEwJDE3iCPvQC3a78JCD5SXxr5tXAm2wi94Bbal0DUzH0e1qQ8B/TlmVf31UoA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b0a66eda-817c-4ad6-18fa-08d876253875 X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7300.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2020 00:55:50.8131 (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: qPwCxRijHAlPakgAR5FkKPmVaDn5LYdRqAzIZSVQ6aJiVY/i7QpOxtqk819VDS1tHYHE3RMyvT34SNd3gxMaVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4355 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When the system goes to suspend, if the controller is at device mode with cable connecting to host, the call stack is: cdns3_suspend-> cdns3_gadget_suspend -> cdns3_disconnect_gadget, after cdns3_disconnect_gadget is called, it owns lock wrongly, it causes the system being deadlock after resume due to at cdns3_device_thread_irq_handler, it tries to get the lock, but can't get it forever. To fix it, we delete the unlock-lock operations at cdns3_disconnect_gadget, and do it at the caller. Fixes: b1234e3b3b26 ("usb: cdns3: add runtime PM support") Signed-off-by: Peter Chen --- drivers/usb/cdns3/gadget.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 6ff3aa3db497..c127af6c0fe8 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -1744,11 +1744,8 @@ static int cdns3_check_ep_interrupt_proceed(struct cdns3_endpoint *priv_ep) static void cdns3_disconnect_gadget(struct cdns3_device *priv_dev) { - if (priv_dev->gadget_driver && priv_dev->gadget_driver->disconnect) { - spin_unlock(&priv_dev->lock); + if (priv_dev->gadget_driver && priv_dev->gadget_driver->disconnect) priv_dev->gadget_driver->disconnect(&priv_dev->gadget); - spin_lock(&priv_dev->lock); - } } /** @@ -1783,7 +1780,9 @@ static void cdns3_check_usb_interrupt_proceed(struct cdns3_device *priv_dev, /* Disconnection detected */ if (usb_ists & (USB_ISTS_DIS2I | USB_ISTS_DISI)) { + spin_unlock(&priv_dev->lock); cdns3_disconnect_gadget(priv_dev); + spin_lock(&priv_dev->lock); priv_dev->gadget.speed = USB_SPEED_UNKNOWN; usb_gadget_set_state(&priv_dev->gadget, USB_STATE_NOTATTACHED); cdns3_hw_reset_eps_config(priv_dev); @@ -3266,7 +3265,9 @@ static int cdns3_gadget_suspend(struct cdns3 *cdns, bool do_wakeup) { struct cdns3_device *priv_dev = cdns->gadget_dev; + spin_unlock(&cdns->lock); cdns3_disconnect_gadget(priv_dev); + spin_lock(&cdns->lock); priv_dev->gadget.speed = USB_SPEED_UNKNOWN; usb_gadget_set_state(&priv_dev->gadget, USB_STATE_NOTATTACHED); From patchwork Thu Oct 22 00:55:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Chen X-Patchwork-Id: 11850059 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 E40D961C for ; Thu, 22 Oct 2020 00:56:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A70392245F for ; Thu, 22 Oct 2020 00:56:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="LLU8mmkl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2894514AbgJVAz7 (ORCPT ); Wed, 21 Oct 2020 20:55:59 -0400 Received: from mail-eopbgr140089.outbound.protection.outlook.com ([40.107.14.89]:31714 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2894510AbgJVAz7 (ORCPT ); Wed, 21 Oct 2020 20:55:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZingxS/fFxk8Cl9esuCjvKaOQxhmXVsFkEljiaScL8MZmeHtIuPEtcB7Le6X2rlJy+UCMZLTb7eKwGGadcuxZSpgOcbkQevberT6H3S7jD8vvePsk1cMGJl8x0AM6FzB2BEvW71p3MQx3BPWqeK1LFOf1oHIJV6kDE0dKHMeg+2jV35JO/mBY3mHMFwwGit8f2c1kVzdWTLNGmT43MSeTZTHedwUOpRKaKzg8jWW+de9CB8BFcxHmaTV/n8AcJ8oPt1Rr24i58+rHOWCqRQX/hcrPkBCb9UcL/yH6d0hGsxbOlPK5u+0Io61DAhw5hIZj5OQtMjAtCR+4Xf6JOh/nA== 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=lX9ZZ4IEdt4fZ9XOACd8KSDjN7SVTNVMi4IXdX/jFaw=; b=C/LCprsQjntMxyRIRLrVK+S2401sUaZGRMCH45F5B9Qps1WraOg2O0IOg9Z44nEGLHsiR3Atwa3xL9EpCataPyxWEhEfGw1gtcboMeuvb0GVXlagF7QlDqAnoNMIxUGALQvAazFvQfovKO6pI+svkGna+tNdIC1z4UFIwSVc5ceMKTwwvufhI7/AQslp3TKChWOy3n7CdkAYW0nEmplfG21v7iOfBCKn2leFK8KHZuGcF2RqilHUrpaHzo9oYIC/h/Z4LbzXU6AySv/tlf5vICAN41bn8Qbvr+ozoIGQU3/JjIOp5N18I4jdgPQu4i6mNaQlEdasKhAUx2KcaVwoOA== 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=lX9ZZ4IEdt4fZ9XOACd8KSDjN7SVTNVMi4IXdX/jFaw=; b=LLU8mmkluuIzg+KHYuSgogAGMGEn82FApzeVpQSgELTQpbpsskSYmVM0DI+/l9ZtwjIKdCIk8of3qX5nDxBUZIDdg6LIXU8l++AIbLzTGlS//whvjbs7Mh4NK1J0xwaK9Zv//eU58CtOXisokqpYGDOZvKOS0L5EFaMI2OpdOwk= Authentication-Results: cadence.com; dkim=none (message not signed) header.d=none;cadence.com; dmarc=none action=none header.from=nxp.com; Received: from AM8PR04MB7300.eurprd04.prod.outlook.com (2603:10a6:20b:1c7::12) by AM0PR04MB4355.eurprd04.prod.outlook.com (2603:10a6:208:5a::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18; Thu, 22 Oct 2020 00:55:54 +0000 Received: from AM8PR04MB7300.eurprd04.prod.outlook.com ([fe80::b902:6be0:622b:26c2]) by AM8PR04MB7300.eurprd04.prod.outlook.com ([fe80::b902:6be0:622b:26c2%4]) with mapi id 15.20.3477.028; Thu, 22 Oct 2020 00:55:54 +0000 From: Peter Chen To: pawell@cadence.com, rogerq@ti.com Cc: balbi@kernel.org, linux-usb@vger.kernel.org, linux-imx@nxp.com, gregkh@linuxfoundation.org, jun.li@nxp.com, stable@vger.kernel.org, Peter Chen Subject: [PATCH v2 3/3] usb: cdns3: Fix on-chip memory overflow issue Date: Thu, 22 Oct 2020 08:55:05 +0800 Message-Id: <20201022005505.24167-4-peter.chen@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201022005505.24167-1-peter.chen@nxp.com> References: <20201022005505.24167-1-peter.chen@nxp.com> X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: SG2PR01CA0102.apcprd01.prod.exchangelabs.com (2603:1096:3:15::28) To AM8PR04MB7300.eurprd04.prod.outlook.com (2603:10a6:20b:1c7::12) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from b29397-desktop.ap.freescale.net (119.31.174.66) by SG2PR01CA0102.apcprd01.prod.exchangelabs.com (2603:1096:3:15::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.18 via Frontend Transport; Thu, 22 Oct 2020 00:55:51 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 64dfddb1-0e13-494e-b5cc-08d876253a48 X-MS-TrafficTypeDiagnostic: AM0PR04MB4355: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m/c7AbccxjMCwPPxZEX1VEl5rRuvSmCy+Nxwv4psSL96G1t5hqKVddOH2SLxLFNDl9j1YOiyQaYktLiWteKf9amqJ63eveHbtvGunb/f0n8AzoSofiOq+3w93NLsFr80Cb6ch3Y6AQpMX4wfjP1TZjwRUJXJyK3536ws2+lke/T47XD6xzYD6EC5YNxfDG0arXdzqPI3LUzBICxgKRY2qIN870Y8CpeQHCNKaWr/Xm0FdvNnJN24vxb+zXg/Y+p9GH95XLIIt87ZR5uC+VTlS985TdshbuRD4+8alpf5sPlPBgyMHwP5eb/2UTKtv0XEZlPDO703KBQmklnZxdy1GI6N+/N2RdkVnOZr4zxivs5XkPUTARwIADg9uEYCD/yW X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM8PR04MB7300.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39860400002)(346002)(366004)(136003)(376002)(86362001)(956004)(8936002)(6486002)(2906002)(30864003)(66946007)(6666004)(66476007)(66556008)(5660300002)(1076003)(36756003)(316002)(6512007)(44832011)(2616005)(16526019)(26005)(478600001)(8676002)(52116002)(83380400001)(186003)(6506007)(4326008)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: EhtPfcCScr65Idsq2OT/ZpbpjD1KiZGLFJFb0SGkZQ4txJ2S9vlLXvoKCzLbFde0Pj9k176ndczJOkBC/mx6zC3E4ETt2cb2aewnvbbfNjoT1yHEW+p0jm9gXd+IbrFbNHXJFJnY7JXgobFfbz0aDlzhQiaKjNIkeIaecu6Bgq5cssXsyXy/XAFSYHUhAY0wfKrCY9Lwh41qItxvaDO6g/TpmANb5S7RC3/Jwd5BvxEsW3FoGZk3x8xXBg96wf4zAya9uHrNQKd3foOzrhhIg5HyiLAqm7dRVay+aeOO0iyrsl4ak6A8cqlcGsIgH4yYCuymzL7N1iyeXTSmFD01RAOdjMCTSzG/FDmL/2By8hV7U4XV1VHh21pqJBhugeYJjvMaOxshgBy/2/BqdN+T7MGUQhskuyBS/ZMbQWpACOyGN9ig+Shsoj8x+gu5nghqL/cONz5IR6JN0ARP+a0qVjeDakowQMK0Mz7rdoroz/PJMQPS6UnzKkH4zK5Lw773ABvLlqpa++h7zFOE8HtowM81qPbIhvtxx5wUuTAJleROWCmAgRN6ZKkhKvJ5D+9jiEylwvaVX59qtv7+RlwHStUIoAuyjUXoN9YZAmHFeT3MmmZ9ZGkVNzUV2VlxPzP3gDUeNfJUGd4wcJ0T81/StQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 64dfddb1-0e13-494e-b5cc-08d876253a48 X-MS-Exchange-CrossTenant-AuthSource: AM8PR04MB7300.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Oct 2020 00:55:53.9254 (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: a1t8wnMpJVZkLaK+g1/nJJAw1rLVETT0KRIY5siqSYN1WmrLkCZDN+wPRlq9mkTTs9Bo8dW7SMfSNBB9WXbpdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB4355 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Pawel Laszczak Patch fixes issue caused setting On-chip memory overflow bit in usb_sts register. The issue occurred because EP_CFG register was set twice before USB_STS.CFGSTS was set. Every write operation on EP_CFG.BUFFERING causes that controller increases internal counter holding the number of reserved on-chip buffers. First time this register was updated in function cdns3_ep_config before delegating SET_CONFIGURATION request to class driver and again it was updated when class wanted to enable endpoint. This patch fixes this issue by configuring endpoints enabled by class driver in cdns3_gadget_ep_enable and others just before status stage. Cc: #v5.8+ Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver") Reported-and-tested-by: Peter Chen Signed-off-by: Pawel Laszczak Signed-off-by: Peter Chen --- drivers/usb/cdns3/ep0.c | 65 ++++++++++++----------- drivers/usb/cdns3/gadget.c | 102 +++++++++++++++++++++---------------- drivers/usb/cdns3/gadget.h | 3 +- 3 files changed, 94 insertions(+), 76 deletions(-) diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c index 4761c852d9c4..d3121a32cc68 100644 --- a/drivers/usb/cdns3/ep0.c +++ b/drivers/usb/cdns3/ep0.c @@ -137,48 +137,36 @@ static int cdns3_req_ep0_set_configuration(struct cdns3_device *priv_dev, struct usb_ctrlrequest *ctrl_req) { enum usb_device_state device_state = priv_dev->gadget.state; - struct cdns3_endpoint *priv_ep; u32 config = le16_to_cpu(ctrl_req->wValue); int result = 0; - int i; switch (device_state) { case USB_STATE_ADDRESS: - /* Configure non-control EPs */ - for (i = 0; i < CDNS3_ENDPOINTS_MAX_COUNT; i++) { - priv_ep = priv_dev->eps[i]; - if (!priv_ep) - continue; - - if (priv_ep->flags & EP_CLAIMED) - cdns3_ep_config(priv_ep); - } - result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); - if (result) - return result; - - if (!config) { - cdns3_hw_reset_eps_config(priv_dev); - usb_gadget_set_state(&priv_dev->gadget, - USB_STATE_ADDRESS); - } + if (result || !config) + goto reset_config; break; case USB_STATE_CONFIGURED: result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); + if (!config && !result) + goto reset_config; - if (!config && !result) { - cdns3_hw_reset_eps_config(priv_dev); - usb_gadget_set_state(&priv_dev->gadget, - USB_STATE_ADDRESS); - } break; default: - result = -EINVAL; + return -EINVAL; } + return 0; + +reset_config: + if (result != USB_GADGET_DELAYED_STATUS) + cdns3_hw_reset_eps_config(priv_dev); + + usb_gadget_set_state(&priv_dev->gadget, + USB_STATE_ADDRESS); + return result; } @@ -705,6 +693,7 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep, unsigned long flags; int ret = 0; u8 zlp = 0; + int i; spin_lock_irqsave(&priv_dev->lock, flags); trace_cdns3_ep0_queue(priv_dev, request); @@ -720,6 +709,17 @@ static int cdns3_gadget_ep0_queue(struct usb_ep *ep, u32 val; cdns3_select_ep(priv_dev, 0x00); + + /* + * Configure all non-control EPs which are not enabled by class driver + */ + for (i = 0; i < CDNS3_ENDPOINTS_MAX_COUNT; i++) { + priv_ep = priv_dev->eps[i]; + if (priv_ep && priv_ep->flags & EP_CLAIMED && + !(priv_ep->flags & EP_ENABLED)) + cdns3_ep_config(priv_ep, 0); + } + cdns3_set_hw_configuration(priv_dev); cdns3_ep0_complete_setup(priv_dev, 0, 1); /* wait until configuration set */ @@ -811,6 +811,7 @@ void cdns3_ep0_config(struct cdns3_device *priv_dev) struct cdns3_usb_regs __iomem *regs; struct cdns3_endpoint *priv_ep; u32 max_packet_size = 64; + u32 ep_cfg; regs = priv_dev->regs; @@ -842,8 +843,10 @@ void cdns3_ep0_config(struct cdns3_device *priv_dev) BIT(0) | BIT(16)); } - writel(EP_CFG_ENABLE | EP_CFG_MAXPKTSIZE(max_packet_size), - ®s->ep_cfg); + ep_cfg = EP_CFG_ENABLE | EP_CFG_MAXPKTSIZE(max_packet_size); + + if (!(priv_ep->flags & EP_CONFIGURED)) + writel(ep_cfg, ®s->ep_cfg); writel(EP_STS_EN_SETUPEN | EP_STS_EN_DESCMISEN | EP_STS_EN_TRBERREN, ®s->ep_sts_en); @@ -851,8 +854,10 @@ void cdns3_ep0_config(struct cdns3_device *priv_dev) /* init ep in */ cdns3_select_ep(priv_dev, USB_DIR_IN); - writel(EP_CFG_ENABLE | EP_CFG_MAXPKTSIZE(max_packet_size), - ®s->ep_cfg); + if (!(priv_ep->flags & EP_CONFIGURED)) + writel(ep_cfg, ®s->ep_cfg); + + priv_ep->flags |= EP_CONFIGURED; writel(EP_STS_EN_SETUPEN | EP_STS_EN_TRBERREN, ®s->ep_sts_en); diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index c127af6c0fe8..5fa89baa53da 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -296,6 +296,8 @@ static void cdns3_ep_stall_flush(struct cdns3_endpoint *priv_ep) */ void cdns3_hw_reset_eps_config(struct cdns3_device *priv_dev) { + int i; + writel(USB_CONF_CFGRST, &priv_dev->regs->usb_conf); cdns3_allow_enable_l1(priv_dev, 0); @@ -304,6 +306,10 @@ void cdns3_hw_reset_eps_config(struct cdns3_device *priv_dev) priv_dev->out_mem_is_allocated = 0; priv_dev->wait_for_setup = 0; priv_dev->using_streams = 0; + + for (i = 0; i < CDNS3_ENDPOINTS_MAX_COUNT; i++) + if (priv_dev->eps[i]) + priv_dev->eps[i]->flags &= ~EP_CONFIGURED; } /** @@ -1976,27 +1982,6 @@ static int cdns3_ep_onchip_buffer_reserve(struct cdns3_device *priv_dev, return 0; } -static void cdns3_stream_ep_reconfig(struct cdns3_device *priv_dev, - struct cdns3_endpoint *priv_ep) -{ - if (!priv_ep->use_streams || priv_dev->gadget.speed < USB_SPEED_SUPER) - return; - - if (priv_dev->dev_ver >= DEV_VER_V3) { - u32 mask = BIT(priv_ep->num + (priv_ep->dir ? 16 : 0)); - - /* - * Stream capable endpoints are handled by using ep_tdl - * register. Other endpoints use TDL from TRB feature. - */ - cdns3_clear_register_bit(&priv_dev->regs->tdl_from_trb, mask); - } - - /* Enable Stream Bit TDL chk and SID chk */ - cdns3_set_register_bit(&priv_dev->regs->ep_cfg, EP_CFG_STREAM_EN | - EP_CFG_TDL_CHK | EP_CFG_SID_CHK); -} - static void cdns3_configure_dmult(struct cdns3_device *priv_dev, struct cdns3_endpoint *priv_ep) { @@ -2034,8 +2019,9 @@ static void cdns3_configure_dmult(struct cdns3_device *priv_dev, /** * cdns3_ep_config Configure hardware endpoint * @priv_ep: extended endpoint object + * @enable: set EP_CFG_ENABLE bit in ep_cfg register. */ -void cdns3_ep_config(struct cdns3_endpoint *priv_ep) +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; @@ -2096,7 +2082,7 @@ void cdns3_ep_config(struct cdns3_endpoint *priv_ep) break; default: /* all other speed are not supported */ - return; + return -EINVAL; } if (max_packet_size == 1024) @@ -2106,11 +2092,33 @@ void cdns3_ep_config(struct cdns3_endpoint *priv_ep) else priv_ep->trb_burst_size = 16; - ret = cdns3_ep_onchip_buffer_reserve(priv_dev, buffering + 1, - !!priv_ep->dir); - if (ret) { - dev_err(priv_dev->dev, "onchip mem is full, ep is invalid\n"); - return; + /* onchip buffer is only allocated before configuration */ + if (!priv_dev->hw_configured_flag) { + ret = cdns3_ep_onchip_buffer_reserve(priv_dev, buffering + 1, + !!priv_ep->dir); + if (ret) { + dev_err(priv_dev->dev, "onchip mem is full, ep is invalid\n"); + return ret; + } + } + + if (enable) + ep_cfg |= EP_CFG_ENABLE; + + if (priv_ep->use_streams && priv_dev->gadget.speed >= USB_SPEED_SUPER) { + if (priv_dev->dev_ver >= DEV_VER_V3) { + u32 mask = BIT(priv_ep->num + (priv_ep->dir ? 16 : 0)); + + /* + * Stream capable endpoints are handled by using ep_tdl + * register. Other endpoints use TDL from TRB feature. + */ + cdns3_clear_register_bit(&priv_dev->regs->tdl_from_trb, + mask); + } + + /* Enable Stream Bit TDL chk and SID chk */ + ep_cfg |= EP_CFG_STREAM_EN | EP_CFG_TDL_CHK | EP_CFG_SID_CHK; } ep_cfg |= EP_CFG_MAXPKTSIZE(max_packet_size) | @@ -2120,9 +2128,12 @@ void cdns3_ep_config(struct cdns3_endpoint *priv_ep) cdns3_select_ep(priv_dev, bEndpointAddress); writel(ep_cfg, &priv_dev->regs->ep_cfg); + priv_ep->flags |= EP_CONFIGURED; dev_dbg(priv_dev->dev, "Configure %s: with val %08x\n", priv_ep->name, ep_cfg); + + return 0; } /* Find correct direction for HW endpoint according to description */ @@ -2263,7 +2274,7 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, u32 bEndpointAddress; unsigned long flags; int enable = 1; - int ret; + int ret = 0; int val; priv_ep = ep_to_cdns3_ep(ep); @@ -2302,6 +2313,17 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, bEndpointAddress = priv_ep->num | priv_ep->dir; cdns3_select_ep(priv_dev, bEndpointAddress); + /* + * For some versions of controller at some point during ISO OUT traffic + * DMA reads Transfer Ring for the EP which has never got doorbell. + * This issue was detected only on simulation, but to avoid this issue + * driver add protection against it. To fix it driver enable ISO OUT + * endpoint before setting DRBL. This special treatment of ISO OUT + * endpoints are recommended by controller specification. + */ + if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir) + enable = 0; + if (usb_ss_max_streams(comp_desc) && usb_endpoint_xfer_bulk(desc)) { /* * Enable stream support (SS mode) related interrupts @@ -2312,13 +2334,17 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, EP_STS_EN_SIDERREN | EP_STS_EN_MD_EXITEN | EP_STS_EN_STREAMREN; priv_ep->use_streams = true; - cdns3_stream_ep_reconfig(priv_dev, priv_ep); + ret = cdns3_ep_config(priv_ep, enable); priv_dev->using_streams |= true; } + } else { + ret = cdns3_ep_config(priv_ep, enable); } - ret = cdns3_allocate_trb_pool(priv_ep); + if (ret) + goto exit; + ret = cdns3_allocate_trb_pool(priv_ep); if (ret) goto exit; @@ -2348,20 +2374,6 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, writel(reg, &priv_dev->regs->ep_sts_en); - /* - * For some versions of controller at some point during ISO OUT traffic - * DMA reads Transfer Ring for the EP which has never got doorbell. - * This issue was detected only on simulation, but to avoid this issue - * driver add protection against it. To fix it driver enable ISO OUT - * endpoint before setting DRBL. This special treatment of ISO OUT - * endpoints are recommended by controller specification. - */ - if (priv_ep->type == USB_ENDPOINT_XFER_ISOC && !priv_ep->dir) - enable = 0; - - if (enable) - cdns3_set_register_bit(&priv_dev->regs->ep_cfg, EP_CFG_ENABLE); - ep->desc = desc; priv_ep->flags &= ~(EP_PENDING_REQUEST | EP_STALLED | EP_STALL_PENDING | EP_QUIRK_ISO_OUT_EN | EP_QUIRK_EXTRA_BUF_EN); diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index 737377913788..21fa461c518e 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1159,6 +1159,7 @@ struct cdns3_endpoint { #define EP_QUIRK_EXTRA_BUF_DET BIT(12) #define EP_QUIRK_EXTRA_BUF_EN BIT(13) #define EP_TDLCHK_EN BIT(15) +#define EP_CONFIGURED BIT(16) u32 flags; struct cdns3_request *descmis_req; @@ -1360,7 +1361,7 @@ void cdns3_gadget_giveback(struct cdns3_endpoint *priv_ep, int cdns3_init_ep0(struct cdns3_device *priv_dev, struct cdns3_endpoint *priv_ep); void cdns3_ep0_config(struct cdns3_device *priv_dev); -void cdns3_ep_config(struct cdns3_endpoint *priv_ep); +int cdns3_ep_config(struct cdns3_endpoint *priv_ep, bool enable); void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir); int __cdns3_gadget_wakeup(struct cdns3_device *priv_dev);