From patchwork Mon Aug 26 09:40:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sherry Sun X-Patchwork-Id: 1153072 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=nxp.com header.i=@nxp.com header.b="SNOEy7Pu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46H6Ts36cbz9sDB for ; Mon, 26 Aug 2019 19:41:53 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2FA32C22100; Mon, 26 Aug 2019 09:40:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4E777C21F87; Mon, 26 Aug 2019 09:40:56 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8A3F0C21F87; Mon, 26 Aug 2019 09:40:31 +0000 (UTC) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140081.outbound.protection.outlook.com [40.107.14.81]) by lists.denx.de (Postfix) with ESMTPS id 1D723C21F9A for ; Mon, 26 Aug 2019 09:40:31 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T1XhcasTYMzPFDB0YGRg0+OPasI1NHH8pISrvl+CcWZLljhlcRY/axbk1SyYGeyvKR14KbsH3B6+LcieBdkWJH0TeM/aWNpYRHVUIo//O0Mo21Vcc1+OLgWmWVQ77S1Rue2yOstlco5XY4FfzF7NgfTfXyP3Q8ROprihueP2dQNQ/xnoGTekuxRtQbD6hjm7Sw5kXllyW3DJ93eikHCbV3nE6DzM7bDJXFsf5acxpWKQ4KOGEu6c6Qfkvo+UOIha5rt9phTlfS/qmQqLrAWzR8HY5hxof0sg1cvflNHvI3XdS9djinbuOL9OtdMuifUiCmHp7sTvmE2bCZoKIPpuwg== 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=WzsoAWacuoDZyhhPGhBxVp3kzysP2B10pSdhmhz6v3c=; b=PXLKnndes2uKXPvaEkyRcoyZOA4/BwAzfEJ5W98erT1JgotJBpIdBY9icNG513DYjCqW/OEFbsr7su0FwXaiSGit7Iy6AEfYMliXfEPZu4CtRJon/ua0wdHEFvzIucA0HNiXWtnJ2fVnBdMkk75BJ8ir3K3pTvYEHgemewvdwiC6NTLfZFM+iT8wUKwFf8eGhRLFanox5aRkIXwzZOYhWNlEA28mWwtXoRCU3r20mpTyDI+9vNs0Qw3aRR5CWJOKQNp0Rwm7zNwe1FNS94u3Kp8wuIHsGzKw2df96wDwCAnv4HPyRu+2o0Xm2fCvW/UN+c+Ti87wuS1TPAWsaJhk/Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WzsoAWacuoDZyhhPGhBxVp3kzysP2B10pSdhmhz6v3c=; b=SNOEy7PuqWzppZ3STDl0c9pzh2hw6yfG9lLD7YulubuWvowa1guzK/0TfzbOVYTTnyA1EkKBkbj+Bz19z7Ruy+cpPDVd0bL+GZLdUfRTFsBE2UwD8K90ozdmv47nCG27ylQL5tJCa25hDcTBc4DKBkZoRbOoy4OaD4uhlVL5P88= Received: from VE1PR04MB6445.eurprd04.prod.outlook.com (20.179.232.214) by VE1PR04MB6750.eurprd04.prod.outlook.com (20.179.235.215) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2199.21; Mon, 26 Aug 2019 09:40:30 +0000 Received: from VE1PR04MB6445.eurprd04.prod.outlook.com ([fe80::714b:566c:c86b:ba12]) by VE1PR04MB6445.eurprd04.prod.outlook.com ([fe80::714b:566c:c86b:ba12%7]) with mapi id 15.20.2199.021; Mon, 26 Aug 2019 09:40:30 +0000 From: Sherry Sun To: "lukma@denx.de" , "marex@denx.de" , "sbabic@denx.de" , "festevam@gmail.com" Thread-Topic: [PATCH v4 3/4] SDP: fix wrong usb request size and add high speed endpoint descriptor Thread-Index: AQHVW/JMAF6y5lubPE+l3avfkI6TVA== Date: Mon, 26 Aug 2019 09:40:29 +0000 Message-ID: <20190826213905.24881-4-sherry.sun@nxp.com> References: <20190826213905.24881-1-sherry.sun@nxp.com> In-Reply-To: <20190826213905.24881-1-sherry.sun@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HK0PR01CA0061.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::25) To VE1PR04MB6445.eurprd04.prod.outlook.com (2603:10a6:803:11c::22) x-mailer: git-send-email 2.17.1 authentication-results: spf=none (sender IP is ) smtp.mailfrom=sherry.sun@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.71] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e194a7be-6480-4deb-233b-08d72a096eca x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600166)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020); SRVR:VE1PR04MB6750; x-ms-traffictypediagnostic: VE1PR04MB6750: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2201; x-forefront-prvs: 01415BB535 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(4636009)(366004)(396003)(39860400002)(376002)(136003)(346002)(199004)(189003)(25786009)(2616005)(26005)(476003)(102836004)(446003)(110136005)(386003)(76176011)(2906002)(1076003)(486006)(2201001)(66476007)(478600001)(53936002)(7736002)(256004)(316002)(44832011)(54906003)(99286004)(11346002)(4326008)(14454004)(14444005)(305945005)(8936002)(36756003)(66446008)(50226002)(71200400001)(66066001)(6506007)(6436002)(186003)(71190400001)(8676002)(5660300002)(81166006)(81156014)(86362001)(6512007)(52116002)(2501003)(6486002)(3846002)(64756008)(66946007)(6116002)(66556008); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR04MB6750; H:VE1PR04MB6445.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: ExaJJx4jbhTqwbHuwlfX6HqajKhCMm3pBI7MbT4dB9PMpl+MtxESOMkkTLhvyDufErnM9dq8yYZUgRzXaG09Elx65aKgnNYvlpH5lv3Q1RaAofq4/OB8LIsFDEKMGnXHHs9BInrJFcGyZcM3pz8kBZX6uPbwNXCYLRooogp/RvtNmhtmpIm+yX+vXX8uCx/P6gNDXerjl9nWEFPoj8lEJ770VteC9EThf2/6OUHDeYHSuKXV2wBpPCpCfHJ88fqffF8/B8K0nMYYOKeJ/7n+BeVq5Z5lbWdQYVGQ5FTudRYAw7lHy4IU88w/HNKwZ9jmxHdD1cpD8I7mvFQA3lMYT0LDbB/RZsquhw0bbXRSWCcWtoh/1jCFby1tdhok+rze6LKjNPEzqi1C8jYqqzcDgAWTk3P9J+Hp8LyFM8KRbQQ= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e194a7be-6480-4deb-233b-08d72a096eca X-MS-Exchange-CrossTenant-originalarrivaltime: 26 Aug 2019 09:40:29.9776 (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: PQrqQqBdPfwx5qgtRalkspAgJNiP2R6N/1YjvaSOJV9VPBYyezYZlJo7pp8S0bFaKj/brD02FHvyK86bWGd7CQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6750 Cc: "u-boot@lists.denx.de" , dl-uboot-imx Subject: [U-Boot] [PATCH v4 3/4] SDP: fix wrong usb request size and add high speed endpoint descriptor X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Because the buffer length of sdp usb request is 65, we have to allocate 65 bytes not 64 bytes. Otherwise there is potential buffer overflow. So the wMaxPacketSize of fullspeed can't meet the needs. Add HS endpoint descriptor for SDP. Then we can use high speed endpoint, and the SDP device can send packet with 512 byte size. Signed-off-by: Sherry Sun Signed-off-by: Ye Li --- drivers/usb/gadget/f_sdp.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/drivers/usb/gadget/f_sdp.c b/drivers/usb/gadget/f_sdp.c index 841814bc07..e7daa1a4f5 100644 --- a/drivers/usb/gadget/f_sdp.c +++ b/drivers/usb/gadget/f_sdp.c @@ -70,6 +70,11 @@ struct hid_report { #define SDP_COMMAND_LEN 16 +/* The first data is for report id, the next 64 bytes are the maximum amount + * of data we need to send to usb host. So a total of 65 bytes are needed. + */ +#define SDP_USB_REQUEST_BUFLEN 65 + struct sdp_command { u16 cmd; u32 addr; @@ -158,6 +163,16 @@ static struct usb_endpoint_descriptor in_desc = { .bInterval = 1, }; +static struct usb_endpoint_descriptor in_hs_desc = { + .bLength = USB_DT_ENDPOINT_SIZE, + .bDescriptorType = USB_DT_ENDPOINT, /*USB_DT_CS_ENDPOINT*/ + + .bEndpointAddress = 1 | USB_DIR_IN, + .bmAttributes = USB_ENDPOINT_XFER_INT, + .wMaxPacketSize = 512, + .bInterval = 1, +}; + static struct usb_descriptor_header *sdp_runtime_descs[] = { (struct usb_descriptor_header *)&sdp_intf_runtime, (struct usb_descriptor_header *)&sdp_hid_desc, @@ -165,6 +180,13 @@ static struct usb_descriptor_header *sdp_runtime_descs[] = { NULL, }; +static struct usb_descriptor_header *sdp_runtime_hs_descs[] = { + (struct usb_descriptor_header *)&sdp_intf_runtime, + (struct usb_descriptor_header *)&sdp_hid_desc, + (struct usb_descriptor_header *)&in_hs_desc, + NULL, +}; + /* This is synchronized with what the SoC implementation reports */ static struct hid_report sdp_hid_report = { .usage_page = { @@ -490,6 +512,11 @@ static int sdp_bind(struct usb_configuration *c, struct usb_function *f) goto error; } + if (gadget_is_dualspeed(gadget)) { + /* Assume endpoint addresses are the same for both speeds */ + in_hs_desc.bEndpointAddress = in_desc.bEndpointAddress; + } + sdp->in_ep = ep; /* Store IN EP for enabling @ setup */ cdev->req->context = sdp; @@ -527,7 +554,7 @@ static struct usb_request *sdp_start_ep(struct usb_ep *ep) { struct usb_request *req; - req = alloc_ep_req(ep, 64); + req = alloc_ep_req(ep, SDP_USB_REQUEST_BUFLEN); debug("%s: ep:%p req:%p\n", __func__, ep, req); if (!req) @@ -542,11 +569,15 @@ static int sdp_set_alt(struct usb_function *f, unsigned intf, unsigned alt) { struct f_sdp *sdp = func_to_sdp(f); struct usb_composite_dev *cdev = f->config->cdev; + struct usb_gadget *gadget = cdev->gadget; int result; debug("%s: intf: %d alt: %d\n", __func__, intf, alt); - result = usb_ep_enable(sdp->in_ep, &in_desc); + if (gadget_is_dualspeed(gadget) && gadget->speed == USB_SPEED_HIGH) + result = usb_ep_enable(sdp->in_ep, &in_hs_desc); + else + result = usb_ep_enable(sdp->in_ep, &in_desc); if (result) return result; sdp->in_req = sdp_start_ep(sdp->in_ep); @@ -592,7 +623,7 @@ static int sdp_bind_config(struct usb_configuration *c) memset(sdp_func, 0, sizeof(*sdp_func)); sdp_func->usb_function.name = "sdp"; - sdp_func->usb_function.hs_descriptors = sdp_runtime_descs; + sdp_func->usb_function.hs_descriptors = sdp_runtime_hs_descs; sdp_func->usb_function.descriptors = sdp_runtime_descs; sdp_func->usb_function.bind = sdp_bind; sdp_func->usb_function.unbind = sdp_unbind;