From patchwork Fri May 7 06:58:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 432770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8FD39C433ED for ; Fri, 7 May 2021 07:14:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 50B06613D6 for ; Fri, 7 May 2021 07:14:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231441AbhEGHPQ (ORCPT ); Fri, 7 May 2021 03:15:16 -0400 Received: from mail-eopbgr80071.outbound.protection.outlook.com ([40.107.8.71]:35204 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230070AbhEGHPP (ORCPT ); Fri, 7 May 2021 03:15:15 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jmr3/ANufpnLvZLQYaigWduueFfCkBUnJ8pU6aJ9DwdAWGKLzTv2poMjqf/i0uF1C3uzH89KbsQXtQnT9BH6VLvf/D3pxVAI7kHbkhXXaClazISlBfKrhDj+f2PejiPNSOhoeVqmtH7PlWWERFTJyv2VGJcQ1CiXjcPt5Uu4Z6WnfzY9MOZG5cXxZ3AftPs6mO4XkGqholL17s6Uefq/qaJw3V7/wWA3WOepwwQDwX7tAapkCLJWC9fvI2QEa1oVgOKCysaXilahlG3fRJvfKoC4CifvSfOLAiQIaWxLW93K76nrs+hQL94tO5e8gTeTsdUQYoFuZ76vzb44pNpllg== 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=KTn3GB0q7w40ohzHeVnmyOYbILXYzjEC9Sbx6vN06uo=; b=jY0z9fa6NaQCjBec1TDDAjJeKPUgHW29fANA1HBo4Rc+S1odLkbL0U2heVpMs3jF2sLmMss3CDFkLFxSdnMYoz14RPSGXEztgunIvJYdyGJKxOWarRglVWSlVWYPiS+fnSZVmzyVJ82wulOlf1/ZvNWsp7YbtREC8stCSWvth5HfYQ5Z9dMVLQt+YzBV+4h7PPSXNS5qzGZlfWGvpctNEOUOHkboI2idJeZG+eBf6yZKVX9e5TyCIlPN3RXFpALnUiZ2n16AjvBpbB3fy/3Rg2NlqQ686JfL+hUehbz62eOwwVKKxflAUOhS0pOiMnjuFLrqhoRCkZ9oTq6Fzs0zGQ== 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=KTn3GB0q7w40ohzHeVnmyOYbILXYzjEC9Sbx6vN06uo=; b=AkuGHG5o6HdsruOT6/dlGiilaoochZexOe82n5CIBanHNm37WzSFyWu2uhmClA8ktfXKFjPx99/flL+72czGwFlDnQdDK+M+HafFWgMTuh9dMXFFz3+IvwzTtSQQryjAPmtBvURrCB17pTroa4gOLr0r3aCiv2om/+WqzG7ICh0= Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none; linuxfoundation.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5935.eurprd04.prod.outlook.com (2603:10a6:803:e9::17) by VI1PR0401MB2639.eurprd04.prod.outlook.com (2603:10a6:800:58::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25; Fri, 7 May 2021 07:14:13 +0000 Received: from VI1PR04MB5935.eurprd04.prod.outlook.com ([fe80::ddf7:8cd0:3132:7dbe]) by VI1PR04MB5935.eurprd04.prod.outlook.com ([fe80::ddf7:8cd0:3132:7dbe%7]) with mapi id 15.20.4108.029; Fri, 7 May 2021 07:14:13 +0000 From: Li Jun To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, mathias.nyman@intel.com Cc: peter.chen@kernel.org, jun.li@nxp.com, jackp@codeaurora.org, linux-usb@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v3 1/3] usb: host: move EH SINGLE_STEP_SET_FEATURE implementation to core Date: Fri, 7 May 2021 14:58:00 +0800 Message-Id: <1620370682-10199-1-git-send-email-jun.li@nxp.com> X-Mailer: git-send-email 2.7.4 X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: SG2PR0302CA0020.apcprd03.prod.outlook.com (2603:1096:3:2::30) To VI1PR04MB5935.eurprd04.prod.outlook.com (2603:10a6:803:e9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.31.174.66) by SG2PR0302CA0020.apcprd03.prod.outlook.com (2603:1096:3:2::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4129.11 via Frontend Transport; Fri, 7 May 2021 07:14:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4597f6a7-0ca0-474b-f0e6-08d91127b791 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2639: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:132; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H8KK6k4N94YpKPmqk3bsAHhIYiv9cRP2EI7jR3BAduT8WurZs9LEbizY1j6qP5Nb8Cq0MgIiu+5p0kw8KbU2SmH9+6eRceQ2au1gG9h0bOvViKeclYqXAwlW+IXXdGgvy/2ltlg2oACp24cNPLT+k21U66Sd8f9qSNpueBnddTffMPDQ5a4rk51DRBLnWrwceU+8YXos9XnvAxBSFQRIpg3ESAZAqE6kSOM2TKXSRvxJj98pPL4x/6rJfFvdScYSovGmQPdgbDXbKafumqHXYm3QkoWI6pXPgMux4ZRfql3uTEHsGuCz7VlBS+K1Dd7qz0xwPwfNZ1zX7bFwA4ipbh/yXBxQOOC+5q6HrndL74WPMI+0DAUJoQDmJ65hOuhZ/i8rGBp+NnmvSfjRZ9AwSUu5jNYngt9WV5hui34hu886Z8pNaBeNaTGTwZxXeu8y6O8/+R8MbNM+MeG2gbjkZCq07V5wgbBHw+ifoKmkdrs9Q/2RE2biaqkuqpwF6TACPQK2KwSVT6GMWJqJz1aD1Lj1sko/cRml5lEM1284fCeXSa0bQ4KEx7GEMn6RS/nJ5DMmT/Xlv/MVUg5hWTfL9ui7Uql8RDfXwwRXEG8s8wH0PBJn4m+ShBdOHCdx3+N9sdr/XFRxarsuPdHj2ztWLJ+tWwLie/dFBx8bhjFEXFCI/bXS11X4rMr2ucQUrLpA X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5935.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(366004)(396003)(39860400002)(136003)(346002)(956004)(2616005)(6512007)(66556008)(26005)(4326008)(66946007)(66476007)(478600001)(36756003)(38350700002)(316002)(86362001)(2906002)(38100700002)(83380400001)(30864003)(6506007)(186003)(8936002)(5660300002)(8676002)(6666004)(6486002)(52116002)(16526019)(69590400013); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: DrVGAmftEhhxvNNYM6BU5px5NO6aYMgwhqAvE9yGNoQoQnj2jaSjm7zDNU+TCpGwROyyHZwAykPzindRRI+ufIkIBWI4CGPBUH8XxYd0gCfHf30LX+9VE5Tt7CM20TDpjIOGHgcLqRcKlvOA+n2VxcEd+HA4qkSOeDDHuW48IxmgxHeKrWIdiME6WeuP0dQvVdcdsYfl76U1TmbQzanY6/zbVjOdwTPcymu0IO2Y6Zxb+jY23DefoIMsDJZ9XqwjaWsyNGfy81piscCqpP2jrx+TR873Tlpzk0wH7nlvU6hFBF8Cu/oPxsO7q4udACbznHIizSGNbcNfHzFft0F6nC90H4EvaoOPT2wc08MWJSpD79akqgv28f0h9cI06KDmWHRkKyHekdelqCPAYM/t9BR65BMyaRtK8TXM69SW3lurhSPtKt3MoEF9UApAcKmvmCTOFLw6rnbsM8dzlEgFf8tiaPRZoMMErc6pihjEQcEUVjMHjIJ6BpcL0r1FULcQoO9BH+iqsgrpa5kPXq3rcruCnUijPd79jAmSdRm3Ambucy7m7+e4dGJPyYY1K444qW9YQLa6y6p1qKanfbwwWRiDFJIx0H5piOGY5F+n0IZOTCpYgJRdBzKTYW7T/CUolWcq7T3RX0wsf0/PzKxSgSj1w298yecoOrlJr5mmSp4u9qpom8qI2ml/OZxR3YWiIHPQVn5jw0MxZecBmik3sb+VQNrfIwPFLtUNSBKElcjXEOhIUNY3WMHTUyAwHpRfeb7cCe3940YVmpVq6bgbCQJq214zk8W5pAYN44EgDgLSNen8yBz83EAbI//tIWR8HPG0GJZ1axT2SRzuCBoD/EXrHzL4S1aBVUU4VQeJYLe8kbJY1Z5SY9mQqLG04Ks9oXBVlx7qflv2xW0YMD9ipuwNHxcBmZoN33ouK40qV6n85UgkcQor9O4kcqZRKP7oGjTjLgaL7aXyKgmmdKX2Yx839Fq8I+jqyyiIxLdnNfwdRtiup8d+/5YGAIjlHgqUlqHldkjN8/FoYs2qrp4BhJ1AJO+bxhGDdMqwwdZKXpWV+wI8LH6HdOWIt4tBOmEHi4uRnSZscrlk3rU2XblM+RMW9pXdaJg4F73lLDTMM1/RWB1prgw5c7bnrnTqJFBYPVV1W+sFfVeN9YtQj0NREX9NxADCqUuXenI81fhtswLKUNk/T0lpn0qNW8BnomCnNk6ftijNQ7VxwuZC96Un7WQZiDfHkzgtAnSlSFPuZEeyf9CsPqP/puIaL214l121qee7jBMMnmfMiM8cMNcxXljFZvlVj7AziJ+JdT64AslDYZssyv/iQ6USexQfraEh X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4597f6a7-0ca0-474b-f0e6-08d91127b791 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5935.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 07:14:13.3815 (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: o/SCEeTNY+WfFwVEw72gbNhdgAvFHw5N2eQ+f7K7f74fVcqmC286JmPzDKE3dHgZ X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2639 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Peter Chen It is needed at USB Certification test for Embedded Host 2.0, and the detail is at CH6.4.1.1 of On-The-Go and Embedded Host Supplement to the USB Revision 2.0 Specification. Since other USB 2.0 capable host like XHCI also need it, so move it to HCD core. Acked-by: Alan Stern Signed-off-by: Peter Chen Signed-off-by: Li Jun --- Change for v3: - Add Alan's A-b tag. Change for v2: - No change. drivers/usb/core/hcd.c | 134 ++++++++++++++++++++++++++++++++++ drivers/usb/host/ehci-hcd.c | 4 ++ drivers/usb/host/ehci-hub.c | 139 ------------------------------------ drivers/usb/host/ehci-q.c | 2 +- include/linux/usb/hcd.h | 13 +++- 5 files changed, 151 insertions(+), 141 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 6119fb41d736..d7eb9f179ca6 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -2110,6 +2110,140 @@ int usb_hcd_get_frame_number (struct usb_device *udev) return hcd->driver->get_frame_number (hcd); } +/*-------------------------------------------------------------------------*/ +#ifdef CONFIG_USB_HCD_TEST_MODE + +static void usb_ehset_completion(struct urb *urb) +{ + struct completion *done = urb->context; + + complete(done); +} +/* + * Allocate and initialize a control URB. This request will be used by the + * EHSET SINGLE_STEP_SET_FEATURE test in which the DATA and STATUS stages + * of the GetDescriptor request are sent 15 seconds after the SETUP stage. + * Return NULL if failed. + */ +static struct urb *request_single_step_set_feature_urb( + struct usb_device *udev, + void *dr, + void *buf, + struct completion *done) +{ + struct urb *urb; + struct usb_hcd *hcd = bus_to_hcd(udev->bus); + struct usb_host_endpoint *ep; + + urb = usb_alloc_urb(0, GFP_KERNEL); + if (!urb) + return NULL; + + urb->pipe = usb_rcvctrlpipe(udev, 0); + ep = (usb_pipein(urb->pipe) ? udev->ep_in : udev->ep_out) + [usb_pipeendpoint(urb->pipe)]; + if (!ep) { + usb_free_urb(urb); + return NULL; + } + + urb->ep = ep; + urb->dev = udev; + urb->setup_packet = (void *)dr; + urb->transfer_buffer = buf; + urb->transfer_buffer_length = USB_DT_DEVICE_SIZE; + urb->complete = usb_ehset_completion; + urb->status = -EINPROGRESS; + urb->actual_length = 0; + urb->transfer_flags = URB_DIR_IN; + usb_get_urb(urb); + atomic_inc(&urb->use_count); + atomic_inc(&urb->dev->urbnum); + urb->setup_dma = dma_map_single( + hcd->self.sysdev, + urb->setup_packet, + sizeof(struct usb_ctrlrequest), + DMA_TO_DEVICE); + urb->transfer_dma = dma_map_single( + hcd->self.sysdev, + urb->transfer_buffer, + urb->transfer_buffer_length, + DMA_FROM_DEVICE); + urb->context = done; + return urb; +} + +int ehset_single_step_set_feature(struct usb_hcd *hcd, int port) +{ + int retval = -ENOMEM; + struct usb_ctrlrequest *dr; + struct urb *urb; + struct usb_device *udev; + struct usb_device_descriptor *buf; + DECLARE_COMPLETION_ONSTACK(done); + + /* Obtain udev of the rhub's child port */ + udev = usb_hub_find_child(hcd->self.root_hub, port); + if (!udev) { + dev_err(hcd->self.controller, "No device attached to the RootHub\n"); + return -ENODEV; + } + buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); + if (!dr) { + kfree(buf); + return -ENOMEM; + } + + /* Fill Setup packet for GetDescriptor */ + dr->bRequestType = USB_DIR_IN; + dr->bRequest = USB_REQ_GET_DESCRIPTOR; + dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8); + dr->wIndex = 0; + dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE); + urb = request_single_step_set_feature_urb(udev, dr, buf, &done); + if (!urb) + goto cleanup; + + /* Submit just the SETUP stage */ + retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 1); + if (retval) + goto out1; + if (!wait_for_completion_timeout(&done, msecs_to_jiffies(2000))) { + usb_kill_urb(urb); + retval = -ETIMEDOUT; + dev_err(hcd->self.controller, + "%s SETUP stage timed out on ep0\n", __func__); + goto out1; + } + msleep(15 * 1000); + + /* Complete remaining DATA and STATUS stages using the same URB */ + urb->status = -EINPROGRESS; + usb_get_urb(urb); + atomic_inc(&urb->use_count); + atomic_inc(&urb->dev->urbnum); + retval = hcd->driver->submit_single_step_set_feature(hcd, urb, 0); + if (!retval && !wait_for_completion_timeout(&done, + msecs_to_jiffies(2000))) { + usb_kill_urb(urb); + retval = -ETIMEDOUT; + dev_err(hcd->self.controller, + "%s IN stage timed out on ep0\n", __func__); + } +out1: + usb_free_urb(urb); +cleanup: + kfree(dr); + kfree(buf); + return retval; +} +EXPORT_SYMBOL_GPL(ehset_single_step_set_feature); +#endif /* CONFIG_USB_HCD_TEST_MODE */ + /*-------------------------------------------------------------------------*/ #ifdef CONFIG_PM diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 94b5e64ae9a2..35eec0c0edcd 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -1238,6 +1238,10 @@ static const struct hc_driver ehci_hc_driver = { * device support */ .free_dev = ehci_remove_device, +#ifdef CONFIG_USB_HCD_TEST_MODE + /* EH SINGLE_STEP_SET_FEATURE test support */ + .submit_single_step_set_feature = ehci_submit_single_step_set_feature, +#endif }; void ehci_init_driver(struct hc_driver *drv, diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c index 159cc27b1a36..c4f6a2559a98 100644 --- a/drivers/usb/host/ehci-hub.c +++ b/drivers/usb/host/ehci-hub.c @@ -726,145 +726,6 @@ ehci_hub_descriptor ( desc->wHubCharacteristics = cpu_to_le16(temp); } -/*-------------------------------------------------------------------------*/ -#ifdef CONFIG_USB_HCD_TEST_MODE - -#define EHSET_TEST_SINGLE_STEP_SET_FEATURE 0x06 - -static void usb_ehset_completion(struct urb *urb) -{ - struct completion *done = urb->context; - - complete(done); -} -static int submit_single_step_set_feature( - struct usb_hcd *hcd, - struct urb *urb, - int is_setup -); - -/* - * Allocate and initialize a control URB. This request will be used by the - * EHSET SINGLE_STEP_SET_FEATURE test in which the DATA and STATUS stages - * of the GetDescriptor request are sent 15 seconds after the SETUP stage. - * Return NULL if failed. - */ -static struct urb *request_single_step_set_feature_urb( - struct usb_device *udev, - void *dr, - void *buf, - struct completion *done -) { - struct urb *urb; - struct usb_hcd *hcd = bus_to_hcd(udev->bus); - struct usb_host_endpoint *ep; - - urb = usb_alloc_urb(0, GFP_KERNEL); - if (!urb) - return NULL; - - urb->pipe = usb_rcvctrlpipe(udev, 0); - ep = (usb_pipein(urb->pipe) ? udev->ep_in : udev->ep_out) - [usb_pipeendpoint(urb->pipe)]; - if (!ep) { - usb_free_urb(urb); - return NULL; - } - - urb->ep = ep; - urb->dev = udev; - urb->setup_packet = (void *)dr; - urb->transfer_buffer = buf; - urb->transfer_buffer_length = USB_DT_DEVICE_SIZE; - urb->complete = usb_ehset_completion; - urb->status = -EINPROGRESS; - urb->actual_length = 0; - urb->transfer_flags = URB_DIR_IN; - usb_get_urb(urb); - atomic_inc(&urb->use_count); - atomic_inc(&urb->dev->urbnum); - urb->setup_dma = dma_map_single( - hcd->self.sysdev, - urb->setup_packet, - sizeof(struct usb_ctrlrequest), - DMA_TO_DEVICE); - urb->transfer_dma = dma_map_single( - hcd->self.sysdev, - urb->transfer_buffer, - urb->transfer_buffer_length, - DMA_FROM_DEVICE); - urb->context = done; - return urb; -} - -static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port) -{ - int retval = -ENOMEM; - struct usb_ctrlrequest *dr; - struct urb *urb; - struct usb_device *udev; - struct ehci_hcd *ehci = hcd_to_ehci(hcd); - struct usb_device_descriptor *buf; - DECLARE_COMPLETION_ONSTACK(done); - - /* Obtain udev of the rhub's child port */ - udev = usb_hub_find_child(hcd->self.root_hub, port); - if (!udev) { - ehci_err(ehci, "No device attached to the RootHub\n"); - return -ENODEV; - } - buf = kmalloc(USB_DT_DEVICE_SIZE, GFP_KERNEL); - if (!buf) - return -ENOMEM; - - dr = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL); - if (!dr) { - kfree(buf); - return -ENOMEM; - } - - /* Fill Setup packet for GetDescriptor */ - dr->bRequestType = USB_DIR_IN; - dr->bRequest = USB_REQ_GET_DESCRIPTOR; - dr->wValue = cpu_to_le16(USB_DT_DEVICE << 8); - dr->wIndex = 0; - dr->wLength = cpu_to_le16(USB_DT_DEVICE_SIZE); - urb = request_single_step_set_feature_urb(udev, dr, buf, &done); - if (!urb) - goto cleanup; - - /* Submit just the SETUP stage */ - retval = submit_single_step_set_feature(hcd, urb, 1); - if (retval) - goto out1; - if (!wait_for_completion_timeout(&done, msecs_to_jiffies(2000))) { - usb_kill_urb(urb); - retval = -ETIMEDOUT; - ehci_err(ehci, "%s SETUP stage timed out on ep0\n", __func__); - goto out1; - } - msleep(15 * 1000); - - /* Complete remaining DATA and STATUS stages using the same URB */ - urb->status = -EINPROGRESS; - usb_get_urb(urb); - atomic_inc(&urb->use_count); - atomic_inc(&urb->dev->urbnum); - retval = submit_single_step_set_feature(hcd, urb, 0); - if (!retval && !wait_for_completion_timeout(&done, - msecs_to_jiffies(2000))) { - usb_kill_urb(urb); - retval = -ETIMEDOUT; - ehci_err(ehci, "%s IN stage timed out on ep0\n", __func__); - } -out1: - usb_free_urb(urb); -cleanup: - kfree(dr); - kfree(buf); - return retval; -} -#endif /* CONFIG_USB_HCD_TEST_MODE */ /*-------------------------------------------------------------------------*/ int ehci_hub_control( diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c index a826715ae9bd..2cbf4f85bff3 100644 --- a/drivers/usb/host/ehci-q.c +++ b/drivers/usb/host/ehci-q.c @@ -1165,7 +1165,7 @@ submit_async ( * performed; TRUE - SETUP and FALSE - IN+STATUS * Returns 0 if success */ -static int submit_single_step_set_feature( +static int ehci_submit_single_step_set_feature( struct usb_hcd *hcd, struct urb *urb, int is_setup diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 96281cd50ff6..22c5d1c0acf3 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -409,7 +409,10 @@ struct hc_driver { int (*find_raw_port_number)(struct usb_hcd *, int); /* Call for power on/off the port if necessary */ int (*port_power)(struct usb_hcd *hcd, int portnum, bool enable); - + /* Call for SINGLE_STEP_SET_FEATURE Test for USB2 EH certification */ +#define EHSET_TEST_SINGLE_STEP_SET_FEATURE 0x06 + int (*submit_single_step_set_feature)(struct usb_hcd *, + struct urb *, int); }; static inline int hcd_giveback_urb_in_bh(struct usb_hcd *hcd) @@ -474,6 +477,14 @@ int usb_hcd_setup_local_mem(struct usb_hcd *hcd, phys_addr_t phys_addr, struct platform_device; extern void usb_hcd_platform_shutdown(struct platform_device *dev); +#ifdef CONFIG_USB_HCD_TEST_MODE +extern int ehset_single_step_set_feature(struct usb_hcd *hcd, int port); +#else +static inline int ehset_single_step_set_feature(struct usb_hcd *hcd, int port) +{ + return 0; +} +#endif /* CONFIG_USB_HCD_TEST_MODE */ #ifdef CONFIG_USB_PCI struct pci_dev; From patchwork Fri May 7 06:58:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 432414 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD226C433B4 for ; Fri, 7 May 2021 07:14:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7B607613ED for ; Fri, 7 May 2021 07:14:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231560AbhEGHPT (ORCPT ); Fri, 7 May 2021 03:15:19 -0400 Received: from mail-eopbgr80042.outbound.protection.outlook.com ([40.107.8.42]:37110 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230070AbhEGHPS (ORCPT ); Fri, 7 May 2021 03:15:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XwQ/2BwWCXr8H/d57FIMQ1LHCaMEZ271296Eqig99zX86Nddspo5tfI9iSOicDLk/tBa/x4m0xkRrETIlqpz1HAf6pLj6O5JdCojfIzYu8JX1a5LPk6ooKFIIBbZ1tmyBCUFLMwzOAKWbgJmiSaDfnnH8v6LTjTMc6OD+zEPtYGaZw2f2cwKf0atD/9TKv31DXqYf/CDg1OCzTllvq2dr9hKo0pd6AGDuRRlOv8FslA5eoGS1ff66jy/KQj5lnEUb5JDU33M9RTABJjvS+EN3C/eNe6VNPF730zQWfpGZg9lGKJTsN0gnUNFGg3zAzLmfPXOFolMECge9+S5VDu73Q== 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=alGqOi6XK/e5JZT00T5ei5LC+hGY25nAdhn1FrfytnU=; b=krnl974vmcyrj/uNhbkR6wcy3uo25tm0jkTTAb3baqjyfHqvHCbYqkgXjhzMsoIjgjD+lco5c/8/ubEBd0+rARsSb6VHwkG7kN+fxq9zget27vXSrlpIf5dF/xuYeWrSaSj1/Wyu98jgqNEjJxgRqD38akI8iBu7x5oA+KJqC507tV9mOype6i+3CJTArWtEmdXnV4uy0D4kVUym6tQZdOJGQ5aBFioD5iSr/hJp7Kagry9faJ74K5LpZUYH7hj9FihGdxpJujPKYKkCmX1Zfb4+Z+CkLBM0NxywKppCHntAA4SrkFNi0ftkyfnLL1etnWkHmMiy5GGy1C/Cu7X3aw== 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=alGqOi6XK/e5JZT00T5ei5LC+hGY25nAdhn1FrfytnU=; b=ITRH0dLhB9mpl0e/mQGLd86q+sMVxigsG0cmTvC8vknzg1MI7PAIMyHdO7rDj5+LFVrXKQefXhNgrApCAH+QKrVXZpcOcwL9djnbZSIJ0ZJRRhBVfVV7CQX0H1JV8gjQM3ttTaYqIyPB10GwvdkwIpRkWCs0+4TMd2wketOYp5Y= Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none; linuxfoundation.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5935.eurprd04.prod.outlook.com (2603:10a6:803:e9::17) by VI1PR0401MB2639.eurprd04.prod.outlook.com (2603:10a6:800:58::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25; Fri, 7 May 2021 07:14:16 +0000 Received: from VI1PR04MB5935.eurprd04.prod.outlook.com ([fe80::ddf7:8cd0:3132:7dbe]) by VI1PR04MB5935.eurprd04.prod.outlook.com ([fe80::ddf7:8cd0:3132:7dbe%7]) with mapi id 15.20.4108.029; Fri, 7 May 2021 07:14:16 +0000 From: Li Jun To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, mathias.nyman@intel.com Cc: peter.chen@kernel.org, jun.li@nxp.com, jackp@codeaurora.org, linux-usb@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v3 2/3] usb: host: xhci: add EH SINGLE_STEP_SET_FEATURE Test for USB2 Date: Fri, 7 May 2021 14:58:01 +0800 Message-Id: <1620370682-10199-2-git-send-email-jun.li@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1620370682-10199-1-git-send-email-jun.li@nxp.com> References: <1620370682-10199-1-git-send-email-jun.li@nxp.com> X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: SG2PR0302CA0020.apcprd03.prod.outlook.com (2603:1096:3:2::30) To VI1PR04MB5935.eurprd04.prod.outlook.com (2603:10a6:803:e9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.31.174.66) by SG2PR0302CA0020.apcprd03.prod.outlook.com (2603:1096:3:2::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4129.11 via Frontend Transport; Fri, 7 May 2021 07:14:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2d30c453-d774-473d-a67d-08d91127b955 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2639: 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: 9nE/pWGlvbkRp1oiCWuEm4c9bvWSyMRnQdN5943xz+7aLOZRKZ9GA5hp4CprOo9xUhy+MBx8FGFVvRjxJ8/MTaRv4KLnhiwAV+XrgS+OgKiiJU1zKhQsT2l4pwN7vH5vE9/eQlgCvlW+QpfSic6KCwngunhnCJCZB2iaGkmmv19VbRtyKiV2JECPTUlxuqq7tZrFsm1FZ8209RYryPWSQVw0H0dGovnRWcboJxVD+7+WHDA9ZVMJwRFSEimF9OGPujoOFUDG7zdvLAJZLIWl0VUkI8VL8Vvnm9Ae6V5bZIpc6wUSyXiKMEXlsy6nJ60VtwIPjHETtCwIpQhtVxZGU7Y5uJT2b4JrsOjWZLevjzyGUEMu+YdPHOnK/dzZkfOw5o/AUdytY8iYHDSQd4daPJHjNAxbuZXVDSVzZHOglEzl9Nhuji4DGb3ThBbwVF1v+XHZjT+NGrD1jiuxB7OpNTghXmi884i3GZrXPMBleAWHwre8Hjkmi21gStulHUJXhIpBB5vwOWzc7Ga8+w3MzLBj6QcOZaVQVIBReT+26ZRxUUPd4uZZn2H/Xs6xEo2wQc0AUwXb7aYDvLbCfNLmXJnAB/8n9pmnL/b+IgiTbEPUV8UOPBmPBdoe87XkHA7vm03ZQCYerBOq8rUiQrQEEU14Ff3dN4Yhxu2bQhhpzPNVQt83gJwYbH8ILQjZ8Nma X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5935.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(366004)(396003)(39860400002)(136003)(346002)(956004)(2616005)(6512007)(66556008)(26005)(4326008)(66946007)(66476007)(478600001)(36756003)(38350700002)(316002)(86362001)(2906002)(38100700002)(83380400001)(6506007)(186003)(8936002)(5660300002)(8676002)(6666004)(6486002)(52116002)(16526019)(69590400013); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: DY8ZSuElz8dMBZD/nueALRWDEWlXttUWvGAHy/fO/7WcTrQoDy8a4DhmP7nAuVPg55lKel0ulFnnat6dN00Syuny4fzzYjqcEyY3gq7WsaEZQX3ip0kcZiKx4scRU+z77IEtRex+6DqfhBRWFBMVP8WpmKwSml0uK5clxrEp92qlykSGXFdaUDukrV42P6JmqvF1i1HNjC9L2ReheJ8+HmO0/LeYaXPb8YR9SQnqMjLPzmFz7cvk12HDOe7Rik41PtvBMyXbdxES5GQrHBVEGEWFOBJZnl7pX53Qn0uFoeDetjEbWmwivR1Hi+GeLKu7EO7ISqXMvIB/FjJX5ea+a5QU/CouLDWCu2fxTRXLGgPKX7Y/NXOa8Q0NFvBnK65A5VXHY9XemdGRUTGoAKoNMbYWmpGl1UqJzgSfzzQDaD/5mA0Naeqm5xFxZjBcHHe+9mKwWl6ez7y54Cx7RQqSKaxkMBPoNwI8n3vp1xXyyFzH08AD4hQDRBvwYb07/fGdKprh7JWfPcLhMz4zeTjCYff4SrklytTq7kyqBogvBuSAM/bdxVTKn7pDdlCa2EKsnsF5Enmf8aiRYCTxznLGSqe9XsMuh/FAVkW3Ay8FlgUX9fRbFzvabC/kaZs8qEMigdxsss+KjCmvBLp3dq3QPdVeHZdYLfzKiJsAzBsQcCgVzM8Hr1NA1D+xZQa0DoPe8w6d6JGXILdfshW8Q1hL3POHXGLnYWHyc5KHPU8dFilDKcw0c7bACY2Q7+oxy7mO7FbWiQjAyY1vd74y9QU676P+mVxBPQaxcXGll1DL1CDOZwoAsTngwkJDdn7y8f6khdO/qSXWy/ndxTqJ1jVxXcujm/QIs0Hvg2irGgQ1rqXH4Robs9d/wRRGeo/DAt4dVr1hUDpoqj/dOTHE66WMbXW7sfOZDI1QXwavJTHaUr37UhIRAtzWlcrHmgXFtu7hR3uMKu0iIQkQTsabrHMQYUg0AFVo4t9IUMZJa84ZYJVurV2+aPhdcQQPFpKCZFUe8B8lzK5tTwU22CYNEExZe8BUczeU/UH2ndyRf9OC4WJBVC8HOjjYVdd8RNfOlpK8XtBwL3jgXtttQ1Bdo1nn3CjzMPLYqTZX+ao0noTtvjH0XXDwEloHdh9ieBl4IQ092xqe2qXjDFH3dNXu7clEIJNx8fg7QLdKUm+qNmb92lDpsvhJZo6Au64qjxRhqEAoJgMsABsuKLSc7dXA5SPcANcQz4Kp6LtCV5PRKwbwdr43Xa0mQ/lFqYwz8af+kpgra4ZUD4v6eTE3Jm0EeI8PfHSOb6n4pVnZve9eYXDzvMNH2CVI5kNn/L4iS4kYAKo/ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d30c453-d774-473d-a67d-08d91127b955 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5935.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 07:14:16.2679 (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: ogQKzeEEHmiNN14gy4A7UEd09x8l3OwrxYmX+YF/xiNdOwf5L3zk9UeZTaeqYpOB X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2639 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Peter Chen This function is similar with EHCI's, but implemented using XHCI. The USB2 host needs to send SETUP packet first, then wait 15 seconds before DATA (IN) + STATUS stage. Signed-off-by: Peter Chen Signed-off-by: Li Jun --- Change for v3: - No change. Change for v2: - No change. drivers/usb/host/xhci-hub.c | 10 +++ drivers/usb/host/xhci-ring.c | 123 +++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci.c | 1 + drivers/usb/host/xhci.h | 10 +++ 4 files changed, 144 insertions(+) diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c index e9b18fc17617..c64ee95cc89b 100644 --- a/drivers/usb/host/xhci-hub.c +++ b/drivers/usb/host/xhci-hub.c @@ -1511,6 +1511,16 @@ int xhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, /* 4.19.6 Port Test Modes (USB2 Test Mode) */ if (hcd->speed != HCD_USB2) goto error; + +#ifdef CONFIG_USB_HCD_TEST_MODE + if (test_mode == EHSET_TEST_SINGLE_STEP_SET_FEATURE) { + spin_unlock_irqrestore(&xhci->lock, flags); + retval = ehset_single_step_set_feature(hcd, + wIndex + 1); + spin_lock_irqsave(&xhci->lock, flags); + break; + } +#endif if (test_mode > USB_TEST_FORCE_ENABLE || test_mode < USB_TEST_J) goto error; diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index 05c38dd3ee36..87a9c1e3325a 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -3793,6 +3793,129 @@ int xhci_queue_ctrl_tx(struct xhci_hcd *xhci, gfp_t mem_flags, return 0; } +#ifdef CONFIG_USB_HCD_TEST_MODE +/* + * This function prepare TRBs and submits them for the + * SINGLE_STEP_SET_FEATURE Test. + * This is done in two parts: first SETUP req for GetDesc is sent then + * 15 seconds later, the IN stage for GetDesc starts to req data from dev + * + * is_setup : argument decides which of the two stage needs to be + * performed; TRUE - SETUP and FALSE - IN+STATUS + * Returns 0 if success + */ +int xhci_submit_single_step_set_feature(struct usb_hcd *hcd, + struct urb *urb, int is_setup) +{ + int slot_id; + unsigned int ep_index; + struct xhci_ring *ep_ring; + int ret; + struct usb_ctrlrequest *setup; + struct xhci_generic_trb *start_trb; + int start_cycle; + u32 field, length_field, remainder; + struct urb_priv *urb_priv; + struct xhci_td *td; + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + + /* urb_priv will be free after transcation has completed */ + urb_priv = kzalloc(sizeof(struct urb_priv) + + sizeof(struct xhci_td), GFP_KERNEL); + if (!urb_priv) + return -ENOMEM; + + td = &urb_priv->td[0]; + urb_priv->num_tds = 1; + urb_priv->num_tds_done = 0; + urb->hcpriv = urb_priv; + + ep_ring = xhci_urb_to_transfer_ring(xhci, urb); + if (!ep_ring) { + ret = -EINVAL; + goto free_priv; + } + + slot_id = urb->dev->slot_id; + ep_index = xhci_get_endpoint_index(&urb->ep->desc); + + setup = (struct usb_ctrlrequest *) urb->setup_packet; + if (is_setup) { + ret = prepare_transfer(xhci, xhci->devs[slot_id], + ep_index, urb->stream_id, + 1, urb, 0, GFP_KERNEL); + if (ret < 0) + goto free_priv; + + start_trb = &ep_ring->enqueue->generic; + start_cycle = ep_ring->cycle_state; + /* Save the DMA address of the last TRB in the TD */ + td->last_trb = ep_ring->enqueue; + field = TRB_IOC | TRB_IDT | TRB_TYPE(TRB_SETUP) | start_cycle; + /* xHCI 1.0/1.1 6.4.1.2.1: Transfer Type field */ + if ((xhci->hci_version >= 0x100) || + (xhci->quirks & XHCI_MTK_HOST)) + field |= TRB_TX_TYPE(TRB_DATA_IN); + + queue_trb(xhci, ep_ring, false, + setup->bRequestType | setup->bRequest << 8 | + le16_to_cpu(setup->wValue) << 16, + le16_to_cpu(setup->wIndex) | + le16_to_cpu(setup->wLength) << 16, + TRB_LEN(8) | TRB_INTR_TARGET(0), + /* Immediate data in pointer */ + field); + giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, + start_cycle, start_trb); + return 0; + } + + ret = prepare_transfer(xhci, xhci->devs[slot_id], + ep_index, urb->stream_id, + 2, urb, 0, GFP_KERNEL); + if (ret < 0) + goto free_priv; + + start_trb = &ep_ring->enqueue->generic; + start_cycle = ep_ring->cycle_state; + field = TRB_ISP | TRB_TYPE(TRB_DATA); + + remainder = xhci_td_remainder(xhci, 0, + urb->transfer_buffer_length, + urb->transfer_buffer_length, + urb, 1); + + length_field = TRB_LEN(urb->transfer_buffer_length) | + TRB_TD_SIZE(remainder) | + TRB_INTR_TARGET(0); + + if (urb->transfer_buffer_length > 0) { + field |= TRB_DIR_IN; + queue_trb(xhci, ep_ring, true, + lower_32_bits(urb->transfer_dma), + upper_32_bits(urb->transfer_dma), + length_field, + field | ep_ring->cycle_state); + } + + td->last_trb = ep_ring->enqueue; + field = TRB_IOC | TRB_TYPE(TRB_STATUS) | ep_ring->cycle_state; + queue_trb(xhci, ep_ring, false, + 0, + 0, + TRB_INTR_TARGET(0), + field); + + giveback_first_trb(xhci, slot_id, ep_index, 0, + start_cycle, start_trb); + + return 0; +free_priv: + xhci_urb_free_priv(urb_priv); + return ret; +} +#endif /* CONFIG_USB_HCD_TEST_MODE */ + /* * The transfer burst count field of the isochronous TRB defines the number of * bursts that are required to move all packets in this TD. Only SuperSpeed diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index ca9385d22f68..a27616775845 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -5426,6 +5426,7 @@ static const struct hc_driver xhci_hc_driver = { .disable_usb3_lpm_timeout = xhci_disable_usb3_lpm_timeout, .find_raw_port_number = xhci_find_raw_port_number, .clear_tt_buffer_complete = xhci_clear_tt_buffer_complete, + .submit_single_step_set_feature = xhci_submit_single_step_set_feature, }; void xhci_init_driver(struct hc_driver *drv, diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 2595a8f057c4..f93fc8f59af6 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -2165,6 +2165,16 @@ int xhci_find_raw_port_number(struct usb_hcd *hcd, int port1); struct xhci_hub *xhci_get_rhub(struct usb_hcd *hcd); void xhci_hc_died(struct xhci_hcd *xhci); +#ifdef CONFIG_USB_HCD_TEST_MODE +int xhci_submit_single_step_set_feature(struct usb_hcd *hcd, + struct urb *urb, int is_setup); +#else +static inline int xhci_submit_single_step_set_feature(struct usb_hcd *hcd, + struct urb *urb, int is_setup) +{ + return 0; +} +#endif #ifdef CONFIG_PM int xhci_bus_suspend(struct usb_hcd *hcd); From patchwork Fri May 7 06:58:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 432769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD537C433B4 for ; Fri, 7 May 2021 07:14:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71130613ED for ; Fri, 7 May 2021 07:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232797AbhEGHPY (ORCPT ); Fri, 7 May 2021 03:15:24 -0400 Received: from mail-eopbgr80084.outbound.protection.outlook.com ([40.107.8.84]:11906 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232796AbhEGHPV (ORCPT ); Fri, 7 May 2021 03:15:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F/HT4I4wimY7JzMx6yYA7eemTNpu9qgi4Bv4YPy7pIPuJFHuvNYi8G5G5VuT+eGhLP4NOznI4i+LicpQ8h73bjcBt2txEJr3B9JIZ4RY/LFBZpsLfnfUfQvwb+/5z6P4mLJL8YrOmzlPmBhclCOc/8uiatLr67gQco4JVrFKCAcf0JxwNOYfk59PwnADdYGs6EHUbZHgBc0YFHfJMfjNQzl7RfCQNraLrMDU35HXz7dVw7VZ1+fJIeujDMJHIcRTNRsOW1XFXTV2IX8XNaXGhmTrQgIlxDqViHI9E3SkStqrf6IcRIK1j0uY9Hle7FrqAOT2Z5wvDarACY3lbJ6MXA== 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=2/c8katVCQUBmobIe7DOEVyFd/toMt/OyoSg0A8OYeo=; b=VhXNrXd3mKX51t9sBeQ4qFnVm8PK0aOLdj0Ed+kN4VPcT1Gb0bEVcxn6Z4EdEM1FLLPtYrdGNSLeAabOQb9JOUl7DjoP487CyziEEwTM1ZdxFkBMuv2r7a+QGjkFySG0yB3FjzLqZER+wPnkupWG1QREOP6322G2FAcurlLZ3BLkjiLRss9vctTPJ6cVmzHlZPyrAfvsfvYK/L+re9C3FB6lldAwnIet07KnkjdrNOIvTAmgaNRPjkj81iUFXbscLFpWxYJ6v5dNCdJhUAqzK3ORp/pKRNLuKB3NDdL28IAI2WnPJLHVFIUbqPNhjmzK5Hm0n5IpHo4rsywRxkTxtQ== 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=2/c8katVCQUBmobIe7DOEVyFd/toMt/OyoSg0A8OYeo=; b=LtqSQDuxQk1bsrabZ/D7Cj0i8THyKlW2TvKmF4jvO6Nb+YJCcHC0/Bn74ftVoC+T3y+dOWDCpMzlBmQ2SjXQU8d83VLBPrHeAWf7rkWIs3IRLfV4qVpa3u46BMW8YkacUom7stH4nsxoX9JSAEiZFrvkLzjOWxJ0nljM/NDvRnY= Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none; linuxfoundation.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5935.eurprd04.prod.outlook.com (2603:10a6:803:e9::17) by VI1PR0401MB2639.eurprd04.prod.outlook.com (2603:10a6:800:58::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25; Fri, 7 May 2021 07:14:19 +0000 Received: from VI1PR04MB5935.eurprd04.prod.outlook.com ([fe80::ddf7:8cd0:3132:7dbe]) by VI1PR04MB5935.eurprd04.prod.outlook.com ([fe80::ddf7:8cd0:3132:7dbe%7]) with mapi id 15.20.4108.029; Fri, 7 May 2021 07:14:19 +0000 From: Li Jun To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, mathias.nyman@intel.com Cc: peter.chen@kernel.org, jun.li@nxp.com, jackp@codeaurora.org, linux-usb@vger.kernel.org, linux-imx@nxp.com Subject: [PATCH v3 3/3] usb: core: hcd: use map_urb_for_dma for single step set feature urb Date: Fri, 7 May 2021 14:58:02 +0800 Message-Id: <1620370682-10199-3-git-send-email-jun.li@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1620370682-10199-1-git-send-email-jun.li@nxp.com> References: <1620370682-10199-1-git-send-email-jun.li@nxp.com> X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: SG2PR0302CA0020.apcprd03.prod.outlook.com (2603:1096:3:2::30) To VI1PR04MB5935.eurprd04.prod.outlook.com (2603:10a6:803:e9::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.31.174.66) by SG2PR0302CA0020.apcprd03.prod.outlook.com (2603:1096:3:2::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4129.11 via Frontend Transport; Fri, 7 May 2021 07:14:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c6e7fed3-0446-4a38-bc10-08d91127bb11 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2639: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iFgyKVsR04J3EWouYbh8Ampl1Jn2Vkylum2wOvByoxvabJRmWBygNU3IUYKDA8mPumh4Ojumlzb2cQbOgtQjI5izF8YcJGn0YKaMrLbwxQTNB9DSV0Q83Y00W8BNJZO9BFy1CoyfoyiUGODx3JrS1DYIdL5ziZACw9XJ4nZaJQa6rPJgTN3iJzhsD7tzRyVUExthM0JZGtE7rNCAQHhyvlFB21iLfuX3TxDaup+RTCNUaIFzqfxlQLQyU1A1xhwoHi/uRYG16ULxtVm0rwM7Q2PtBbZvHDurHAUjUAD0aNPOHFcO9E6LAwLynl28d7tXj8qobVHJTTcY2QBWkElzYG/vdcIa96xl4a14Nj9GsR6nW4J6emERzfRtDk6zE9hVLSfdo8bB2WopDoiPtk+r3/9POOFKIVtpfS/2W8cZIkPlv7FBnHlnH5m1tHhftIh4Y08RXXGxxNpLz8NDKGNCTndmMwj2LRkzGArUzceSI+S/OOZuYlLzK/YDJ3L9CuYXquESn2Uqha86AtCto/TXW4mh6aBGq0Qk6+eHdUA8B1Xt6HqwbH08meV8WKB0pEtYsjRRSmVtu1gL9HGodGtc+ufvLZB2bI4hxSqcyvngRMQtDPvqcpSrTDmKBpxzJvmzucKKxpXJdc4OLpN3Dh0IUfkrOwdQC0b4Vj6ZrsHiik2Xlzo4m2FlMQG3ClLlAhsS X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5935.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(366004)(396003)(39860400002)(136003)(346002)(956004)(2616005)(6512007)(66556008)(26005)(4326008)(66946007)(66476007)(478600001)(36756003)(38350700002)(316002)(86362001)(2906002)(38100700002)(83380400001)(6506007)(186003)(8936002)(5660300002)(8676002)(6666004)(6486002)(52116002)(16526019)(69590400013); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: rJTPR1OeS/pyl/ciW3ogZfqQLEgqdt9aBVCw9hWOGKdL1c1ORlteBQ5EAoDrj+GJTgX8hPnox+0NQSfShYZ6T4v15sFiw8fWllvO1QjESp1UAhwi9aAZ4TzK9KETwlv6j61hUJbGptbGGc4IChfvh2EN6/CTlAaxLlW2yakcM7g+85Q1ypgaLbWU3dy2QDWHCFHe3h/4h2DHHoBKVN2h7RX1aOLwXHw4ODnTwRa4U9TYrqjSyghhGY5ip8mBAGUbDXGOotRkOt49zJEQEDUyMFM6b7WHmc83RGEEh9/74cn2j8TK+cGWASaVXl2w0CBpzN2Ks7UohqnLxRWEKuojX8Ied1aDSfC6tpWJEUtxNTSYUTLLNUpCxp0U4fzzjv0sOEJe3ma4jMwLMufl/ITGreYsu8HfCj3uaco6ivUD9stjxoqkgFiJLaDw2lFre3nl9pLCtkq4PwUCx0c+4NO9ZO8B32x+CM+4lk3fMRU+fxrrubbIdHxYr4broevs7lo7AbcXQ4nhpFVe7ZZzprWOumQ5h7CNzJHZjB5m437LArgFasw6uQEmMe4XTFfpEH2/qFh6N6cj3D1yJY/RsRn71EAh8GdPFOV66L1W7e/c5x39EMSRu4WTJ6p6Lztv6bQ+ulaDnWiw51xB0rXnU7gsTE+zm+DlFORpr4NeM8gZnJ719eD3XRTRjvc15euBzmd+GFsRDAo9420YgfGEBWiNT0Qm8QZpRtZWttwGwwHV0B1AfT0n55gnYCce/5gk50A8Wh2hoDM7Wf4VnKXmBloJtnaJIHpKgVCnz2NoCKlaxmSCinsZHkAeADJrsjvKYRzt6Hd73bVp2NC7EoG0qxXRoes8tGaUG2lsC4scLmyN60W/IxUWYWJnFENHSHgt8lDcFJGjqf3GYKxGTHzb2n0Pu+Mt1VrRpOrbrRqgvdrAFB2cRPis5FNs/bVsFpoDxvQAya+gVePE+uDBBdx3o7OlixmwEjklI9oIb2GjD7bZgMUvNo1nZvOgVtiElVF+qvp7QAzWFmATD4B/E7Oz0aMeRaAcWHGRxAR58TN487MqFodrr4/2r3gLCqTmQtAK/8lv7QJSiOE2Oh873prxZRcqJp15NTNIFPpc7Kp58exbnE5z03gqaPXD40x0/T+J3LyjLXDGbqE+X8FQW22Mc0LFGOQ/7kbNMlnFEpytHq5bA5xyE5UY79NLtfvNRiA3/xLIwOIVQqAOGeoEk6NQLdKoxT9a5pND519qhSWqzHJHsvp3wykQCngSc0ZpdkOSOKNIHm86aBgUkammVTddnh5HYjE7bu1cmclkA8lAVq2f6RQwPIy4b9QI2utGrOM6xAlc X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c6e7fed3-0446-4a38-bc10-08d91127bb11 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5935.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 May 2021 07:14:19.2582 (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: T5TQoTt65poGiWaNb3SI4XPVg9itzjC6F9JazP52uu84r0lfeED9sNip3LiAYPLc X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2639 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use map_urb_for_dma() to improve the dma map code for single step set feature request urb in test mode. Signed-off-by: Li Jun --- Change for v3: - Correct the error handling if map_urb_for_dma() fails. change for v2: - Add this new patch to use map_urb_for_dma API to replace both of dma_map_single() calls, suggested by Jack Pham. drivers/usb/core/hcd.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index d7eb9f179ca6..fa72697f4829 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -2159,16 +2159,11 @@ static struct urb *request_single_step_set_feature_urb( usb_get_urb(urb); atomic_inc(&urb->use_count); atomic_inc(&urb->dev->urbnum); - urb->setup_dma = dma_map_single( - hcd->self.sysdev, - urb->setup_packet, - sizeof(struct usb_ctrlrequest), - DMA_TO_DEVICE); - urb->transfer_dma = dma_map_single( - hcd->self.sysdev, - urb->transfer_buffer, - urb->transfer_buffer_length, - DMA_FROM_DEVICE); + if (map_urb_for_dma(hcd, urb, GFP_KERNEL)) { + usb_put_urb(urb); + return NULL; + } + urb->context = done; return urb; }