From patchwork Sun Nov 18 10:09:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Laszczak X-Patchwork-Id: 10687711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B357B13BB for ; Sun, 18 Nov 2018 10:11:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A162129D31 for ; Sun, 18 Nov 2018 10:11:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9505629D38; Sun, 18 Nov 2018 10:11:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A7E129D3E for ; Sun, 18 Nov 2018 10:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727593AbeKRUbH (ORCPT ); Sun, 18 Nov 2018 15:31:07 -0500 Received: from mx0b-0014ca01.pphosted.com ([208.86.201.193]:41298 "EHLO mx0a-0014ca01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727332AbeKRUbE (ORCPT ); Sun, 18 Nov 2018 15:31:04 -0500 Received: from pps.filterd (m0042333.ppops.net [127.0.0.1]) by mx0b-0014ca01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id wAIA8q7E007702; Sun, 18 Nov 2018 02:10:51 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=proofpoint; bh=Ri0rRoCuzi5Zwr6rL2q84TLb34WtlpwOf1ixAbyJhXk=; b=P5Y7POIcio1Df7c07gUew2Kx/qBt0VG1rpCpGHTpybtzKby5zCXw4BaF7YBQFjbzwVkZ OVd6PbLp04zmySAbAtp3OJvq6+fBnyvHgfPpwjTY7lePCXyQVJIzIi3KS36LoXkdHtat IyFvkWOOHJB5OOnh50ayC1DiUG5vSe+uE3/JBJfBJ8617RDLcp91fntODkoVAw4RJzlX 3FoQ9oURfFaSrpetnCVmrPt+4DlXA5Cq3YrvcKNzPC7I//UD2gIma6wV7n/3nIcNQbNc NpEzD4PtTRuKxA3y89mkMmYurhD1+BQZjWmrG5dNQWYJhFlM48Ktmq9YJc0YC8y+xyd3 yA== Authentication-Results: cadence.com; spf=pass smtp.mailfrom=pawell@cadence.com Received: from nam05-dm3-obe.outbound.protection.outlook.com (mail-dm3nam05lp0118.outbound.protection.outlook.com [216.32.181.118]) by mx0b-0014ca01.pphosted.com with ESMTP id 2ntff7w450-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 18 Nov 2018 02:10:50 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cadence.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ri0rRoCuzi5Zwr6rL2q84TLb34WtlpwOf1ixAbyJhXk=; b=hw8HbTXKXUI2o9yxbaOrJp3ZqNyXucezc1ripe6al7GZyIdqLVfEGZKFRHwb+miqGkHpjH3D2CQFrZY1uxK3XEVEnhBLSfymEairVu2m1Fi6Z2/N2yjcgypXrFCR9lfSSj5qpN8GkN8sEZz+eIVz3q7HVb69+wH/FzFOQnTN8K8= Received: from CO2PR07CA0063.namprd07.prod.outlook.com (2603:10b6:100::31) by SN1PR0701MB1870.namprd07.prod.outlook.com (2a01:111:e400:517b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.26; Sun, 18 Nov 2018 10:10:47 +0000 Received: from DM3NAM05FT042.eop-nam05.prod.protection.outlook.com (2a01:111:f400:7e51::202) by CO2PR07CA0063.outlook.office365.com (2603:10b6:100::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.22 via Frontend Transport; Sun, 18 Nov 2018 10:10:47 +0000 Received-SPF: SoftFail (protection.outlook.com: domain of transitioning cadence.com discourages use of 158.140.1.28 as permitted sender) Received: from sjmaillnx2.cadence.com (158.140.1.28) by DM3NAM05FT042.mail.protection.outlook.com (10.152.98.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1339.3 via Frontend Transport; Sun, 18 Nov 2018 10:10:46 +0000 Received: from maileu3.global.cadence.com (maileu3.cadence.com [10.160.88.99]) by sjmaillnx2.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAb5U029622 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Sun, 18 Nov 2018 02:10:45 -0800 X-CrossPremisesHeadersFilteredBySendConnector: maileu3.global.cadence.com Received: from maileu3.global.cadence.com (10.160.88.99) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Sun, 18 Nov 2018 11:10:44 +0100 Received: from lvlogina.cadence.com (10.165.176.102) by maileu3.global.cadence.com (10.160.88.99) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Sun, 18 Nov 2018 11:10:44 +0100 Received: from lvlogina.cadence.com (localhost.localdomain [127.0.0.1]) by lvlogina.cadence.com (8.14.4/8.14.4) with ESMTP id wAIAAexH032166; Sun, 18 Nov 2018 10:10:40 GMT Received: (from pawell@localhost) by lvlogina.cadence.com (8.14.4/8.14.4/Submit) id wAIAAeAY032123; Sun, 18 Nov 2018 10:10:40 GMT From: Pawel Laszczak To: CC: , , , , , , , , , , , , "Pawel Laszczak" Subject: [RFC PATCH v2 12/15] usb:cdns3: Adds enumeration related function. Date: Sun, 18 Nov 2018 10:09:08 +0000 Message-ID: <1542535751-16079-13-git-send-email-pawell@cadence.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1542535751-16079-1-git-send-email-pawell@cadence.com> References: <1542535751-16079-1-git-send-email-pawell@cadence.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: maileu3.global.cadence.com X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:158.140.1.28;IPV:CAL;SCL:-1;CTRY:US;EFV:NLI;SFV:NSPM;SFS:(10009020)(39850400004)(396003)(136003)(376002)(346002)(2980300002)(199004)(189003)(36092001)(356004)(486006)(51416003)(76176011)(50226002)(8936002)(186003)(26005)(126002)(86362001)(2906002)(426003)(446003)(11346002)(6666004)(4326008)(336012)(4744004)(476003)(2616005)(6916009)(107886003)(4720700003)(47776003)(8676002)(246002)(36756003)(7636002)(5660300001)(54906003)(16586007)(478600001)(305945005)(106466001)(26826003)(105596002)(42186006)(87636003)(316002)(50466002)(217873002)(48376002)(14444005)(2351001)(309714004);DIR:OUT;SFP:1101;SCL:1;SRVR:SN1PR0701MB1870;H:sjmaillnx2.cadence.com;FPR:;SPF:SoftFail;LANG:en;PTR:corp.cadence.com;A:1;MX:1; X-Microsoft-Exchange-Diagnostics: 1;DM3NAM05FT042;1:YII8wd/a4EoFRCSoGFM6rSQ7bfh1yKmP8yzbQUsgDDqqqPx48NqG5iGKXTto0ZX1gPYkOjN7ITa8XUf4O3ib1NASbVZJp1Leb+ZvvTURN3ZaVdKYkIEmWzAGud1nKjso X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ed79e2ba-3de0-4c21-e49b-08d64d3e1be0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(2390098)(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060);SRVR:SN1PR0701MB1870; X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;3:3IgVhbvGQF7/83WVQb6qc1dyjo8BHOurWh2nPzPs+wG+5cIu4XEfbA0B5WK2h9jfxWhYBrdzf9imy54zgeWMWyx/EUu+/icBWTq+KFU8YfJtJtstY7TbjDcSvXrqig3noOvXxcRz8Dc1wl2Sdeyxcq5JwXyxw9l0phD7XXumBcaSrEBAGsPYkiiB4kTZQEhubfoYDfutCQ3sjymsEjQ908uof4C/xhP2g/Wl3GUbklalfwc8Rb+3y5ZXzfL+Yp+A8vYEdBcqPE5j+yVnzoWJgWJPEVYarO4FRSWCWGP22urgPkviIxLSdDbYfLxX6pfOVqEwtV0fwzWceI+sqB4HEhlzkhPWn9ZvPi0g0Wg21XY=;25:Ek0861f01ivLBTodiGYpvYGusi9JLMjcr/gIWEuJkjL9aW7envYsq35ziojjFW5ivLIpOAshB9NVSL7osKG7yTkzlmOJiwPXkR66+owWvTEUwNFfvIXqsRyJsxurZnHWGDzUGzdn9znkCMYd0DxD6jU7WL8x9lztY042KJmqmSTOO9wEvFCjylqKHCvrxYcppk+pvZd2kOtIo61I3XMHDRpHQgyNyqUKjfIQR+1FrCF8viKevKDj3MvZXxX7CSFg+TwoHt7zF7fJ34Z5Y9HOalRjWJ+/gcfTiarf6hFKc4FBW0d1tk/HkkCfSqnhXQZOVk6tJUqsc1tfs0Ubaul+IjYWlcVUZm0QcJOAo8rDznY= X-MS-TrafficTypeDiagnostic: SN1PR0701MB1870: X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;31:sq5UJFgchVw5QMk6jJUr1hxivFCIGzMBjo7QA3Xjb9ZcFO2bQ4fEY8ECSkMK5ekC+G4ZEKHIcyEWoPpCmVFws0YXbxZzb9O1KmaQHvS1pApFA+O4Qzcm0FYscKpucY/mhT5/uggBeGDroAjYk1PW2DrfwhwoLee6e0PVsx9FmZCTRNKeVtLv1ZqKLStqQ+oD4coa8YU3JqF0t8xD/3ZKevvj1H9mVl6elNq1AopwSlk=;20:P0x/QWxr5OmpUDtHJrvckZDXnrMZUjKKN45Ws44rqZ+XeWc8t6u8kOHQPxZnDroTsoUdHZfG3yDjdG7FEZXLCAbvYfy8zn3hLWWLCetTjlH5sCvY5aw7Qx5v4NaQ0FdNdcp2cwuKsRPJ0AMfXYihsmWkLQuhpo544gzcKth3eRxcOm0vwiuMvuVruQZQiSkYhbiHF2dg39nHLG+m89wFcxN1Q1Oe3Jubsm4F4hQ6VkkEh/qtgiJMdARiaGYPHyYWG+SqJPPOTIKgQzmxf58G5RM2h7Xq9uOHPW0GgFzIUrfdcji+LWlpqvsaI31Z5nhHJLLyCa9a/0uhzMePHL76vpE+aQeXSrVv1+tGYXxgZ6B4DpJy2YeH1ya3MDabuVbeIfyyB2kyaDVBfKdte/qzKLxobN2U2ChGHdGjdfCYHIo6xQcJgFdrS0rj8gVaftf4YSkZ1LGbGzQexxcT1Re64NXCiVYPPIdxxWrbLQBpIbQb64ogePnKFe9s1aylNLJT X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(72806322054110)(185117386973197); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(93006095)(93003095)(3231415)(944501410)(52105112)(10201501046)(3002001)(148016)(149066)(150057)(6041310)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095);SRVR:SN1PR0701MB1870;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0701MB1870; X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;4:yoaeGGvx8pqfZhEHZz1URzxW+7z0WH+exKiE1kY/RMsO6UJUt3OKk1Zl/nwVMaZZ/bq58BotAUItoBUbrGb2qnO1Hri9Bn0gwiXjNkGoLck0BSfK++bThgn/Duj9f6IIzzq0aTKz47S0u4LGKofRntUbaVndTWphMmYKkdYa7zQp62PAid2+twVFdR1b5SRULV23ex5pZ1Jw/joPwX+lmnNdqNoav+XiBPwQdPj1ZZsdOW56HEIV3okavv6h1WTnIZq22pKr28bNnXO+v3Lw1bBomBf/vElzJtkAWO/B1kyboU/4/Lqeu8gCRCf14WtvVqjVrMkwSWZQNdFFppWJLtf3Vu9bPAr2YUg52NF5YVM= X-Forefront-PRVS: 0860FE717F X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;23:Iim2ZTlJCzt/v6VtRkf6fC77++aDaXC6Dd94naOmB0RIGYES9NkWfcVEYaDNgBBJPIEC/Uhr15OgIunmO3Q3YgcdDFyg0u7ki5aWE5UnW3hM/U0y8AqRncDBVTYtbjdft9TUaudN6fxkHWgbJHkRVM2OjychEvYW3OP/V/kta4WTQ3apTkmQm5XyuX39JF9P3LLYXgpV1XgDvTJAEUSAndvXaem4uH2qKVHL3BTQd9pUxdjoow5qIbCoiyH8QMfEAiTEr1FMumJ+5D/8c3BA1Roz6jWy/1yzmXRe3FXFA12tfV35wg3iCYg659bZgRCYikNtgc2n6QD/Rj2ylcOXzYSom8k4UQRimqtTkVj+ALifhzRkecefaLFmIZCA3vCcT9u5u6/qKnk6i4pl6jdq7xYEWegn0m25A7mowcwEhNnnftwTlFZqrNkY4gV8NP6rGWyv+hiLPUkJlGXU1YIm7g4u7pi0O2oGnDxvgZLU6qlUSdEqHVMNW2j0vwJefMzJXtqzm+G2lbkKDSY/SlXSProYJOPjUtBHxR+1Ff4rWUG65mIPbYOWSbnTRHZYDhX7wVsLZdbFTFvxRMOP08cHfK/ovyKX/EOl3JdhmSdJQ1DWfxRBf4Nulc2yuQZnn1TyulqXc8HSmZYuK4d8N4OPPluCz1kbXZLonDXqLphmeVdzSDuMYol/dVz+KHSKOpms+JdFDC8w9KKebwmvAVNM/VVSZ6qbFoPDANBDUifi97oxycBM8PRBHV2F0uCWHTKr2AKscUGuZWS9CyEMHav8XKBnYxWLT7xTskD1yTYEpyQoUFoWvwtSR8XIMqh8D5ink833ungjkDCufoMLgevDA+6eK94BjtUssImz//Iworl8t6dNACUQCevet8oIm7YY7Bo7DMebv2c3Uw3Vbz+V3XBAsnrClNvzfBu9qeZgJyzv1tx/tg8S0aIhvXYpIfWwJJ5i4S/8p5SaA92xGSVR/2PEtw8XDYXcE5267+FN6WSlu461HNrik/xHRqk2bIjULcgHPxUm22uIEABZguKF4yKBetIWaTZQ6tBatsGK0dt7sxriLHT5sbTijhU57FQY6upJCcGYXDP7o1CsXWLmn8rrNTkFqG4zAbrgN/AGXTFJepuLeEiYdlNETVT80m0p5HDGyq162lDF6pKKtKgmhVQX4iJ/QF+g1iBTxSlW852Mon4TarF3jM+I1kq+zEtx X-Microsoft-Antispam-Message-Info: mr490MLaOY1BzANyASLF1CLCk7mhPKNLa338pUSaadkvRGjaVNOB/KmHmk7qojpThDFuJ4j2GCnRILD9hnwU8NXN6r7pMLW/9ujamGcVyZHz5JjSHRoZgzApqVzBE7Ym+moNklB6Hz7t1gp209B7KlEYkFnx3ctYuCo4+6whsZklTHUVhXvFXSmck3ZLnqgly44AY0yKAQebD+4oXzF9w55+NaN8kxSsPltT9d2d+Z2ex+gV/eKbG0nNbZgm8BXDLKC6pY11WsjBjEBsgkfv5HQWCsAd3TtPGjwSAqYvfTQLMaoiimjtBjJXHB7sez3D928AXZ4yEUFZzkskbo5pP+6FgjeITuZFpU8JjnkY53k= X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;6:K3+qCxDlqkKnw6Lyjt/h3uUAMqD5day1UJrtAc1fkT/CEr8QFQbQNRWITJqMPunOFR8ZCNoZH0CFw4EHMbGiOCJzdE6G446Y59tkFo1oiCtJgfsuJLfRP/8zlDVCJ8YzssKH3v3S67euGpCbP1MrlBQqQkSAdQ2x60sQtSKYhCZiiuDJrESl5Iz+PPLoGCugNunSrAUovMsjQJgsZEYkd1+qKwJ+rFAMeAButwHAUe1l2YFUY1Fh64ECKoGCVHYUfo5sk5kcwhXbJNhTuy1xPKaPzKgGvPGokuY4pn6ESbYL8UE5JOZjCzVu9DOb8uvAYa83yX2v1iOCJyx+HOqxShDDx94PNcvd8aH5Fh0+xzYB5g7ZWfhK025WVIwOTyrVjpMNgh4gg50NvgY5JiJE4zpXdzSakma8HOC0ke5SS0wkNka9vaXw73vADHlquBFSzbZUEgfE/k4cP/JluS+qag==;5:KgNjIa0IngOLTS6Wm56+c9HmvNhiFm4nZBP9WcaTy7ZtkXLLRL/9Dnp3kctt7chhGYYnknEfvgXGmhbuwPkj+4RDkVrxuJU8W/oNMIzzGymeDutZBerSH8P+IEl4GjrisIjrRNPzb4Pqc+BzNqOw05M7Z18vyFCL58XwhAstFbo=;7:/3FCiOCPYFarPGy+31imNAnHtgo6GgCOnilurATJrWUVe+M4ebyYbrHI2EzEi9DOMet62CLD0H5uutYGgQTY7L4J/vod5r0gdWAypp5QujMzUyy5dw79tClwt+TFv8fpTFxihp9hkjjwnjuQWdcHjg== SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN1PR0701MB1870;20:lY3tEl/pdURczK7wTOtXxEEh+0XOqQS8kDW+Z93qTH7FvwWO67KUb0DuCWuYnJUbR3dn5KuMdOJK7VlIHyk6L1jY6omPZ7lfwXVl6rs+wMkWYOfd9h6TiunXxkXAZQJIaKk4UOcS+e7g1h/R5HfWcHYwPZUSEHR9Z6DLF6c9kXBMVH0kbjIFy4+Lmd8Ymgf0FIwFAU5yp5Q6Jadw100a4SBSs0tYCysP+BuqKJ1DgzwuBP8MfJ3wQXZtxMnI6QJP X-OriginatorOrg: cadence.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2018 10:10:46.4757 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed79e2ba-3de0-4c21-e49b-08d64d3e1be0 X-MS-Exchange-CrossTenant-Id: d36035c5-6ce6-4662-a3dc-e762e61ae4c9 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=d36035c5-6ce6-4662-a3dc-e762e61ae4c9;Ip=[158.140.1.28];Helo=[sjmaillnx2.cadence.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0701MB1870 X-Proofpoint-SPF-Result: pass X-Proofpoint-SPF-Record: v=spf1 a:mx-sanjose2.Cadence.COM a:mx-sanjose4.Cadence.COM a:mx-sanjose5.Cadence.COM include:mktomail.com include:spf-0014ca01.pphosted.com include:spf.protection.outlook.com include:auth.msgapp.com include:spf.mandrillapp.com ~all X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-18_03:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_check_notspam policy=outbound_check score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811180097 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch implements a set of function related to enumeration process. Some standard requests are handled on controller driver level and other are delegated to gadget core driver. All class requests are delegated to gadget core driver. Signed-off-by: Pawel Laszczak --- drivers/usb/cdns3/ep0.c | 491 ++++++++++++++++++++++++++++++++++++- drivers/usb/cdns3/gadget.c | 119 +++++++++ drivers/usb/cdns3/gadget.h | 4 + 3 files changed, 610 insertions(+), 4 deletions(-) diff --git a/drivers/usb/cdns3/ep0.c b/drivers/usb/cdns3/ep0.c index eb92fd234bd7..6f33d98f7684 100644 --- a/drivers/usb/cdns3/ep0.c +++ b/drivers/usb/cdns3/ep0.c @@ -10,6 +10,7 @@ * Peter Chen */ +#include #include "gadget.h" static struct usb_endpoint_descriptor cdns3_gadget_ep0_desc = { @@ -52,9 +53,31 @@ static void cdns3_ep0_run_transfer(struct cdns3_device *priv_dev, writel(EP_CMD_ERDY, &priv_dev->regs->ep_cmd); } +/** + * cdns3_ep0_delegate_req - Returns status of handling setup packet + * Setup is handled by gadget driver + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns zero on success or negative value on failure + */ +static int cdns3_ep0_delegate_req(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + int ret; + + spin_unlock(&priv_dev->lock); + priv_dev->setup_pending = 1; + ret = priv_dev->gadget_driver->setup(&priv_dev->gadget, ctrl_req); + priv_dev->setup_pending = 0; + spin_lock(&priv_dev->lock); + return ret; +} + static void cdns3_prepare_setup_packet(struct cdns3_device *priv_dev) { - //TODO: Implements this function + priv_dev->ep0_data_dir = 0; + cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, 8, 0); } static void cdns3_set_hw_configuration(struct cdns3_device *priv_dev) @@ -90,9 +113,431 @@ static void cdns3_set_hw_configuration(struct cdns3_device *priv_dev) } } +/** + * cdns3_req_ep0_set_configuration - Handling of SET_CONFIG standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, 0x7FFF on deferred status stage, error code on error + */ +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, *temp_ep; + u32 config = le16_to_cpu(ctrl_req->wValue); + int result = 0; + + switch (device_state) { + case USB_STATE_ADDRESS: + /* Configure non-control EPs */ + list_for_each_entry_safe(priv_ep, temp_ep, + &priv_dev->ep_match_list, + ep_match_pending_list) + cdns3_ep_config(priv_ep); + + result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); + + if (result) + return result; + + if (config) { + cdns3_set_hw_configuration(priv_dev); + } else { + cdns3_gadget_unconfig(priv_dev); + usb_gadget_set_state(&priv_dev->gadget, + USB_STATE_ADDRESS); + } + break; + case USB_STATE_CONFIGURED: + result = cdns3_ep0_delegate_req(priv_dev, ctrl_req); + + if (!config && !result) { + cdns3_gadget_unconfig(priv_dev); + usb_gadget_set_state(&priv_dev->gadget, + USB_STATE_ADDRESS); + } + break; + default: + result = -EINVAL; + } + + return result; +} + +/** + * cdns3_req_ep0_set_address - Handling of SET_ADDRESS standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_set_address(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + enum usb_device_state device_state = priv_dev->gadget.state; + u32 reg; + u32 addr; + + addr = le16_to_cpu(ctrl_req->wValue); + + if (addr > DEVICE_ADDRESS_MAX) { + dev_err(&priv_dev->dev, + "Device address (%d) cannot be greater than %d\n", + addr, DEVICE_ADDRESS_MAX); + return -EINVAL; + } + + if (device_state == USB_STATE_CONFIGURED) { + dev_err(&priv_dev->dev, "USB device already configured\n"); + return -EINVAL; + } + + reg = readl(&priv_dev->regs->usb_cmd); + + writel(reg | USB_CMD_FADDR(addr) | USB_CMD_SET_ADDR, + &priv_dev->regs->usb_cmd); + + usb_gadget_set_state(&priv_dev->gadget, + (addr ? USB_STATE_ADDRESS : USB_STATE_DEFAULT)); + + cdns3_prepare_setup_packet(priv_dev); + + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); + + return 0; +} + +/** + * cdns3_req_ep0_get_status - Handling of GET_STATUS standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_get_status(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl) +{ + __le16 *response_pkt; + u16 usb_status = 0; + u32 recip; + u32 reg; + + recip = ctrl->bRequestType & USB_RECIP_MASK; + + switch (recip) { + case USB_RECIP_DEVICE: + /* self powered */ + usb_status |= priv_dev->gadget.is_selfpowered; + + if (priv_dev->gadget.speed != USB_SPEED_SUPER) + break; + + reg = readl(&priv_dev->regs->usb_sts); + + if (priv_dev->u1_allowed) + usb_status |= BIT(USB_DEV_STAT_U1_ENABLED); + + if (priv_dev->u2_allowed) + usb_status |= BIT(USB_DEV_STAT_U2_ENABLED); + + if (priv_dev->wake_up_flag) + usb_status |= BIT(USB_DEVICE_REMOTE_WAKEUP); + break; + case USB_RECIP_INTERFACE: + return cdns3_ep0_delegate_req(priv_dev, ctrl); + case USB_RECIP_ENDPOINT: + /* check if endpoint is stalled */ + cdns3_select_ep(priv_dev, ctrl->wIndex); + if (EP_STS_STALL(readl(&priv_dev->regs->ep_sts))) + usb_status = BIT(USB_ENDPOINT_HALT); + break; + default: + return -EINVAL; + } + + response_pkt = (__le16 *)priv_dev->setup; + *response_pkt = cpu_to_le16(usb_status); + + cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, + sizeof(*response_pkt), 1); + return 0; +} + +static int cdns3_ep0_feature_handle_device(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + enum usb_device_state state; + enum usb_device_speed speed; + int ret = 0; + u32 wValue; + u32 wIndex; + u16 tmode; + + wValue = le16_to_cpu(ctrl->wValue); + wIndex = le16_to_cpu(ctrl->wIndex); + state = priv_dev->gadget.state; + speed = priv_dev->gadget.speed; + + switch (ctrl->wValue) { + case USB_DEVICE_REMOTE_WAKEUP: + priv_dev->wake_up_flag = !!set; + break; + case USB_DEVICE_U1_ENABLE: + if (state != USB_STATE_CONFIGURED || speed != USB_SPEED_SUPER) + return -EINVAL; + + priv_dev->u1_allowed = !!set; + break; + case USB_DEVICE_U2_ENABLE: + if (state != USB_STATE_CONFIGURED || speed != USB_SPEED_SUPER) + return -EINVAL; + + priv_dev->u2_allowed = !!set; + break; + case USB_DEVICE_LTM_ENABLE: + ret = -EINVAL; + break; + case USB_DEVICE_TEST_MODE: + if (state != USB_STATE_CONFIGURED || speed > USB_SPEED_HIGH) + return -EINVAL; + + tmode = le16_to_cpu(ctrl->wIndex); + + if (!set || (tmode & 0xff) != 0) + return -EINVAL; + + switch (tmode >> 8) { + case TEST_J: + case TEST_K: + case TEST_SE0_NAK: + case TEST_PACKET: + cdns3_set_register_bit(&priv_dev->regs->usb_cmd, + USB_CMD_STMODE | + USB_STS_TMODE_SEL(tmode - 1)); + break; + default: + ret = -EINVAL; + } + break; + default: + ret = -EINVAL; + } + + return ret; +} + +static int cdns3_ep0_feature_handle_intf(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + u32 wValue; + int ret = 0; + + wValue = le16_to_cpu(ctrl->wValue); + + switch (wValue) { + case USB_INTRF_FUNC_SUSPEND: + break; + default: + ret = -EINVAL; + } + + return ret; +} + +static int cdns3_ep0_feature_handle_endpoint(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + struct cdns3_endpoint *priv_ep; + int ret = 0; + u8 index; + + if (!(ctrl->wIndex & ~USB_DIR_IN)) + return 0; + + index = cdns3_ep_addr_to_index(ctrl->wIndex); + priv_ep = priv_dev->eps[index]; + + cdns3_select_ep(priv_dev, ctrl->wIndex); + + if (le16_to_cpu(ctrl->wValue) != USB_ENDPOINT_HALT) + return -EINVAL; + + if (set) { + writel(EP_CMD_SSTALL, &priv_dev->regs->ep_cmd); + priv_ep->flags |= EP_STALL; + } else { + struct usb_request *request; + + if (priv_dev->eps[index]->flags & EP_WEDGE) { + cdns3_select_ep(priv_dev, 0x00); + return 0; + } + + writel(EP_CMD_CSTALL | EP_CMD_EPRST, &priv_dev->regs->ep_cmd); + + /* wait for EPRST cleared */ + ret = cdns3_handshake(&priv_dev->regs->ep_cmd, + EP_CMD_EPRST, 0, 100); + if (ret) + return -EINVAL; + + priv_ep->flags &= ~EP_STALL; + + request = cdns3_next_request(&priv_ep->request_list); + if (request) + cdns3_ep_run_transfer(priv_ep, request); + } + return ret; +} + +/** + * cdns3_req_ep0_handle_feature - + * Handling of GET/SET_FEATURE standard USB request + * + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * @set: must be set to 1 for SET_FEATURE request + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_handle_feature(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl, + int set) +{ + int ret = 0; + u32 recip; + + recip = ctrl->bRequestType & USB_RECIP_MASK; + + switch (recip) { + case USB_RECIP_DEVICE: + ret = cdns3_ep0_feature_handle_device(priv_dev, ctrl, set); + break; + case USB_RECIP_INTERFACE: + ret = cdns3_ep0_feature_handle_intf(priv_dev, ctrl, set); + break; + case USB_RECIP_ENDPOINT: + ret = cdns3_ep0_feature_handle_endpoint(priv_dev, ctrl, set); + break; + default: + return -EINVAL; + } + + if (!ret) + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); + + return ret; +} + +/** + * cdns3_req_ep0_set_sel - Handling of SET_SEL standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_set_sel(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + if (priv_dev->gadget.state < USB_STATE_ADDRESS) + return -EINVAL; + + if (ctrl_req->wLength != 6) { + dev_err(&priv_dev->dev, "Set SEL should be 6 bytes, got %d\n", + ctrl_req->wLength); + return -EINVAL; + } + + priv_dev->ep0_data_dir = 0; + cdns3_ep0_run_transfer(priv_dev, priv_dev->setup_dma, 6, 1); + return 0; +} + +/** + * cdns3_req_ep0_set_isoch_delay - + * Handling of GET_ISOCH_DELAY standard USB request + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_req_ep0_set_isoch_delay(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + if (ctrl_req->wIndex || ctrl_req->wLength) + return -EINVAL; + + priv_dev->isoch_delay = ctrl_req->wValue; + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); + return 0; +} + +/** + * cdns3_ep0_standard_request - Handling standard USB requests + * @priv_dev: extended gadget object + * @ctrl_req: pointer to received setup packet + * + * Returns 0 if success, error code on error + */ +static int cdns3_ep0_standard_request(struct cdns3_device *priv_dev, + struct usb_ctrlrequest *ctrl_req) +{ + int ret; + + switch (ctrl_req->bRequest) { + case USB_REQ_SET_ADDRESS: + ret = cdns3_req_ep0_set_address(priv_dev, ctrl_req); + break; + case USB_REQ_SET_CONFIGURATION: + ret = cdns3_req_ep0_set_configuration(priv_dev, ctrl_req); + break; + case USB_REQ_GET_STATUS: + ret = cdns3_req_ep0_get_status(priv_dev, ctrl_req); + break; + case USB_REQ_CLEAR_FEATURE: + ret = cdns3_req_ep0_handle_feature(priv_dev, ctrl_req, 0); + break; + case USB_REQ_SET_FEATURE: + ret = cdns3_req_ep0_handle_feature(priv_dev, ctrl_req, 1); + break; + case USB_REQ_SET_SEL: + ret = cdns3_req_ep0_set_sel(priv_dev, ctrl_req); + break; + case USB_REQ_SET_ISOCH_DELAY: + ret = cdns3_req_ep0_set_isoch_delay(priv_dev, ctrl_req); + break; + default: + ret = cdns3_ep0_delegate_req(priv_dev, ctrl_req); + break; + } + + return ret; +} + static void __pending_setup_status_handler(struct cdns3_device *priv_dev) { - //TODO: Implements this function + struct usb_request *request = priv_dev->pending_status_request; + + if (priv_dev->status_completion_no_call && request && + request->complete) { + request->complete(priv_dev->gadget.ep0, request); + priv_dev->status_completion_no_call = 0; + } +} + +void cdns3_pending_setup_status_handler(struct work_struct *work) +{ + struct cdns3_device *priv_dev = container_of(work, struct cdns3_device, + pending_status_wq); + unsigned long flags; + + spin_lock_irqsave(&priv_dev->lock, flags); + __pending_setup_status_handler(priv_dev); + spin_unlock_irqrestore(&priv_dev->lock, flags); } /** @@ -101,12 +546,50 @@ static void __pending_setup_status_handler(struct cdns3_device *priv_dev) */ static void cdns3_ep0_setup_phase(struct cdns3_device *priv_dev) { - //TODO: Implements this function. + struct usb_ctrlrequest *ctrl = priv_dev->setup; + int result; + + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) + result = cdns3_ep0_standard_request(priv_dev, ctrl); + else + result = cdns3_ep0_delegate_req(priv_dev, ctrl); + + if (result != 0 && result != USB_GADGET_DELAYED_STATUS) { + dev_dbg(&priv_dev->dev, "STALL for ep0\n"); + /* set_stall on ep0 */ + cdns3_select_ep(priv_dev, 0x00); + writel(EP_CMD_SSTALL, &priv_dev->regs->ep_cmd); + writel(EP_CMD_ERDY | EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); + } } static void cdns3_transfer_completed(struct cdns3_device *priv_dev) { - //TODO: Implements this function + if (priv_dev->ep0_request) { + usb_gadget_unmap_request_by_dev(priv_dev->sysdev, + priv_dev->ep0_request, + priv_dev->ep0_data_dir); + + priv_dev->ep0_request->actual = + TRB_LEN(le32_to_cpu(priv_dev->trb_ep0->length)); + + dev_dbg(&priv_dev->dev, "Ep0 completion length %d\n", + priv_dev->ep0_request->actual); + list_del_init(&priv_dev->ep0_request->list); + } + + if (priv_dev->ep0_request && + priv_dev->ep0_request->complete) { + spin_unlock(&priv_dev->lock); + priv_dev->ep0_request->complete(priv_dev->gadget.ep0, + priv_dev->ep0_request); + + priv_dev->ep0_request = NULL; + spin_lock(&priv_dev->lock); + } + + cdns3_prepare_setup_packet(priv_dev); + writel(EP_CMD_REQ_CMPL, &priv_dev->regs->ep_cmd); } /** diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c index 309202474e57..0202ff5f6c90 100644 --- a/drivers/usb/cdns3/gadget.c +++ b/drivers/usb/cdns3/gadget.c @@ -70,6 +70,30 @@ static u8 cdns3_ep_reg_pos_to_index(int i) return ((i / 16) + (((i % 16) - 2) * 2)); } +/** + * cdns3_ep_addr_to_index - Macro converts endpoint address to + * index of endpoint object in cdns3_device.eps[] container + * @ep_addr: endpoint address for which endpoint object is required + * + * Remember that endpoint container doesn't contain default endpoint + */ +u8 cdns3_ep_addr_to_index(u8 ep_addr) +{ + return (((ep_addr & 0x7F) - 1) + ((ep_addr & USB_DIR_IN) ? 1 : 0)); +} + +/** + * cdns3_ep_addr_to_bit_pos - Macro converts endpoint address to + * bit position in ep_ists register + * @ep_addr: endpoint address for which bit position is required + * + * Remember that endpoint container doesn't contain default endpoint + */ +static u32 cdns3_ep_addr_to_bit_pos(u8 ep_addr) +{ + return (1 << (ep_addr & 0x7F)) << ((ep_addr & 0x80) ? 16 : 0); +} + /** * cdns3_next_request - returns next request from list * @list: list containing requests @@ -464,6 +488,99 @@ static irqreturn_t cdns3_irq_handler_thread(struct cdns3 *cdns) return ret; } +/** + * cdns3_ep_onchip_buffer_alloc - Try to allocate onchip buf for EP + * + * The real allocation will occur during write to EP_CFG register, + * this function is used to check if the 'size' allocation is allowed. + * + * @priv_dev: extended gadget object + * @size: the size (KB) for EP would like to allocate + * @is_in: the direction for EP + * + * Return 0 if the later allocation is allowed or negative value on failure + */ +static int cdns3_ep_onchip_buffer_alloc(struct cdns3_device *priv_dev, + int size, int is_in) +{ + if (is_in) { + priv_dev->onchip_mem_allocated_size += size; + } else if (!priv_dev->out_mem_is_allocated) { + /* ALL OUT EPs are shared the same chunk onchip memory */ + priv_dev->onchip_mem_allocated_size += size; + priv_dev->out_mem_is_allocated = 1; + } + + if (priv_dev->onchip_mem_allocated_size > CDNS3_ONCHIP_BUF_SIZE) { + priv_dev->onchip_mem_allocated_size -= size; + return -EPERM; + } else { + return 0; + } +} + +/** + * cdns3_ep_config Configure hardware endpoint + * @priv_ep: extended endpoint object + */ +void cdns3_ep_config(struct cdns3_endpoint *priv_ep) +{ + bool is_iso_ep = (priv_ep->type == USB_ENDPOINT_XFER_ISOC); + struct cdns3_device *priv_dev = priv_ep->cdns3_dev; + u32 bEndpointAddress = priv_ep->num | priv_ep->dir; + u32 interrupt_mask = EP_STS_EN_TRBERREN; + u32 max_packet_size = 0; + u32 ep_cfg = 0; + int ret; + + if (priv_ep->type == USB_ENDPOINT_XFER_INT) { + ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_INT); + } else if (priv_ep->type == USB_ENDPOINT_XFER_BULK) { + ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_BULK); + } else { + ep_cfg = EP_CFG_EPTYPE(USB_ENDPOINT_XFER_ISOC); + interrupt_mask = 0xFFFFFFFF; + } + + switch (priv_dev->gadget.speed) { + case USB_SPEED_FULL: + max_packet_size = is_iso_ep ? 1023 : 64; + break; + case USB_SPEED_HIGH: + max_packet_size = is_iso_ep ? 1024 : 512; + break; + case USB_SPEED_SUPER: + max_packet_size = 1024; + break; + default: + //all other speed are not supported + return; + } + + ret = cdns3_ep_onchip_buffer_alloc(priv_dev, CDNS3_EP_BUF_SIZE, + priv_ep->dir); + if (ret) { + dev_err(&priv_dev->dev, "onchip mem is full, ep is invalid\n"); + return; + } + + ep_cfg |= EP_CFG_MAXPKTSIZE(max_packet_size) | + EP_CFG_BUFFERING(CDNS3_EP_BUF_SIZE - 1) | + EP_CFG_MAXBURST(priv_ep->endpoint.maxburst); + + cdns3_select_ep(priv_dev, bEndpointAddress); + + writel(ep_cfg, &priv_dev->regs->ep_cfg); + writel(interrupt_mask, &priv_dev->regs->ep_sts_en); + + dev_dbg(&priv_dev->dev, "Configure %s: with val %08x\n", + priv_ep->name, ep_cfg); + + /* enable interrupt for selected endpoint */ + cdns3_set_register_bit(&priv_dev->regs->ep_ien, + cdns3_ep_addr_to_bit_pos(bEndpointAddress)); +} + /* Find correct direction for HW endpoint according to description */ static int cdns3_ep_dir_is_correct(struct usb_endpoint_descriptor *desc, struct cdns3_endpoint *priv_ep) @@ -1104,6 +1221,8 @@ static int __cdns3_gadget_init(struct cdns3 *cdns) priv_dev->is_connected = 0; spin_lock_init(&priv_dev->lock); + INIT_WORK(&priv_dev->pending_status_wq, + cdns3_pending_setup_status_handler); priv_dev->in_standby_mode = 1; diff --git a/drivers/usb/cdns3/gadget.h b/drivers/usb/cdns3/gadget.h index 8c2f363f9340..db8c6cb9f2a5 100644 --- a/drivers/usb/cdns3/gadget.h +++ b/drivers/usb/cdns3/gadget.h @@ -1070,14 +1070,18 @@ struct cdns3_device { int cdns3_handshake(void __iomem *ptr, u32 mask, u32 done, int usec); void cdns3_set_register_bit(void __iomem *ptr, u32 mask); +void cdns3_pending_setup_status_handler(struct work_struct *work); int cdns3_init_ep0(struct cdns3_device *priv_dev); void cdns3_ep0_config(struct cdns3_device *priv_dev); +void cdns3_ep_config(struct cdns3_endpoint *priv_ep); void cdns3_check_ep0_interrupt_proceed(struct cdns3_device *priv_dev, int dir); void cdns3_select_ep(struct cdns3_device *priv_dev, u32 ep); void cdns3_enable_l1(struct cdns3_device *priv_dev, int enable); struct usb_request *cdns3_next_request(struct list_head *list); +void cdns3_gadget_unconfig(struct cdns3_device *priv_dev); int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep, struct usb_request *request); +u8 cdns3_ep_addr_to_index(u8 ep_addr); int cdns3_gadget_ep_set_wedge(struct usb_ep *ep); int cdns3_gadget_ep_set_halt(struct usb_ep *ep, int value); struct usb_request *cdns3_gadget_ep_alloc_request(struct usb_ep *ep,