From patchwork Sun Aug 26 03:45:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Terin Stock X-Patchwork-Id: 10576247 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B024E920 for ; Sun, 26 Aug 2018 03:45:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9732B293B8 for ; Sun, 26 Aug 2018 03:45:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 856922954D; Sun, 26 Aug 2018 03:45:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C464293B8 for ; Sun, 26 Aug 2018 03:45:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726224AbeHZH0n (ORCPT ); Sun, 26 Aug 2018 03:26:43 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43277 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbeHZH0n (ORCPT ); Sun, 26 Aug 2018 03:26:43 -0400 Received: by mail-pl1-f194.google.com with SMTP id x6-v6so2672848plv.10 for ; Sat, 25 Aug 2018 20:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=terinstock-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:user-agent:user-agent :mime-version:content-transfer-encoding; bh=6agb8KVaiKKpUSlWJAHiq4CBpytt7+l9kpQHejX0aC4=; b=ZXcaZriXROSSyybaYklH36rb+xbYqcMVv9ViJkP5UJumEJQj17L2Kq9bd383rqVjfA amVlHbjxp/BC2rJX6KDV7EjqLopO9Nvh+3RrxXnNqB4jxE7D0EMDg8nDpP+e/FmxKESu KCBj66DHJZGb+41jznI7bZL3VT9jp/tBHC3780gmuwAC+8Ipn3qqFcMRzRUyNnlace2E 8ckWi4xDiPL3rvNCJK1QhLy6y1cao9NJhH6tYanmlWy96pIkoYFJjLdRJuPGjB7ldcU1 bUw0Xfoqf6fWTiOYAIQYSM3Uzl2SRwrLYlEJyNB9mNDNRlQA9E/hEbNc9s1fcntI+QQJ KoWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :user-agent:mime-version:content-transfer-encoding; bh=6agb8KVaiKKpUSlWJAHiq4CBpytt7+l9kpQHejX0aC4=; b=MysqKkKTrvpqGV/Mr3ig4k5c255br/77AhHtWk1a7vohNS31P+CI27my9wuSAB6299 HK8pRgKTrPb8Iosw7ES4l1e00ttUZDMw8zFMK2tT9nPZGA0UkfITjepqPwqHWBHP9s1R UWX7Diw8arWCNdkXpXMbeuc7qKZS+eI880y1Y4s895K/dqfMdF4v5DgESHV5iXbeVPph x+qJr7Fr4Z6Z3MTMGaA4B7x1lhtj6OZkJ0qaIMssTGAOHJHgL9b45u5FNnNCxZ5MzvxE wjATXov8sIasxuFUZggO2f1u22+1G2agcRKLtw4gaRWCfAsNmaGEmac6qzjvlwnNFeoz 6I9g== X-Gm-Message-State: APzg51C0ekObnug7+7y6lgIqK8bkdrtAWo/PiDJy6rLazl4G7Ym5bYJ5 zlFA8L6KgJCBnz50tJ6cEl0mDskQH7wl X-Google-Smtp-Source: ANB0VdaLv+hsTihVRHOonYfX7SDEPxKJIt0MSbrX8ynPYLGIxjxY27rTARTgAzYWUyeFIoztFXncwA== X-Received: by 2002:a17:902:7b83:: with SMTP id w3-v6mr7786880pll.192.1535255135847; Sat, 25 Aug 2018 20:45:35 -0700 (PDT) Received: from rincon.localdomain ([136.24.13.23]) by smtp.gmail.com with ESMTPSA id p26-v6sm20433237pfi.183.2018.08.25.20.45.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 25 Aug 2018 20:45:34 -0700 (PDT) Date: Sat, 25 Aug 2018 20:45:34 -0700 From: Terin Stock To: linux-usb@vger.kernel.org Cc: dianders@chromium.org, jwerner@chromium.org, dtor@chromium.org Subject: [PATCH] usb: dwc2: host: use hrtimer for NAK retries Message-ID: <153525513399.26461.366517296951223355.stgit@Rincon.localdomain> User-Agent: mail v14.9.10 User-Agent: StGit/unknown-version MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Upon upgrading a Raspberry Pi 3B-based project from vanilla 4.14, attempts to mount a floppy disk in a generic USB floppy drive would hang until the floppy drive was removed from the system. Tracing shows that during mounting the drive produces a large amount of NAKed transactions, but would eventually continue. A previous commit added a retry delay on NAKed transactions, using jiffies, that results in indefinite NAKs in this scenario. Modify the wait delay utilize the high resolution timer API to allow for more accurately scheduled callbacks. Fixes: 38d2b5fb75c1 ("usb: dwc2: host: Don't retry NAKed transactions right away") Signed-off-by: Terin Stock --- drivers/usb/dwc2/hcd.h | 2 +- drivers/usb/dwc2/hcd_queue.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/usb/dwc2/hcd.h b/drivers/usb/dwc2/hcd.h index 5502a501f516..93483dc37801 100644 --- a/drivers/usb/dwc2/hcd.h +++ b/drivers/usb/dwc2/hcd.h @@ -366,7 +366,7 @@ struct dwc2_qh { u32 desc_list_sz; u32 *n_bytes; struct timer_list unreserve_timer; - struct timer_list wait_timer; + struct hrtimer wait_timer; struct dwc2_tt *dwc_tt; int ttport; unsigned tt_buffer_dirty:1; diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c index 301ced1618f8..2d0cfd7f2cfe 100644 --- a/drivers/usb/dwc2/hcd_queue.c +++ b/drivers/usb/dwc2/hcd_queue.c @@ -59,7 +59,7 @@ #define DWC2_UNRESERVE_DELAY (msecs_to_jiffies(5)) /* If we get a NAK, wait this long before retrying */ -#define DWC2_RETRY_WAIT_DELAY (msecs_to_jiffies(1)) +#define DWC2_RETRY_WAIT_DELAY 1*1E6L /** * dwc2_periodic_channel_available() - Checks that a channel is available for a @@ -1465,9 +1465,9 @@ static void dwc2_deschedule_periodic(struct dwc2_hsotg *hsotg, * * @t: Pointer to wait_timer in a qh. */ -static void dwc2_wait_timer_fn(struct timer_list *t) +static enum hrtimer_restart dwc2_wait_timer_fn(struct hrtimer *t) { - struct dwc2_qh *qh = from_timer(qh, t, wait_timer); + struct dwc2_qh *qh = container_of(t, struct dwc2_qh, wait_timer); struct dwc2_hsotg *hsotg = qh->hsotg; unsigned long flags; @@ -1491,6 +1491,7 @@ static void dwc2_wait_timer_fn(struct timer_list *t) } spin_unlock_irqrestore(&hsotg->lock, flags); + return HRTIMER_NORESTART; } /** @@ -1521,7 +1522,8 @@ static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, /* Initialize QH */ qh->hsotg = hsotg; timer_setup(&qh->unreserve_timer, dwc2_unreserve_timer_fn, 0); - timer_setup(&qh->wait_timer, dwc2_wait_timer_fn, 0); + hrtimer_init(&qh->wait_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); + qh->wait_timer.function = &dwc2_wait_timer_fn; qh->ep_type = ep_type; qh->ep_is_in = ep_is_in; @@ -1690,7 +1692,7 @@ void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) * won't do anything anyway, but we want it to finish before we free * memory. */ - del_timer_sync(&qh->wait_timer); + hrtimer_cancel(&qh->wait_timer); dwc2_host_put_tt_info(hsotg, qh->dwc_tt); @@ -1716,6 +1718,7 @@ int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) { int status; u32 intr_mask; + ktime_t delay; if (dbg_qh(qh)) dev_vdbg(hsotg->dev, "%s()\n", __func__); @@ -1734,8 +1737,8 @@ int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) list_add_tail(&qh->qh_list_entry, &hsotg->non_periodic_sched_waiting); qh->wait_timer_cancel = false; - mod_timer(&qh->wait_timer, - jiffies + DWC2_RETRY_WAIT_DELAY + 1); + delay = ktime_set(0, DWC2_RETRY_WAIT_DELAY); + hrtimer_start(&qh->wait_timer, delay, HRTIMER_MODE_REL); } else { list_add_tail(&qh->qh_list_entry, &hsotg->non_periodic_sched_inactive);