From patchwork Mon Sep 23 08:12:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13809380 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011036.outbound.protection.outlook.com [52.101.70.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B229F4F215 for ; Mon, 23 Sep 2024 08:11:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727079071; cv=fail; b=Lhp0YcTDL8V1Aghz03sk1Fpk9xMN5d0gMcaq1QewmqN7uK+yo2+JhLyWTDD5yiZIF+mYKUp0KphyPSPdcF+7HJlu2HSdJFQjTjzm2QuOA6zB9WWpdbf9iXarbt0g+vcGZ4oVHF4r9nDMO8+QtlAZeWZMvrSNnbzeluqqOnHzXj4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727079071; c=relaxed/simple; bh=eGXYF/Mvb3FCExUJeiCYcoTGUnGyX8YzOEh42vD0R80=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=ZGJBviMuRUBhKBp0DZVBOEZLRF32qQccKi3+/CW/Mm8ueu497WyrfUGto9u+6z3yVrda62lD9T8zX+Rtcbj5zH2HUZy2Sy4u29XfoPxIeM/xZdpn07Xt9AHWjJXJpz6wG1aZab1xm3k5MuyI3RA9tGyNP87vcVRC25iPrUw+AXQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=gI/rG8T2; arc=fail smtp.client-ip=52.101.70.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="gI/rG8T2" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CsoNmb3+yK1beInPYy2mPnPuvbqESgNjbEpmGpdXJ1l67o56wUwdN5phHUSTfYzjEQLaBVO7BxlebftrqntR7K621m8in8iAYeyMdvKTT76yF72S7QgZf0TIDw45zj7QMDyqnKZvuTlPiweeXgp0BKK4JuTjYfL40z2tITSX6e+ukkps2uKsIZJAzD507s7uIGjVHRXaPP68UPdHnVso1PL0iZyj/9/SGfv/WPPg/nhXgiMMHP2WTAZsA7RH7aOIUpKgwLVzQzzuQcw3vTyOJNaifZzMBagaLJ4gLgRavUtL/MmTF1Yxk96lZsHYaSHLyOvqTZ7X9v9wsECyP/C4ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9Ye8NjMJz6I7mT07gigiSOXZpMY+iI5gH2ci3E0dBxs=; b=NkSIhQscBE9Pro54U8jdABhNJJVXm6MQLPvJpG0tgsBuESUr5yfLzdcUfHUXGvsMN5Kn3HkVYnMQPVhVc4rmOvsPUOe3fgpM54CzRPVkGY4kRExqySgqeaA5rg7qwpZhT8yuDAULKz58ZQBQtJLE8Ghu8boMbARx32UVQ3W/0SwWg5f7VbQJBi/2HMXtIGorp24tymOE1V9lwONOHm4pYm8lP+RyJy5fMI0yPhj1CRS71KzaWA9I70Nx9meQwgOeaZDkPNbQb82a21lyhym9+i7oY5NNPkBYTMCgIKDMWRH5ssSuioltDxSOoS0rqzkvHDpBgjgeoJXXIPNSR0dH5g== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9Ye8NjMJz6I7mT07gigiSOXZpMY+iI5gH2ci3E0dBxs=; b=gI/rG8T25SOh1Bj4Kr+cx/xh3XQHYJzfS2GYFY+KNzyuQXrVDNPE/IeB4pK5zDQxh4ePnn8uCtYvmBVr+wLyu4zKTjoPpN3sMmQprlHNiy/YRIJlinEEg5Oquscg+dDeSI8pZtfzteWG9xs1JQYsGn+sJ+uUtUwTcc3JG4r/idttReZxHE7wYw4JoyidYINlPkuoW3AxPlpgQgTi6EbahhpvnJxQmNX/cXcKSY+/n+cK2zQ36IIIK/YLb906kixxrAq7j8VNpqkIEyJn9Y8EjoyJusM6ziNIjyvGYy0TsHOyp5D8XEAQ0Vu3DHuLAdT+QkZilIJloavJWtoz4YDB5w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) by PR3PR04MB7244.eurprd04.prod.outlook.com (2603:10a6:102:8e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Mon, 23 Sep 2024 08:11:03 +0000 Received: from DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::4e24:c2c7:bd58:c5c7]) by DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::4e24:c2c7:bd58:c5c7%4]) with mapi id 15.20.7918.024; Mon, 23 Sep 2024 08:11:02 +0000 From: Xu Yang To: peter.chen@kernel.org, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, imx@lists.linux.dev, jun.li@nxp.com Subject: [PATCH v2 1/3] usb: chipidea: add CI_HDRC_HAS_SHORT_PKT_LIMIT flag Date: Mon, 23 Sep 2024 16:12:01 +0800 Message-Id: <20240923081203.2851768-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SG2PR06CA0237.apcprd06.prod.outlook.com (2603:1096:4:ac::21) To DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8822:EE_|PR3PR04MB7244:EE_ X-MS-Office365-Filtering-Correlation-Id: de474912-7b66-450e-29c2-08dcdba743bb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|1800799024|366016|376014|38350700014; X-Microsoft-Antispam-Message-Info: 7yOw0SDxKgkXxXAIk13SEwiNPnGHdVz/XrQt5rBFBSOekSkM+K9Nk8xNxaz14AO0Slw+Z5antHQPP5dR4ICi1aPI6D0BHcG/CdjM6CmXJJPzxZFv88+0Vqo0e639Lrg8m3bKiaro3H7fUHEmRi8rR888hJDe9Sp3acIqwZvsoXY6uLE55H9pEuPTN/8OA9osk7cW1t7vAeCLexm3ibnIZgiF11XBdoM+MdMpKT/dW9M9UvRtB6r3lHI9Fh59Luj6PcYMhhFrMugopI/TtTSNal4QN4NXnxrTpFkpZB2lyQfgIFPWiufpf59Onei1nn20mUAIKCIM6v8oM9u7PZaSkg7dfUj1Zxn3a0q8a+fwy2pPElkbRGwNMMgpY8T990Bg5vqIjTO2gp1Yek1n67Q0iC+fM3Mq9TnfTQeBszI0JbI+vgNrG+7PdRWHUTMRuCtkMoSqeCsGUOUElX/tswwl6rxpVR2g+RAP1HyqkX45oSk3OSzMHapS1XVHRqhvBbgVNjDzqMVVXPDct0Im8n0/3s9eKj+e5uO1Gn3oCQ+O2ITQDWimCv3Pe7xzJYMePJ+CRjlFx6s9eu2IW71bN04k2TUTVldCg6CJd/EHnn11DqsyWaxuV0Ylbd358/C+rgAF/2cWqCDQHVhHEFI03Lg4hZVWUVZ16orQLYq93QUEKNXMiwUIOgmOEMT9XC3QTlTiG/8NCSbOuugr/BybO6VtVC5MkyFn0TgIDcLy9d+15n2GVvOMpbVR6DRZi6wbK+2pva2YOould8KV03PLUK4KxCqm38SXbkVA908tsXVJWNpQze49wXCE5xzRUepKuE+UeJ91FRxl9Mkx4G2R+H3eCd0/FIHMDE4V7qyqsjLOU/TXhqVlTtHMYNEabmdxMJMNe7sVDmbAg3J0n5No8qqczBb66ug3Tp3DVId2PqDrdZPDsxzxH6aidx0L9G/SLgc7fCfJHQWu+qNEVDtrG9XHbR+lJ6mJMpbcoCFTmBl1jS71FeM2Zo9qZpZ0aXLt/6NUguObQWN4tDSNdWxebzyR7txDEtJHMvOjbC1eBUJ6fh1a0MNNSLV7pWVwTPjpY9JzfcQ88mltfRPyVKSYS6MiVkqXU5StJnsXTI5wCBI048YjP/NXjqB2Rr+r2CQXys+Npf/mx0TjrX+ZNNYtQSkHCqo2HqDe/Xn88PxQDcfyeqc0a4cM8x6GhAhDNsSyvbj5E+Yqlk63Qu00DpCwisW6qNd1H0MRZzE8L5GAK+zxG8Ks1FHAsPOk1ZIUCXXCyBXEUp41YE8RRcnvpECO1WHsoeZc3z89jarkcVlv8bRU45RLJiQPMeW1+NoKmEfGR3rDMbNtKsTGf6nz9Ps+f4lq6g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8822.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(1800799024)(366016)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-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zP9HTDD4U7SBC1H5mVxbdMOrnPvvW3JgWaxRQ//ddElk4FV0GsqS7cuJvERRBpV0jDEdNDqFjOa9W79V1BdUbdFuIOq0nUjXeV1y7F4a7fKgfyt3JNhdfki+E+Z0LQAAsirG45CuGXdLu7zVFVmqkWYAJksZ3D4lyscfkQLuj9siIWjd6GlGpwW3j4rrASXfz2BbB9gYyiqp++UpbxDvwUEdBVh10tQNIPWMU9Q1J/UDJg2G9xVq8kCCJ7/7kPF6zVO/A5oGiJTYRYKkNSwp0/J3CXNsg535PY4sftFWJDFHcSFhF8gbYZ7EIKKy7CQXcCql9aPoTE/1MZul46RtKUWk/54ty7GMe6kE1pTjN5Nxx8ozdFTxYfkQHLYAPUkGk8Sy+EHCorMD0gvTz/g3QXhlXjxDpKbJoECSUxbZZi+Kl0erx1Lt/0w/ooSrkMVGAfMHOkJfE9dDVgbLlw/olvj+TmsuuUOQC2eWE3RW2PqwN5yHIun77mGPVIMLMfQee9VT7PWXbqowSNZAoNAm4Sfz X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: de474912-7b66-450e-29c2-08dcdba743bb X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8822.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 08:11:02.4150 (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: uQ0pZLe8l9c8WgIYEN3K/yyQvZzgstUVNKQsq5u+5Fhr5BK0xMeQtka6CZU8hqr1+j3LZly3rRKZYbydxeeIXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7244 Currently, the imx deivice controller has below limitations: 1. can't generate short packet interrupt if IOC not set in dTD. So if one request span more than one dTDs and only the last dTD set IOC, the usb request will pending there if no more data comes. 2. the controller can't accurately deliver data to differtent usb requests in some cases due to short packet. For example: one usb request span 3 dTDs, then if the controller received a short packet the next packet will go to 2nd dTD of current request rather than the first dTD of next request. 3. can't build a bus packet use multiple dTDs. For example: controller needs to send one packet of 512 bytes use dTD1 (200 bytes) + dTD2 (312 bytes), actually the host side will see 200 bytes short packet. Based on these limits, add CI_HDRC_HAS_SHORT_PKT_LIMIT flag and use it on imx platforms. Signed-off-by: Xu Yang Acked-by: Peter Chen --- Changes in v2: - new patch --- drivers/usb/chipidea/ci.h | 1 + drivers/usb/chipidea/ci_hdrc_imx.c | 1 + drivers/usb/chipidea/core.c | 2 ++ include/linux/usb/chipidea.h | 1 + 4 files changed, 5 insertions(+) diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index 2a38e1eb6546..e4b003d060c2 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -260,6 +260,7 @@ struct ci_hdrc { bool b_sess_valid_event; bool imx28_write_fix; bool has_portsc_pec_bug; + bool has_short_pkt_limit; bool supports_runtime_pm; bool in_lpm; bool wakeup_int; diff --git a/drivers/usb/chipidea/ci_hdrc_imx.c b/drivers/usb/chipidea/ci_hdrc_imx.c index c64ab0e07ea0..17b3ac2ac8a1 100644 --- a/drivers/usb/chipidea/ci_hdrc_imx.c +++ b/drivers/usb/chipidea/ci_hdrc_imx.c @@ -342,6 +342,7 @@ static int ci_hdrc_imx_probe(struct platform_device *pdev) struct ci_hdrc_platform_data pdata = { .name = dev_name(&pdev->dev), .capoffset = DEF_CAPOFFSET, + .flags = CI_HDRC_HAS_SHORT_PKT_LIMIT, .notify_event = ci_hdrc_imx_notify_event, }; int ret; diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 835bf2428dc6..5aa16dbfc289 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -1076,6 +1076,8 @@ static int ci_hdrc_probe(struct platform_device *pdev) CI_HDRC_SUPPORTS_RUNTIME_PM); ci->has_portsc_pec_bug = !!(ci->platdata->flags & CI_HDRC_HAS_PORTSC_PEC_MISSED); + ci->has_short_pkt_limit = !!(ci->platdata->flags & + CI_HDRC_HAS_SHORT_PKT_LIMIT); platform_set_drvdata(pdev, ci); ret = hw_device_init(ci, base); diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h index 5a7f96684ea2..ebdfef124b2b 100644 --- a/include/linux/usb/chipidea.h +++ b/include/linux/usb/chipidea.h @@ -65,6 +65,7 @@ struct ci_hdrc_platform_data { #define CI_HDRC_PHY_VBUS_CONTROL BIT(16) #define CI_HDRC_HAS_PORTSC_PEC_MISSED BIT(17) #define CI_HDRC_FORCE_VBUS_ACTIVE_ALWAYS BIT(18) +#define CI_HDRC_HAS_SHORT_PKT_LIMIT BIT(19) enum usb_dr_mode dr_mode; #define CI_HDRC_CONTROLLER_RESET_EVENT 0 #define CI_HDRC_CONTROLLER_STOPPED_EVENT 1 From patchwork Mon Sep 23 08:12:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13809381 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011036.outbound.protection.outlook.com [52.101.70.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3DD774F215 for ; Mon, 23 Sep 2024 08:11:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727079073; cv=fail; b=LmZ0Lp+Vsx4eFmq99w9sFYLH2eMJ+LX5WIVEDaCy97GQrchdJSCVTmfxlLq8ZmCYvXFfd+gGVS9EFYeWqQthYgJZGZSPFpSLCduZjS3AS0K1oMy8/q3Emd78bW4wghF7K0fEKQhGBjGgjp/eWbIH8wZrBeBh5RBe9SkzkOomQQw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727079073; c=relaxed/simple; bh=ACUEC30puNZB1M3QRbJbowjVa+UdnNqQgRllQoaY6RE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=L4Uyb4egmdwnRhuxr9a7T42d5E3IDaL+B8WRSHXEVOO5eftnIbIZItH7GrdnxUdnfx2F3AB/7lNGzenJPcJZS45xY0Skg+hSHP097YOn/wR7k2KgvSbICROZ+qFn310kDPNAO1ejXgDk7b7gxLTubdt3qidJMrxlj21dYlqjFco= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=Y5bZ5M8g; arc=fail smtp.client-ip=52.101.70.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="Y5bZ5M8g" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Z/f/7FjihFeU6YAyjHgT/LBNVytUgwNKLmLz+Mxw3VAVdRfh227Pv9Wh5+9vbnyVj8HZhj4c+7FL+cVzX6DeE4AKDzkTNBvw9UIDhBb0Ze61ZITvlAEamdG/FZKAXTRXgZP6sDxEv95kSYP5710Nqha5mnT8J5lR2tjX7MYxCtwJ/m2zC0NmsaDlYqblX4GnMq64sofmTIkhIn+hnrK5Llmd+DRFo2i1nwiJV6B2+fXUcvYVG9Zvr0ub0eSFKf3FSzdEl79Vy2mcRqH7dzPFSChvCXxp53EjhQKUzgGjT7pNOptK3+m6XYfwrSEuFudLQ7V8+zMJgNWszbSQOGDF/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YhZ1i4b3f20/FBIzXCqa6JnlMB0/tS68AHYo79JYnss=; b=BJraRwEcyT5lHT71e6j8TsJnPI2SSohJRjb99yXjSyETIE2yMuiRZWRjaSfNLmQmjzNnXfWmoxkfroEmHU2yUMQeFNPtJX0MYKSOVvr6S7SlO2JFeaDz1nTpc9A5E5C4yjE2hmQASBMeUFgWs6kFkh3Mrqrqcw+i0V6DSIn0rXpAv1pl+SGV8x9oWtYSj+/EZLMS3fQeEpEHcCiPbn1HQfmImlZ9oNb5QIpoxfVmolQALoKwdygd2azJIPHvzGnx0IGVQJBhI/HvNMgiN5Hanq0dqSjYmPWHfqTAZnjfAQU7GkupbZceTQ4DT3Wxw98WZwTt8fEpUNoKdu24z5fJ3Q== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YhZ1i4b3f20/FBIzXCqa6JnlMB0/tS68AHYo79JYnss=; b=Y5bZ5M8gpOzQ4QdanlUEysTJ9Cc2ZAyUqy5ZF6or+4l96AK+wR3W7v6F86107b51gPRtgHDuVhsZspjgwaz3z4lMi5M/3wNEK3bGsXt1iexcBMeAUo/c6BgaTXpW1B+TyXda8/vevvOMfK7B9nNzvOzpX6NKcgHx3tvMl3mpsDUgJOOeZ2gw3hZ1nMfXx+sTlGIQPsw2yzdmzRk7gUseA6nMQW21Vi/RwtMF5octILsb3xzz4t6Tq0jikAjZob4hOmCp5c9lFH8nz7S3V6MldxhINv2Ezfipcr0/UgMjEkW6guqJ/GeVV2zq54QTQMxsgmsVdog9TmqN6gJxjbk0Vg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) by PR3PR04MB7244.eurprd04.prod.outlook.com (2603:10a6:102:8e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Mon, 23 Sep 2024 08:11:04 +0000 Received: from DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::4e24:c2c7:bd58:c5c7]) by DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::4e24:c2c7:bd58:c5c7%4]) with mapi id 15.20.7918.024; Mon, 23 Sep 2024 08:11:04 +0000 From: Xu Yang To: peter.chen@kernel.org, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, imx@lists.linux.dev, jun.li@nxp.com Subject: [PATCH v2 2/3] usb: chipidea: udc: limit usb request length to max 16KB Date: Mon, 23 Sep 2024 16:12:02 +0800 Message-Id: <20240923081203.2851768-2-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240923081203.2851768-1-xu.yang_2@nxp.com> References: <20240923081203.2851768-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SG2PR06CA0237.apcprd06.prod.outlook.com (2603:1096:4:ac::21) To DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8822:EE_|PR3PR04MB7244:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ff5c75f-ebec-462e-69c9-08dcdba74517 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|1800799024|366016|376014|38350700014; X-Microsoft-Antispam-Message-Info: GVmuyDRpZEJwnusGb5F/3tjTkUoujl9rn2jhr+hgEzv50wCbih/x0TIU5E+F+wDGTsdRs+BxvGGpKJR39WXxepybH6AzXHKs783bKgX92VW267z18BYKwGcKOHcLN4+F8t0R4CVpakqi88MdRy7pW+wFNTEgFBBpeX3xx2MubTgf+LoDzqRww0WQ4tOD2qFCZ2Da9PWfcE6c0R0UISO8ViqksQmuqdzld8AdT+PsD2bTrPp87PeWWSLiOTYjuBu/24zBy1uhdvZ6wjeo+EgP3CEsxu7XqNFQn6J64+pdXHcT4YPVmBm1tj2+8xPw9cvPAYugI1hxoMVy/yzP1qe3UJsG85f/3fQ+m5BwnNly3Ep2gnbLvn53ZKDVYt5BuXnj3AsgOCOrLe/9yEzLNdIulKU+LaGJtO2Y7WAk8TjZZybHxQR2oumPb3aBusbEP4UADfHGh8uFvmCJTlpmxsTvqCIDfNDqOaZXwm8GuqdeK7xvvw6310Fj4X6VKYIBYt1Mc6BhwC/3OlT7WX6L9L8r4Gww3ImGO2j6+EEWDMRQZjbHWdiJJU5GmYq50W7hLmFeAFhzSIg8cmAbf+7X4EQAy79kc2hr4bVF7exQ3HA2W705ef+hamsYlMMkAWXem+wGjga1/9sxzQ3TafZtmpb9GvsLV+Tonz85AQC0ghReX6I1Nl8nBMj1L/w4kAc+xShlTZRKt5ewEHsqGFToSKpCrnraJuIV/jearBXzF6CdHXJtBhPJG/aUdO3cdyIJMoPDkrs7ynx9pU4mOc3mSsvza/+qwtnX69shJkkgp1h2JOTbGQNDjMmlXq7ChbuqJ2vcYZXhQB4Th/uH3BmJmn42AwLI7K/djF2bgLi8/vDB5lJkZpMnqSKtitLurXUrcYOYK3t1yk+uNtTl59ckGcYVwpNgnx+cMA8G0v7eUOPUC0fgRpxsL8V8ISoRYcQ38y6KuG8CrWPUfcnb6lvhn9wryUVfX1yubo9jVmxD/ohFHV2GMp7ctixm1GQuFzUwXr9FH3knY4t2gBM+ey5H6eUCkdcv3bM2bMqOKtgNoPcABAn4c8Ehwp+TtOPeIIwXkICdfDgdvcVslfN99EYY68YpVP1x9vXIjVyVJjPQSR/Qs7/gJLQWS+D1AabiUU5kN06oJupOygINIFDSwfvu12t4p3gj92w+ORUdPvIxXdfPRS20uRvs5RFAtc6OpEIeE/9KSiA6aal9l8v5+ABa+IiTCrroOlGIe5815hGDcizZFDSIMm4U0AZB+/9a4cufo0gY2qnA9uklcSmrdx0gV2bDtIs6ggFKw+nyhBohQ6Bw8ayBu0stYGRFyjW9GrBKwAoucRZmBtnZN9I0pAIMoJeM6w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8822.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(1800799024)(366016)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pMrOIOJxt3TXoMuf+uiem2D9Dzfml7q0AgW3Rgt4plNWMfLlZ8j9td+L040tSA83imK2CWDhuB1hJSGWw47n9DMz3908hjAUmoP+ODvUEX2GFUs4rSW9MuLondpYDkQZqf8J6bvqXNAld597dsrcF6IlcMBr8KoV5u47JiAh9QpBEBduaOxsRdUohogWIqYFHMRkmxyFkm3E2zwIiSp+nTSfytOOAB3d9UqeXJk0SQubBYFkS5H+c81zqgmeLNZCGWwnecdDx+T6IVpLXFOsLWqFaFbfS173nTjidQYaopS5nSxBOPaqwX5ja3Si6dv8AvyPyZGTXjxYlX/j6e0cGUTtz5fF93RrVgwhJKvbQHYFKuDOs89BlJAkHJVpUhijXIQ7f8ScxmQqcduECiX88meOQhFkLc9c2n4YXMUciHTCJTeSttm0x6GasblA6m8pgGNfuN+xzJ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qoNEvC6Xi+h1zn/tjkzkddeIincLZ1Jf1mxw+EGfWBC8QnmTjVPFaOeAdyyItHZj5Eqz X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ff5c75f-ebec-462e-69c9-08dcdba74517 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8822.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 08:11:04.7679 (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: KXv98pVDQ3jo4eZyqSqBISwuFOdZqnqiLhmRmdpJ6KjUE6sOoVNDVLL2cO6pkD/ydlERcXj1quC3jaqJDz6chg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7244 To let the device controller work properly on short packet limitations, one usb request should only correspond to one dTD. Then every dTD will set IOC. In theory, each dTD support up to 20KB data transfer if the offset is 0. Due to we cannot predetermine the offset, this will limit the usb request length to max 16KB. This should be fine since most of the user transfer data based on this size policy. Signed-off-by: Xu Yang Acked-by: Peter Chen --- Changes in v2: - limit request length only when ci->has_short_pkt_limit set - modify commit message --- drivers/usb/chipidea/ci.h | 1 + drivers/usb/chipidea/udc.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index e4b003d060c2..97437de52ef6 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -25,6 +25,7 @@ #define TD_PAGE_COUNT 5 #define CI_HDRC_PAGE_SIZE 4096ul /* page size for TD's */ #define ENDPT_MAX 32 +#define CI_MAX_REQ_SIZE (4 * CI_HDRC_PAGE_SIZE) #define CI_MAX_BUF_SIZE (TD_PAGE_COUNT * CI_HDRC_PAGE_SIZE) /****************************************************************************** diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 18c1882cf088..5badb39cb2bf 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -972,6 +972,12 @@ static int _ep_queue(struct usb_ep *ep, struct usb_request *req, return -EMSGSIZE; } + if (ci->has_short_pkt_limit && + hwreq->req.length > CI_MAX_REQ_SIZE) { + dev_err(hwep->ci->dev, "request length too big (max 16KB)\n"); + return -EMSGSIZE; + } + /* first nuke then test link, e.g. previous status has not sent */ if (!list_empty(&hwreq->queue)) { dev_err(hwep->ci->dev, "request already in queue\n"); From patchwork Mon Sep 23 08:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13809382 Received: from AS8PR04CU009.outbound.protection.outlook.com (mail-westeuropeazon11011036.outbound.protection.outlook.com [52.101.70.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44CC44F215 for ; Mon, 23 Sep 2024 08:11:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.70.36 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727079075; cv=fail; b=Br8Ki5f/x21qMJqp4s8QcqJ6MeiiE6lnBiZR0ybm9o4yZmogx1OjAeDcILoYcQIC78EaBgGMqW3KwjgIRQj0xD8/4bow1BUooATKE1bVsV2Wxi5L2uLo+080ELqq3OH6HDWqxW13sAjhwsYSwN+Utyjf6F6Kzyz8yTPBCW3brg0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727079075; c=relaxed/simple; bh=Hfqq2gKviGZoX5M5SLxYQNMsXxBIWmcuHVEMBwtQkNE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=jrvBgtbRyXSiFsb0DKJJhfw9BZdNDvyMRjSfyNDIBFW3n7raRdt/RKnDU8mGdd0LFpKKEVECt7bNNfiAC1OOgMgD/VwBwg1SaX65ui3kaH2N66tBoPB6nWo/B/oZoehoTRmN9pwfxW6mgW8iySSqZlK7B6aa1T7TH32iDzV0POk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=O4GzTVk/; arc=fail smtp.client-ip=52.101.70.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="O4GzTVk/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cb1BY5p0Vr5aNYAyEs5XhtZhhkpjt0kuawbvkj1R44EuGpawZjIlcoDCilitOSdnn/ekoUIenx4TKbhGjv1PAdRvIlHYjahqrN9UQuq1zECP2iuw7QjR4RleQBlxB6egoth/5BBDb81G2DyqJBrB3phNHeViXos8m45af2FuviUOocYuQp2Afhp3vcFV4dsZ7i+dGu4U3bUruPNr3ZgZH6c6B+A+pheuLiUZe4w/urG+HpmqqAcTJ9kECbiylp/qJq+td7/iBlh45XRASqBGOnVDS5oCcpwjbzG3G4HnfXQHS/Rrinb4+1mWjHPjcUJXdCRl0d1Ofq1FAf7B539UQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=aMhZP/5QVHjnuanH9acnHrgJyprB/uX6cWEDIRp0jkA=; b=nWQU2fq5r/RcvNsx8TVA6oE2bpn+SjosngBsFt6ICJtKBvFJHJ+3CG/Qyx65pVOKGvm/Mpwhbpybaso/fpWywn0bbqp/m8a/wVFfgUduX30momuHOR08fHPmgWgt5JYxNoKC2OTp7ydlRaTMAZa9HP7TCN8T2sxZTcjVN3FwFPNcrSr6HlDeFWIRsxlk6E5gMdrBFKTVSl95gTZJyHqtx00GmK16b8eJ+WsCyiuJNCTqzbkaJPC50yg/XboEUjbbya3cxPMSHQ1Xe6uQ+xZidFTlPojYvwE7U0ewky5tJuOT/Tf370g0JYU/0Dd0rNqEEWl1rOFwjMvQJxZ3SiRodw== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aMhZP/5QVHjnuanH9acnHrgJyprB/uX6cWEDIRp0jkA=; b=O4GzTVk/ffbv7rI3vbZp6cgXb9z6sNIR1JjlxxHChr230AFldyd0oOqS0OCyUWpvJnsp838DZMT5qIzKYpBSMp8uFtL7foya49TW3CmM9PnAQ3E9Cr5UpTQLDGUuRoAjAqEUZT+hWcRMq7GS+jfkIudfiq0qi6KjwbClmO+sTP1DNuXrAK+eOO1oEkdUPM9V1TbvXcDQKKQBc6S7VtjbQciEUqU4Xc3QUiqsDHzxrGZ++cv1XlzZg2C9oHWBVAe51fxFY39i4ZsuffXHAde7ml12RztUUbAiw2HMJBYz/s+biLtLYdGWsjUWK8DR3KyG3YTqHTQktmTHK9wsRtfxww== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) by PR3PR04MB7244.eurprd04.prod.outlook.com (2603:10a6:102:8e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Mon, 23 Sep 2024 08:11:07 +0000 Received: from DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::4e24:c2c7:bd58:c5c7]) by DU2PR04MB8822.eurprd04.prod.outlook.com ([fe80::4e24:c2c7:bd58:c5c7%4]) with mapi id 15.20.7918.024; Mon, 23 Sep 2024 08:11:07 +0000 From: Xu Yang To: peter.chen@kernel.org, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, imx@lists.linux.dev, jun.li@nxp.com Subject: [PATCH v2 3/3] usb: chipidea: udc: create bounce buffer for problem sglist entries if possible Date: Mon, 23 Sep 2024 16:12:03 +0800 Message-Id: <20240923081203.2851768-3-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240923081203.2851768-1-xu.yang_2@nxp.com> References: <20240923081203.2851768-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SG2PR06CA0237.apcprd06.prod.outlook.com (2603:1096:4:ac::21) To DU2PR04MB8822.eurprd04.prod.outlook.com (2603:10a6:10:2e1::11) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8822:EE_|PR3PR04MB7244:EE_ X-MS-Office365-Filtering-Correlation-Id: 81c892ee-7128-4a1c-7535-08dcdba74674 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|1800799024|366016|376014|38350700014; X-Microsoft-Antispam-Message-Info: PPopRSKxg/QXwTix4X8Wp3S49lrve72aPFe23dsIab4D9eKb9CnDrKMbUQ8fen3Fvgr9MGoEjAAJ6u5rnbgX+mwdsF8g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3TRupeHGRkXvfnTn/wk5NqwWvv36NqC5F5fIgE2V1ytMi6H0AdJaSVfMZw+Msv05RTfLT/FRIg0Tk+uT+cr11GmeHHUT7QzkARB9irXn8pCJRBwxzP/+bFG2x2vpvFndIQTCbsDBF70pPJ/qBT0Owq2FpI1DxYmk8qOZG6Od/JqzDBkebOrWavWQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8822.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(1800799024)(366016)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TnyJeZ5yGsKQqLW6OcFiBRIJF7c7OIZP4aZir1VrNHdb9PXWjSKd2ibO9VblyBc8B2zJBK8G12JHsulbPqocJAsrr/VJVO6Haj39l60+28JbHn4hiwHa0j+9j/7Tmbeh8EV/Nsg8V8UHebGOLEvNBakCIW43pAyGqz+nRhXn9oE2gEgdnMBHMDULWs1H26tEngCU0V4dLA4ZcmJjc3ZCS6ihQmL3OENOURhdyGHv/oFoW62zWJ2b4rggcW+9V011GDGhC8yqUBZZI1QmunPVc7Zcw7CuIysWv8/D50t6dLcQa9WDQqYLlaSeBqCEry3nwU4BRr73CHrHrLeN2XxtVesOKYoosonxv1I+mWf7IN8QHp7HKh86yO0hU4iP2ToR5SuJS1ZjB06JzIb9vig3Obh4Mu/qD/gcTh//8FV0pMQE6zNPI4kY9DftqLtZmRVEz+kdKOhO8pgR3zEAlftebXDut/8eVcFHOhvNm+xAkpB8kSBHkwS5JHQOtinNdmbJk1oafpI3qeR/L9uKHZiOxg8Mi3fJGbGS0aON02uc1T77tTxpCjm0WxQw8eQEST5T/PjdqHOfV/+GNqdNhT71P2Q98I/SH8AHkcELQHNCJX639OWjsi4hTD/IrE9emIY/FwR2wU1LOGllX2atVbugkUwNbykbSizFzoxFgoYtQiqU/vO373CLU4R7OQwlt6UPfpZV3UIlreU0h7WVR3rIQkbnxlB9effzqkCTAD2PbvKrvi8CnLHk2W70KGL3XA/jfGGNJh6fd/AzCksyh2aCHsGN1dp9n4vtNFzhy8PTKG5d993rrFjhnkU2mCKb/khkb0XvVYhgFUMD2jI30HzU4o2u+CfJVvwFmJ3RLC4GaWDHsQbd8J6gelZXR+Rcaj3aULHiBcLkKBFP0sJr6MxDM151adY71dnd3kl0Gi4n7Kyd+dgIZQCDAWxWxmtTJs5wdqq2A26CICnxY12BTX56BBUqGXLVQiteb6hOu9R4tp6NQlv2PMvODv7X6WPrELkUZS6WYzbuITPgeIv0eiBhLbM7OuVOxwliclS7G2YqmfTQB+G8SXe1SnHPbOqvhMBjdEoY/wfWhghASEdBvQu+04c3DkiWjWetacHsIpEWhHwIIAXhQe65Dy1YQQ1lHNPSOn2Gs4zYjtwVyODacyW9M2AiLKMu9IefgQZoWqVsjJWR5BXB8R9vTTatxnTqUDvCoZij7jsFkxoT295eKi8yWW5ghklRnCyJoDv/BxUhlViUGB50N4Thoj93Y0N8G9nciaPX66AGGrmh+3LYZnBg0560RvtKyb+WZY1nOMSXrdVgaPnc7WMbgP8NQxhbN8KF7eRvlkmE0aFoOntd/XALcHQnIEruaPFz9ePb/wtMDr0BR9tYHVd2/z3KXsP16IWR4wWPX1RlKqq3gRBg5eWYYNfWtA75Zmg/h4p3oLvxc8mlKvKEiM9JkaAmR7Fsefm2WKvTepZmQRmNEFcZcTE4rSNdAxXANLVHaNQQj46VnAnz5TasAvfdTH0nYXZupWUGafvok1qZAZO4xEsJ7hmFP0qxXTvd5VtzETa+SOarrBKKpbMXwvOT2Z3MslR2tDk5 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81c892ee-7128-4a1c-7535-08dcdba74674 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8822.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 08:11:07.0087 (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: 7xN2/3Rxg1mCuvzTPAPs+ePi9jGSAI6hMeDEQHAgrqa1vK/ADk/rcMvFHrOdtKnj5jbICF7+sfB3vF9toSn2Lw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7244 The chipidea controller doesn't fully support sglist, such as it can not transfer data spanned more dTDs to form a bus packet, so it can only work on very limited cases. The limitations as below: 1. the end address of the first sg buffer must be 4KB aligned. 2. the start and end address of the middle sg buffer must be 4KB aligned. 3. the start address of the first sg buffer must be 4KB aligned. However, not all the use cases violate these limitations. To make the controller compatible with most of the cases, this will try to bounce the problem sglist entries which can be found by sglist_get_invalid_entry(). Then a bounced line buffer (the size will roundup to page size) will be allocated to replace the remaining problem sg entries. The data will be copied between problem sg entries and bounce buffer according to the transfer direction. The bounce buffer will be freed when the request completed. Acked-by: Peter Chen Signed-off-by: Xu Yang --- Changes in v2: - judge ci->has_short_pkt_limit - add Ack-by tag --- drivers/usb/chipidea/udc.c | 148 +++++++++++++++++++++++++++++++++++++ drivers/usb/chipidea/udc.h | 2 + 2 files changed, 150 insertions(+) diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c index 5badb39cb2bf..8a9b31fd5c89 100644 --- a/drivers/usb/chipidea/udc.c +++ b/drivers/usb/chipidea/udc.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -540,6 +541,126 @@ static int prepare_td_for_sg(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) return ret; } +/* + * Verify if the scatterlist is valid by iterating each sg entry. + * Return invalid sg entry index which is less than num_sgs. + */ +static int sglist_get_invalid_entry(struct device *dma_dev, u8 dir, + struct usb_request *req) +{ + int i; + struct scatterlist *s = req->sg; + + if (req->num_sgs == 1) + return 1; + + dir = dir ? DMA_TO_DEVICE : DMA_FROM_DEVICE; + + for (i = 0; i < req->num_sgs; i++, s = sg_next(s)) { + /* Only small sg (generally last sg) may be bounced. If + * that happens. we can't ensure the addr is page-aligned + * after dma map. + */ + if (dma_kmalloc_needs_bounce(dma_dev, s->length, dir)) + break; + + /* Make sure each sg start address (except first sg) is + * page-aligned and end address (except last sg) is also + * page-aligned. + */ + if (i == 0) { + if (!IS_ALIGNED(s->offset + s->length, + CI_HDRC_PAGE_SIZE)) + break; + } else { + if (s->offset) + break; + if (!sg_is_last(s) && !IS_ALIGNED(s->length, + CI_HDRC_PAGE_SIZE)) + break; + } + } + + return i; +} + +static int sglist_do_bounce(struct ci_hw_req *hwreq, int index, + bool copy, unsigned int *bounced) +{ + void *buf; + int i, ret, nents, num_sgs; + unsigned int rest, rounded; + struct scatterlist *sg, *src, *dst; + + nents = index + 1; + ret = sg_alloc_table(&hwreq->sgt, nents, GFP_KERNEL); + if (ret) + return ret; + + sg = src = hwreq->req.sg; + num_sgs = hwreq->req.num_sgs; + rest = hwreq->req.length; + dst = hwreq->sgt.sgl; + + for (i = 0; i < index; i++) { + memcpy(dst, src, sizeof(*src)); + rest -= src->length; + src = sg_next(src); + dst = sg_next(dst); + } + + /* create one bounce buffer */ + rounded = round_up(rest, CI_HDRC_PAGE_SIZE); + buf = kmalloc(rounded, GFP_KERNEL); + if (!buf) { + sg_free_table(&hwreq->sgt); + return -ENOMEM; + } + + sg_set_buf(dst, buf, rounded); + + hwreq->req.sg = hwreq->sgt.sgl; + hwreq->req.num_sgs = nents; + hwreq->sgt.sgl = sg; + hwreq->sgt.nents = num_sgs; + + if (copy) + sg_copy_to_buffer(src, num_sgs - index, buf, rest); + + *bounced = rest; + + return 0; +} + +static void sglist_do_debounce(struct ci_hw_req *hwreq, bool copy) +{ + void *buf; + int i, nents, num_sgs; + struct scatterlist *sg, *src, *dst; + + sg = hwreq->req.sg; + num_sgs = hwreq->req.num_sgs; + src = sg_last(sg, num_sgs); + buf = sg_virt(src); + + if (copy) { + dst = hwreq->sgt.sgl; + for (i = 0; i < num_sgs - 1; i++) + dst = sg_next(dst); + + nents = hwreq->sgt.nents - num_sgs + 1; + sg_copy_from_buffer(dst, nents, buf, sg_dma_len(src)); + } + + hwreq->req.sg = hwreq->sgt.sgl; + hwreq->req.num_sgs = hwreq->sgt.nents; + hwreq->sgt.sgl = sg; + hwreq->sgt.nents = num_sgs; + + kfree(buf); + sg_free_table(&hwreq->sgt); +} + /** * _hardware_enqueue: configures a request at hardware level * @hwep: endpoint @@ -552,6 +673,8 @@ static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) struct ci_hdrc *ci = hwep->ci; int ret = 0; struct td_node *firstnode, *lastnode; + unsigned int bounced_size; + struct scatterlist *sg; /* don't queue twice */ if (hwreq->req.status == -EALREADY) @@ -559,11 +682,29 @@ static int _hardware_enqueue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) hwreq->req.status = -EALREADY; + if (hwreq->req.num_sgs && hwreq->req.length && + ci->has_short_pkt_limit) { + ret = sglist_get_invalid_entry(ci->dev->parent, hwep->dir, + &hwreq->req); + if (ret < hwreq->req.num_sgs) { + ret = sglist_do_bounce(hwreq, ret, hwep->dir == TX, + &bounced_size); + if (ret) + return ret; + } + } + ret = usb_gadget_map_request_by_dev(ci->dev->parent, &hwreq->req, hwep->dir); if (ret) return ret; + if (hwreq->sgt.sgl) { + /* We've mapped a bigger buffer, now recover the actual size */ + sg = sg_last(hwreq->req.sg, hwreq->req.num_sgs); + sg_dma_len(sg) = min(sg_dma_len(sg), bounced_size); + } + if (hwreq->req.num_mapped_sgs) ret = prepare_td_for_sg(hwep, hwreq); else @@ -745,6 +886,10 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct ci_hw_req *hwreq) usb_gadget_unmap_request_by_dev(hwep->ci->dev->parent, &hwreq->req, hwep->dir); + /* sglist bounced */ + if (hwreq->sgt.sgl) + sglist_do_debounce(hwreq, hwep->dir == RX); + hwreq->req.actual += actual; if (hwreq->req.status) @@ -1592,6 +1737,9 @@ static int ep_dequeue(struct usb_ep *ep, struct usb_request *req) usb_gadget_unmap_request(&hwep->ci->gadget, req, hwep->dir); + if (hwreq->sgt.sgl) + sglist_do_debounce(hwreq, false); + req->status = -ECONNRESET; if (hwreq->req.complete != NULL) { diff --git a/drivers/usb/chipidea/udc.h b/drivers/usb/chipidea/udc.h index 5193df1e18c7..c8a47389a46b 100644 --- a/drivers/usb/chipidea/udc.h +++ b/drivers/usb/chipidea/udc.h @@ -69,11 +69,13 @@ struct td_node { * @req: request structure for gadget drivers * @queue: link to QH list * @tds: link to TD list + * @sgt: hold original sglist when bounce sglist */ struct ci_hw_req { struct usb_request req; struct list_head queue; struct list_head tds; + struct sg_table sgt; }; #ifdef CONFIG_USB_CHIPIDEA_UDC