From patchwork Sat May 8 05:33:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 432943 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.8 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, 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 D0B5EC433B4 for ; Sat, 8 May 2021 05:50:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AE1C561464 for ; Sat, 8 May 2021 05:50:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229521AbhEHFvT (ORCPT ); Sat, 8 May 2021 01:51:19 -0400 Received: from mail-eopbgr80044.outbound.protection.outlook.com ([40.107.8.44]:62119 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229473AbhEHFvT (ORCPT ); Sat, 8 May 2021 01:51:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dLbsXeOTutxARBmuhuVI1kugqu2Ov7lCLBNtw9RnMGrYrWxPQS13m3VIPMD5B6t+2Cq8XQVKkzU+aKKls9yeS+V5JX8JzKOwdba+pGplwjHfQ/vpPAdXY5pckFdrphgiF7O/SUFtf371L70BUHcn7ObPIjI189tlyaglt6f6pj9IB0EuQu+7Jy/urBBvQHJz6vtYmtAf0pIHFNJQS/dW4bh1nwPx0MxOSKLWvBDczU4igrqQ87auk4BM6dyLOarDADUk7raGR7ugNHfxUwghGdnO5xVqSR/osMp7YJkpwQJP1C2AMRYld0qE8PujcKdPXhUueftKa1tuCqm+1Emwjw== 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=9xhjvczhnAWDdOFQA/3q2O6dWzBzDp9k4vft74qZJcI=; b=Srw9FZGQutefe32uz0klHtKRESyIlmMCQLjsiJxyYmQEzLFdJZxAs7hvLLh5jVvWfL4H0ukxd5JQ4MNi+ggv+aRmbBmvxRVH2+upefwbghbmfbWi8Q7hsFEGH3SQ5pILBwZSAA/0PM88+rY1MMyuHvPkHUqta7LGVw3d77vJ05QR30WnGT+cd0Kp8ha1G05YAsYL5stm8IVTkh2oWWcRHl4OxmmmTrwnpyO0dguNTCfGw4XpdtG9SVDsYrEW1sQGec3C6ez0+PecVRxPTqaGKO0ZFGSM0BiBmVpgKgXwO2GgXtRZZX5Rs+RNMAPHal5NqGtWKg7zh1tUA0uk6gA44A== 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=9xhjvczhnAWDdOFQA/3q2O6dWzBzDp9k4vft74qZJcI=; b=gg+HianQTyiMDrg4rH6R7ql7nfmNXHf37mQj1vEYlIxLC2Gc51UvYteAhc3mgE9eAQZDUFBpmozFKQOn6ngxoe2smFuUC//PVSfw6EtNZv0RRlG8jSdhVNsC2j77VGkK3Xm/ThIerNMB6FX274w0aYSsI/27oKDCCiy9xROsp8Y= 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 VI1PR0401MB2557.eurprd04.prod.outlook.com (2603:10a6:800:56::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.29; Sat, 8 May 2021 05:50:15 +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; Sat, 8 May 2021 05:50:14 +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 v4 1/3] usb: host: move EH SINGLE_STEP_SET_FEATURE implementation to core Date: Sat, 8 May 2021 13:33:57 +0800 Message-Id: <1620452039-11694-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: SG3P274CA0009.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::21) 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 SG3P274CA0009.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4108.24 via Frontend Transport; Sat, 8 May 2021 05:50:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c30982ff-1cf3-4b51-d7ae-08d911e52672 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2557: 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: eLrO3H0OC+oI2W7/YtpkJelkpMmjpfwKrwjWjq72Tp65ZVGKD9woFzZcGTfgCvBrmFhTd6WZs08Y4UT0+DxVezAd9KjNCihFHsTOS1CREE9WAlpgDWlYlTDB3SWE/3RJPjd6q69g6RYwbL1ol5vNoUI0iFoOW+5Be4qVJ9KcylosA73CY0iqwOAsRJGMHOMSnSKIYLZFxqpUNAKErkdSSTLeZ6vxzVm9FVzw0hztxWgKhxe0htiunG2S2+CYL+ZsHi30qUDlS3i0iIT7MoAr6WlzhfFTyYhkHovpCB0eWRkJ2oXyB1BAXjKUB+mOP9Gbv2U2oFL3wPdATi/8FPwcZjx0QXD+DILE7MKXIlM1a4WnwEdkCKP/QySumTmUV5mOm5bZTlduQkgJR8b+sw4por3lfuS78ZYoxRifDNd24ECeSFz99SwagxYsSvh89QOeh5euiCSAbz+KxGFNZwuXg/gCOqeaY3fd8B48vt4w+oZ9T5HpO/myM+4aCgTzFmppDb5XpFCKQ2Bi2uAuFd+J4hpBp4k9ixcUE23hgp9CeEMhlosBB3bYwPzor0wVbip5HObx7y6xFXlDjbF1FCrChwjse2KsJbjzeirtHpWYDDVtu1mNH3poJcXappAA1IFmz7wqU8NTQzvZABkTGyNNwTe7TVbIa/RazQ2FJ9mLEzDuw1ESxeHTk9AjMByW5JO4 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)(39860400002)(396003)(136003)(346002)(366004)(376002)(2906002)(8936002)(52116002)(6506007)(4326008)(83380400001)(38350700002)(38100700002)(2616005)(66946007)(66476007)(66556008)(6666004)(956004)(8676002)(6512007)(16526019)(5660300002)(316002)(36756003)(478600001)(86362001)(30864003)(186003)(6486002)(26005)(69590400013); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UeeWXLeFYhzZmCCRGBwHsAwGRz0jboQRifxyOAFmOd1XIRaNOuueTEsO7sHf9RHjYMXuhvZU3n50f9KKQYut5Tkt76chnvSGm1Qw8AhAzTmh/Q7G5THWRybR9gLmCIZIlVPHExVVVW3IFBd+hFG+rCeyL7Z9Dwns8Ve7rYpxnrpi+y4/YbbeYX6Fubco1yHtFApcIIpSToP2bbFogvN5lg1A+v8pRLejqBrOWN8EUbYjHUc2TCJ22WbourIRqAqKxJ83VLh1EM5rykJR4rKidnYWviO31tLXEY8JSmjlon0sjHxtXOvT5ltAiuwoYZLMiELk/WUoO+JS7gBNEJszJI2P4DdaYlX9u2FIb52WZsQW1Nrh/yuhhmndSMIIRY/IJDkBpgoXbnrj5E8wdrNtSH2P49FzUGj0vvuqnM1EYR+/qLSH4fMswjMfkvXr/zLvZ2gH+RWlYchPbM1/0+Yp9BZ6IhTO+CoGIXYfzjqXttSYnWstCo3qChnLOJOir+o1Klf2SCR144fp5PbWoMm3CpCoo27YIInkwO3uidBPpBwDjpNzyEfsF5QQdbzRKi3wXCF46utYALoG6E4iSous8kmcijx7cQ0QvZYGeFGtNY1HAznYSB0qFJ9xN1Kf7sCnj/64hG3Hn4FZgrkDz8dvz0mAI04LErf8cCHgHVTdEL7GYlsTYi/hKoEzOOt0FG9tOPp3HctY725VkypuJCwuUSEL2O7HtxcCj828ukBQP21SAOK4rtPY233VACmsutOCY9rhB+jxcV07v8DT+xsQnxJMR3kCF7ubBsoiy6LpxAAePX2fXYmqXZrmDERQP4BF6UrwWN0i6DZGJByEjXpSRcKS3DfMPSKOjnYyJG7eQzT1oC8Q6mupDlWXcwdmQbyeQMg1wRz887KIn0bdAAazyJbhFMzEEUhpVI7n0aC8MSXD4xsac6e+3mSmEWXY/L9HjZ5D0LQa5Fe3FJkquhrVrbWvPC/HhIKhIB0WvsK7euLfpFX+Jzv5Xqs756tamB7fd4Fy4WTN3sORCCLufP1mgA5Rxj1FnL08MSfd+d7JQ2dgKwVTFBzTMavr2jThJBvMNMFsavkGIHx2Ag1cxyYtijutQwGMABtgJ0eHwj0aqADfpRqhqjn0ZEepmby61j2hgF6nYrh9l5IMX8DcTCvdaGhZwegmzqSat/7ne546a56zi76ajMUJ3m5dZ4xZBHWUU1FSVRz+tY+NC7zYLpe3FZnp/4Tyj3OzI46Wbpms9UDWx472YOVCUtwINLhbUWglvBKAGDWwgUnltDPB8y3D74InRrSbaQNYyCkaehdDusOnoWVUaqxkx4l5jCaBy+M1 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c30982ff-1cf3-4b51-d7ae-08d911e52672 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5935.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2021 05:50:14.8444 (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: BdW0mCL+ZROeKMnj6JyQLzsT0hsHjjS7pF7EokU/aI7MK0ExNv8QllqADBSegK90 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2557 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 v4: - No change. 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 Sat May 8 05:33:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 432765 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.8 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, 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 C3B5DC433ED for ; Sat, 8 May 2021 05:50:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A20576145E for ; Sat, 8 May 2021 05:50:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229523AbhEHFvU (ORCPT ); Sat, 8 May 2021 01:51:20 -0400 Received: from mail-eopbgr80044.outbound.protection.outlook.com ([40.107.8.44]:62119 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229481AbhEHFvT (ORCPT ); Sat, 8 May 2021 01:51:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XtCa3NZOZXppIzA/Jos00eD/vqRsQODCoIsE4MYVD3fJ06pouFTUotyotjdcNh1CZDy8LUQIf7kW09Lu+KN4KONDFXfdSB/CHa0zSpYIL3MkFcZo+aj+dZ+UaKE+/3+gfOqrWvkWQiOrjpPfX3kQkuU/WIITF9ouuHBbqxN2iBMfnJnNDpU28WrpvkuJX7Nid52xk5YULAxAFIjL0l8+nz2/cbbTFAA6F+7wNA5XDwiQ4IUMkw+b5NaD7Lxm5ksGJSnY+DXpVaKcC8L45SzvmIav8rMpiO1xvdp95oQe9K+HImKBorXlo/noJu/WKWzoxNm39/0WE7qoFjkM0DpK7A== 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=bHHT31ga4R0H9qZyQLw7kT1NFJaBBVJjscKuj/Kd7Fc=; b=k9TpS0xSEV1XRrGpzPp7Sa1F9uClgDCz2uGBkWuNy5Oj63bW9R//WrhOow2+Jmmtp4JMfcAAUeNx8IG+HEK5jiP+27efTDCaxUZyf6cyUk/2ou/UwWOHPec38ejMqrbbuwJJ1vhFA93bA+0WPcl9V2aoHpD1mxQyUWNo75Y/UHgOP8uA+Q1p9nrpm4nsJJG72fy9StWiwLLpzDVXPpSUzXUMnZl3lkYv8nCyAGrozmRJaGnV72426irUf3gKuOPmZjr/3/93UeLbYrDBQoIup892g/hR8efmAUYJ1x6O9RvRxRdwPQ9EIlX4isW48DFIh6NSGXaxm7gXtKwUabJfUw== 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=bHHT31ga4R0H9qZyQLw7kT1NFJaBBVJjscKuj/Kd7Fc=; b=Pc/PUU7+JmgDJkDk08stHCksKBqs6sEIl1ga+QwkDBKZAvlsWklA5si76wOggQkS7CXjfAWn0AACpuhSFBXK75cn9pC1cbR5sqOrXEKZfmCjyoWzyu8vyIgWWNVj98VS83DswFuBL1dKAyPyr6QYXKWI95vMYkMDqYh5d4urJA8= 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 VI1PR0401MB2557.eurprd04.prod.outlook.com (2603:10a6:800:56::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.29; Sat, 8 May 2021 05:50:17 +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; Sat, 8 May 2021 05:50:17 +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 v4 2/3] usb: host: xhci: add EH SINGLE_STEP_SET_FEATURE Test for USB2 Date: Sat, 8 May 2021 13:33:58 +0800 Message-Id: <1620452039-11694-2-git-send-email-jun.li@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1620452039-11694-1-git-send-email-jun.li@nxp.com> References: <1620452039-11694-1-git-send-email-jun.li@nxp.com> X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: SG3P274CA0009.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::21) 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 SG3P274CA0009.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4108.24 via Frontend Transport; Sat, 8 May 2021 05:50:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d3aa58c6-be01-4be3-2360-08d911e5289a X-MS-TrafficTypeDiagnostic: VI1PR0401MB2557: 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: 1aUI+hijTxCfUTXGLJ5LAl5GnKDHUTbf9+R4nriA2ypnrat8XMecH13UdFHLSkYSaLcxrbITBUSPZwBouYe/CjhxFSu33Aiyb/eQNc1ojnQD03ROhy2gCL4kHrp9392i0AlS3uzsyTZekN5P6G3qRc1AR8lSaRSDmOa5zqH0IzIBnU0uzmd0jEHoq9WNVYOOASrjffmgj6z/J6qNJRgLLoMsuGa8lbvTYV+effLlFrTDlp5twJMP3Zr0qxl460moHt1vWPrik2FUc/fT9WwNWzpfTFnnxqLFMaTrK4zwU6TbbZDUQRLRtCwV+t5OIgXZT+7UsD1XdeyaIwWaLk2BYGXQ2lg3S5Q0m3EOyRxx5mQKfgNGefWV2ups1EVnrk/ZkuIJYStS93w4lteXd5uhZghRQ1X2Om9z1QMszCzQW/dO2o7RkbDUxpyCSZWpbWWK/YVSLSNKAB4d0V4dgYlMEecpAWTC4rgt6NCVr1O+mA3oHcqqf496LnQGPs29XlX9gmUpjEg2JU2C1ckozp90InTTv/s3pZuZoKp1/dCnIf6d/Gn30UjCMpImalsP62Wd4hC58KL+Azl6chOTRt9qQ+aXKR4uDm/lv3frwYUssgCyumGhQHXZmSljvlgG1q8u81dk2YUV8Ei07tGBEcyVizWRWKuVKYQ2LisTGmK/TF9gbvbzBCq0NqeBtWP63vSI 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)(39860400002)(396003)(136003)(346002)(366004)(376002)(2906002)(8936002)(52116002)(6506007)(4326008)(83380400001)(38350700002)(38100700002)(2616005)(66946007)(66476007)(66556008)(6666004)(956004)(8676002)(6512007)(16526019)(5660300002)(316002)(36756003)(478600001)(86362001)(186003)(6486002)(26005)(69590400013); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: oRtEbrGFWulCFZcPZutz1G2NEYzvkPcJ0nfFz+5jSuC9eDBA2LilY9C+T/wDqZsig6e265pqiE6dTHPAWAEjq8rL/IcVFo0IUHfF9vh9RinyTmMty1yLDtaDwC7xbxmaDb2tREqVLFxupr/XvFMSd9apZiE8yxuIcHNy6qGWunICev5BQfGR3YbK+RVuJ4gf4rN8WpUnM2/UBpoQUKhDoBx383N3enywZkNvfhBnjxTVf97j3fdNZFLx3vGIz9s4QFGuDFc+blyhi625jdhT0TjNud5bJVqJWM6u6Hr15sRpkC+4iyVWox5ITZAe3wivmfDUWRmeuaTNpqeOg9SaIsmIUjfropZQsboFsny7GKFVWZR/q1SwDk2U52tUEG+qDUPU2l2isJZml9zhQLkQGXcpLrG9UxXyAzPg9LfOoCmwCSmdB+9WXS9M3quPTx9/sT7NrWnJrSC9hdkN/lgFn+QkF4ZqYIE6BB93wH4sA5fr9umzolgl8B3eoiw5k/EkZZU/o64s6hQCXM28UkKWi3pDyKmadFn+kLh0NjW0DpF1jvSQMV/G+kSfA5T+McLwaRiyrFZi+xAj5W6J597UuJTCk2r43OOhjZIyNcMA3XHNSEBU3zZwuZ+SZ77spc/LI4PQji5E56A2fas6XJwv2u00W8XRmo8f3I2GISjXaBER6/2ifgT7iZQLAT97hj1nIEOJYH8KYHz2w9ovzaKutMaKEJjb9O+Mdw+xBEBgeBqK4Y2RLPB1vQY4Lj86lM/3PY5aeXHeP4HiSMLZzQc1E6MgIIfVLG+j0v6TenKIZC8Nlz39Q/oW6/F56jGEB+pQhfwQwVpN2yAPemDVfvv80KCUnUAgR4+v/MYtqBNZTjnLsQgs2lHJ65JSTDIdtmMsDulAqvxadrZOD3iYy5N69MG09BKO1f/Is/Uqd2g9qnUPUgro43SvyX9yr8sKfhAImHNpPRPJYjZEFnEoC2a6V8nOuQmlVkU1YW+G6TNyGped3+zzZK3VwPiRHsFRYoljEAcC8oeLoOHT0OAOp4tLLc3z5lEAGnyZgO2FKimWUT9MSoMNTX9oNbVWNJOoKJFdLX622m9dJriWDBLQRVGJMXBxsiaQ2yl3PuEmyXH5RXns5O4vHs0mX4FJxwpwO8yV6DTZSF19weOvvF0tq8I5hEie5QxUZLVuLhzVKl32L3QAR2YMMxxx+JvX0rzQbvTRWrR8w2mTGEnJdqf3C2yQdjdqmKy7gxK8A7urr0hj6qC2cakZoBYk4/W6JxPXTMGcQpabFKPA7axdXy4vcX6/KHzVaW+VMIlmT8iV/Zes4bQf7KLnpNFBy92l5a47/GWD X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3aa58c6-be01-4be3-2360-08d911e5289a X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5935.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2021 05:50:17.8377 (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: NkQxxmXwLLZjJVrlESMxluvs+oedzN1ovaBQbboyMyRc0JW+lCMhgJuC5fdyVI3n X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2557 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 --- No change since v1. 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 Sat May 8 05:33:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Li X-Patchwork-Id: 432942 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.8 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, 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 AF25DC433B4 for ; Sat, 8 May 2021 05:50:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8C26C61448 for ; Sat, 8 May 2021 05:50:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229542AbhEHFva (ORCPT ); Sat, 8 May 2021 01:51:30 -0400 Received: from mail-eopbgr80073.outbound.protection.outlook.com ([40.107.8.73]:27342 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229481AbhEHFvX (ORCPT ); Sat, 8 May 2021 01:51:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ktzS9DR7g6wn75JplDdqgmKV8IlJ0G/Pt4p44USUrg18VEgh3ay5A1hFQmZRyhIrJtR9ectS6z3KV5FNGmHM2nOIXawwWgwqf2LcRLEX+xxlWOZbaXdJIaBK1RV+g21PX8000A/UEaR2v3arWPDqwhgYepB974RICthXJWsidR5S+YC3UJHO9gbGd7Rd3sed+WJ93BLfyDPH96O44oJDWW3jcdbAc5gyc5g+3KYa5yBD2bXkNhA4lxmrXzDmhkrlsZRjcfQhTGbCsksSZuoJ31gsKX+tOE+KayJNmquL98ojZ7JAxx83NEL4FaI27fY9d5lMmdvcsqnUYGIcHIp3Iw== 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=58rcjgRM0e9M+iPvx0aFYPXSjN8h3AMEN3YjUsgaHFA=; b=SO+LryE8CeIzoysJwgXeKEOTDqVxZWcnuHeD4Vrhy7T7DWvju92pfdjzShYnyTjxr4chNZoIPLU8N0IuEVNxlms9lUmTVozb+B+x6vYWWC/i3zP+J1XLSdgRDAqR3KAMrUqwHws28spRUY3rBPegmesXi46i/aLDyFRDhdil6t1B3lBYDt7Gy6nffj0Dl9iTge3e5T/E2hlMkFenaieC2Cn/YIInKJJFNQ7MP79R4enT71ak9y2AVa66AS6zJbZvdGB1eT6rt6FPizY5DcAz+kuTdsOF0yKG5EEeRfZV66lMs3BeGMIjaP6XkVVeaTOMLDNrw/AuzlhgoQhzuDN1DQ== 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=58rcjgRM0e9M+iPvx0aFYPXSjN8h3AMEN3YjUsgaHFA=; b=aOBHMVXpc3EQHLn9eov9gdGQZKDJLn+zlRS0RD3Uwe0txCNJhmoxNwtNTI8tMsxXzlUX3ZDALLg1XxdMvmfUQcQnWlYC8E77XGFig3tqMIlSATWbzefr4FZRg33iMP2T0ywgAHlMYo0DUg5PuOvMnxWsT+q6HF5Vgrp26s/tfjw= 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 VI1PR0401MB2557.eurprd04.prod.outlook.com (2603:10a6:800:56::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.29; Sat, 8 May 2021 05:50:21 +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; Sat, 8 May 2021 05:50:21 +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 v4 3/3] usb: core: hcd: use map_urb_for_dma for single step set feature urb Date: Sat, 8 May 2021 13:33:59 +0800 Message-Id: <1620452039-11694-3-git-send-email-jun.li@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1620452039-11694-1-git-send-email-jun.li@nxp.com> References: <1620452039-11694-1-git-send-email-jun.li@nxp.com> X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: SG3P274CA0009.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::21) 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 SG3P274CA0009.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.4108.24 via Frontend Transport; Sat, 8 May 2021 05:50:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6022c9b8-cb6a-4e80-bf40-08d911e52a60 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2557: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 11FyAMvnMiCYvfm7MIP7QSJmxwgkU/dFSZUezo5HTc+04eX3DKBT7BboFAP6xvzgZ1cwOmJBEdzmuPUmSpoTiLmd53NhpvK+En/qHsM3JjQTp2A4QNTFlT18GACfwIwe8koKJnm3k8d/Lv8tSwHqQOi3hJTJm2B6JP9qg5kqbtzMBL5ID0fpd5bFP5t60gP4kKEg9hxgDGtxHlkYDh0H7y7+pUcPva4tEyD3t5WtIH8KoUheD51qUrVFfZ70SF44b6pcvv9yipgoYCiMLwEqy9WtoTGW5QsCxPpPKUdAtXinD03f1eR/h7YIUhggzz08ODg+n9ljzC4yACCAVMhRrly4GMywFHM30WNTJsP9grCebEEyYeoKJxG6bP+zOqfzJX3ZU1fApxy5je6oOjoUzWhjpfb1A3qjZcjSu/x0W9i8sByzitt6uNxaZKShrMXmGxNhqzRXN77lpq7hyD/e1DmQSs6kMccjuXysaugB5WUwPWU6kD/jfWBUXE4i7Q8VFVG3aLlhF3xvIuOjBTP9xRJxOwQTIGsdUkX7oMOUJ9VRR05H3YeEe8EinvREFShbHBTYehMb/lMe1A+ORMNBZPRgXvprys8ZKS+y4iah7BoxRWkZsiPB9gkzP6yogwkWmtYDejjKvEwv8QjcIlnAUHnGxKiR7Pzlcpz6mAxMKX5h8t4ENgidgF9fnvwoqH/w 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)(39860400002)(396003)(136003)(346002)(366004)(376002)(2906002)(8936002)(52116002)(6506007)(4326008)(83380400001)(38350700002)(38100700002)(2616005)(66946007)(66476007)(66556008)(6666004)(956004)(8676002)(6512007)(16526019)(5660300002)(316002)(36756003)(478600001)(86362001)(186003)(6486002)(26005)(69590400013); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: Ou4GnuGWf6+2eUaxhKM0ISQLsAZ9THnTFH9VPz58n+hYpvfgBXQiKop8SYTLu8fGcirRaCZEBHyiMJxs7Y4WuH83uE6QwGgDgk5S80w1DO/PHOKoZBqciwy/2lgvymTGtThWt8AiHa5cRm7IVQHFVsL9fsF1bjLaNu+z4vgjQKyKFUJbIfEjLXb9WgnlVrlGRRcoOm+/jxwXHap+lSg+IOg4eqit8+VFU/S/to31UYTWV3agWmVOms9jGLwR7qOx9ehhkMsPS4Pf9fcl0Nhl7sDk19QmZyRr7Yf+Mtyof/j+63BkkCaCS+sOLF/fPWVRhlV4dTavQOB5Y1sJ+UHOQop1Qh7QoW5ZuZQSAiMD2K3jOgxIUW6BO6D3fmVPPYbmuqzuR47/Cvu6KsFfLJ9XcTTNZq/BeUu+wQfRtJBqNez4WDUjiWj3vCbU1DltKEzWl0fnCcSFntUHS83UJY4RCTCTMDW3iCas/tupNJNt4OkDT4JG4KRnnUwTq8k7F2OL82PKwiJx4kx2x/Ul56wcqNIu7hq0HYc7vHXFy9VoCDCVQAxTbRSs9xC6zYCpOOoLpUxvbyRZu1nDltLljvDDgB4qG/ZVIgJUE9Po+fXAYrnVSD1dhpkt5Bdkl+sQlw1mUnn0I3Q9LP+iY1X11tuYieT3bRBgrUMXizx9YsA61QPW8VrCuSUFJneoFLB6H9yOo65F4aIhmTyFnbGEB/hJjsg8i562CDH7KxpGC+4RfOQ9HC+T/o6oQ91YscJvc4Y5Z7BQsOpfO+fJqIYioAZelfYiVmoS5xzYeYEFh60xERmw7o6u/HlpskL42VdIgRWJgVJxwv9GRmY/rSYeGsD3J3gU0Sw8z2nLMg3zqnt0f7VCpoRba/dI5NMap1YlYT/0HFA6ZmhxazQzej9sSC8vavewmIhhnp7Pu1MUYrwUwcnSkiJRbhEEfnLiLi1hfbMTBwvFa17V8y+RuRj94Vwf4+ct3vUw5Fh9o20BfXJsklrO6/YjkLyY2mviDEJ5LdkYwtpkUC2Qy/kJVprMrWFCsl3854ZWkV1l169r5FR7zaaDH1tTCatPsIDwpuAlx+KZTxoC3+PE34N/9EhpomuBbYjKLOeE463pOXkg2xAJvHdz3J3pRpd8iQv1m7pT2x0AURgZvSc0WDo3qmL7RkdIsOvSjaH0aB9sll3/E5rAYZQAXuXmerjhLV9YH7SS7sXh+IDGFMrZWsu8At4iyM3zEv6hND5diNyvAXSuqHahIl1vtCoxnlpoTOv4aP7BNlpUMYf13mzD9/ZjGRx9PB5EDHAcIFFP8/rQqr3Vp1t/HqX4zuzY98eFF4eOi02K1nK8 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6022c9b8-cb6a-4e80-bf40-08d911e52a60 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5935.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 May 2021 05:50:20.9650 (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: WauZpzpafsRWQvaRSXw3WRDrzHRTGGJFyMb9oaYGGWdSNEyOtNcKb2JJgiEyldmv X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2557 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 v4: - Add missing usb_free_urb() to balance refcount to be 0. 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 | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index d7eb9f179ca6..0f8b7c93310e 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -2159,16 +2159,12 @@ 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); + usb_free_urb(urb); + return NULL; + } + urb->context = done; return urb; }