Message ID | 20231020140655.v5.1.I6e4fb5ae61b4c6ab32058cb12228fd5bd32da676@changeid |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp1325358vqb; Fri, 20 Oct 2023 14:08:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYQcq/TyEdyQ9TcyIRw07GJJDy0Ewbou3RlnsKlExRc/B3JmtBXT2J84SDaFh8u0/nSkdu X-Received: by 2002:a05:6e02:1d96:b0:351:526a:4bc with SMTP id h22-20020a056e021d9600b00351526a04bcmr4107050ila.15.1697836111186; Fri, 20 Oct 2023 14:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697836111; cv=none; d=google.com; s=arc-20160816; b=BMjBfb0s+7u2bUEWKPUGv/z40kVEydHx4GHl72jMXseeA6OIE719tB322GOGtDAr3Z 5qTZWrlFj8UmHvrNgKLGOfOIO7oYPHStboQNMjSxMpCO9upfrmgjJbJscAdJaZ0sW7xb MVx7vTR+jYpOlnoqHjd+PXCWcL1RXSxGOrGhS1+mr+gt1DghHo9dEY0p56WlnhMFPzTB 9O75gkS60mHFOREr6uCSU3g1Mrtb5K1G7atZ1y0YpUj5ygJ0r1MBC6t8rMIYIu3ogAoU 9eOMMEFcbFP6XfY5SNkLrqDVmT1jzGhZgvU/wLDly7U1ZJnyjhHWBIgPr2RneTQmjky8 B9hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=99XDTyUCvOUhQUp0MWN4ekbCgPLwBk+829H/gHSUoe4=; fh=zTr+uH2kSs/oKblpwigKoDAJbZw82uLZilNO8W1q+qc=; b=Q3YdiHKu3f3qeg8EatcpxH72U/KGSVEdlvzOrJoCMY1rNu9l6BlZhPcjkmOUmT6So1 NWMFkMg1snu/XN13IB1BvwlH5rdOGunixfOnmU/swziRuizcAxoZ+yZLvSzqKKoiERzi x/VF2g30lrhxybApiCg95P69dSmyvtDiz2bF0BNpwO370GF86IYLJZ4CNm/fSbOhKsmO URuxYkt5rDvh5p2CXUKydZALfm2fRfExzSXsvc3EocCJxdmt9GXH68/iZhdufgdhlTwy WsE+ERdlB24M0Jf9mVPWIK4izwnBx99OvzjTKhla2z4ArhfSq+NgoQ2AGAkTgdUEbvLd c4xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=l++ihJie; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id r15-20020a632b0f000000b005b7e3ee181fsi2498535pgr.642.2023.10.20.14.08.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 14:08:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=l++ihJie; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id C302B82B42F4; Fri, 20 Oct 2023 14:08:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231625AbjJTVIP (ORCPT <rfc822;a1648639935@gmail.com> + 26 others); Fri, 20 Oct 2023 17:08:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231288AbjJTVIO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 20 Oct 2023 17:08:14 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D6E3D70 for <linux-kernel@vger.kernel.org>; Fri, 20 Oct 2023 14:08:12 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6be1bc5aa1cso1190160b3a.3 for <linux-kernel@vger.kernel.org>; Fri, 20 Oct 2023 14:08:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697836092; x=1698440892; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=99XDTyUCvOUhQUp0MWN4ekbCgPLwBk+829H/gHSUoe4=; b=l++ihJieNoy2NHFRNriaVLflw6AB/L1XBBboft2BObY5YA6vlOKya89SzkA/PiNAjY wnnfJkVl8PwEs0SMLh1hnOAkRDjAVdKK6ClYDB9brBne42ZuBcTNry59JUSxHmfTNavA CvC8Sx21xeLXU8gKEACoswf8NN+MEWHoQKjM0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697836092; x=1698440892; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=99XDTyUCvOUhQUp0MWN4ekbCgPLwBk+829H/gHSUoe4=; b=t5nYZT9zNRiUa787zyJdelWQFKcbvPGz8u3v/NC0p5nWH/+Qo8PQf/dGnCbKvW/ChQ gmhqGTZQNE6jQk7evwN7/7gDp8SUPZgwLNze/vURcRYuw2vMPIbF8I3InHD1HH4BAtkV M19kupuArv2AjZL7rn81+S3tyvt3srYY0uyGLPUDECWjgcRVFNjt4myebdxoeoelgTiC CTK54w/7LzUFVDcMELYY+4mApsXUXbHvrxSmNrMlAyVRaH4H1PvjumBSiqx06zHfMZUA f22p1noQL0BW5h6FyZTqcmoXeZyr84o1lruB1BL7zbx2KWr0JLEmR1GeNTuDm5diJ30t GPWA== X-Gm-Message-State: AOJu0YypAO3KUIKWlmLmC2+DEwqMhRQ40ui6ePcQCRSXCg93J+rCWHxi NKhupk69BU2wOIqv/SM2LPuNGw== X-Received: by 2002:a05:6a00:b4f:b0:6be:2081:f66d with SMTP id p15-20020a056a000b4f00b006be2081f66dmr3132834pfo.27.1697836091742; Fri, 20 Oct 2023 14:08:11 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:c078:ee4f:479f:8486]) by smtp.gmail.com with ESMTPSA id w14-20020aa7954e000000b00686b649cdd0sm1969278pfq.86.2023.10.20.14.08.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 14:08:11 -0700 (PDT) From: Douglas Anderson <dianders@chromium.org> To: Jakub Kicinski <kuba@kernel.org>, Hayes Wang <hayeswang@realtek.com>, "David S . Miller" <davem@davemloft.net> Cc: Edward Hill <ecgh@chromium.org>, Laura Nao <laura.nao@collabora.com>, Alan Stern <stern@rowland.harvard.edu>, Simon Horman <horms@kernel.org>, linux-usb@vger.kernel.org, Grant Grundler <grundler@chromium.org>, Douglas Anderson <dianders@chromium.org>, =?utf-8?q?Bj=C3=B8rn_Mork?= <bjorn@mork.no>, Eric Dumazet <edumazet@google.com>, Paolo Abeni <pabeni@redhat.com>, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v5 1/8] r8152: Increase USB control msg timeout to 5000ms as per spec Date: Fri, 20 Oct 2023 14:06:52 -0700 Message-ID: <20231020140655.v5.1.I6e4fb5ae61b4c6ab32058cb12228fd5bd32da676@changeid> X-Mailer: git-send-email 2.42.0.758.gaed0368e0e-goog In-Reply-To: <20231020210751.3415723-1-dianders@chromium.org> References: <20231020210751.3415723-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 20 Oct 2023 14:08:26 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780310197899706316 X-GMAIL-MSGID: 1780310197899706316 |
Series |
r8152: Avoid writing garbage to the adapter's registers
|
|
Commit Message
Doug Anderson
Oct. 20, 2023, 9:06 p.m. UTC
According to the comment next to USB_CTRL_GET_TIMEOUT and
USB_CTRL_SET_TIMEOUT, although sending/receiving control messages is
usually quite fast, the spec allows them to take up to 5 seconds.
Let's increase the timeout in the Realtek driver from 500ms to 5000ms
(using the #defines) to account for this.
This is not just a theoretical change. The need for the longer timeout
was seen in testing. Specifically, if you drop a sc7180-trogdor based
Chromebook into the kdb debugger and then "go" again after sitting in
the debugger for a while, the next USB control message takes a long
time. Out of ~40 tests the slowest USB control message was 4.5
seconds.
While dropping into kdb is not exactly an end-user scenario, the above
is similar to what could happen due to an temporary interrupt storm,
what could happen if there was a host controller (HW or SW) issue, or
what could happen if the Realtek device got into a confused state and
needed time to recover.
This change is fairly critical since the r8152 driver in Linux doesn't
expect register reads/writes (which are backed by USB control
messages) to fail.
Fixes: ac718b69301c ("net/usb: new driver for RTL8152")
Suggested-by: Hayes Wang <hayeswang@realtek.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
(no changes since v1)
drivers/net/usb/r8152.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
Comments
On Fri, Oct 20, 2023 at 2:08 PM Douglas Anderson <dianders@chromium.org> wrote: > > According to the comment next to USB_CTRL_GET_TIMEOUT and > USB_CTRL_SET_TIMEOUT, although sending/receiving control messages is > usually quite fast, the spec allows them to take up to 5 seconds. > Let's increase the timeout in the Realtek driver from 500ms to 5000ms > (using the #defines) to account for this. > > This is not just a theoretical change. The need for the longer timeout > was seen in testing. Specifically, if you drop a sc7180-trogdor based > Chromebook into the kdb debugger and then "go" again after sitting in > the debugger for a while, the next USB control message takes a long > time. Out of ~40 tests the slowest USB control message was 4.5 > seconds. > > While dropping into kdb is not exactly an end-user scenario, the above > is similar to what could happen due to an temporary interrupt storm, > what could happen if there was a host controller (HW or SW) issue, or > what could happen if the Realtek device got into a confused state and > needed time to recover. > > This change is fairly critical since the r8152 driver in Linux doesn't > expect register reads/writes (which are backed by USB control > messages) to fail. > > Fixes: ac718b69301c ("net/usb: new driver for RTL8152") > Suggested-by: Hayes Wang <hayeswang@realtek.com> > Signed-off-by: Douglas Anderson <dianders@chromium.org> Reviewed-by: Grant Grundler <grundler@chromium.org> > --- > > (no changes since v1) > > drivers/net/usb/r8152.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c > index 0c13d9950cd8..482957beae66 100644 > --- a/drivers/net/usb/r8152.c > +++ b/drivers/net/usb/r8152.c > @@ -1212,7 +1212,7 @@ int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) > > ret = usb_control_msg(tp->udev, tp->pipe_ctrl_in, > RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, > - value, index, tmp, size, 500); > + value, index, tmp, size, USB_CTRL_GET_TIMEOUT); > if (ret < 0) > memset(data, 0xff, size); > else > @@ -1235,7 +1235,7 @@ int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) > > ret = usb_control_msg(tp->udev, tp->pipe_ctrl_out, > RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE, > - value, index, tmp, size, 500); > + value, index, tmp, size, USB_CTRL_SET_TIMEOUT); > > kfree(tmp); > > @@ -9494,7 +9494,8 @@ static u8 __rtl_get_hw_ver(struct usb_device *udev) > > ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), > RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, > - PLA_TCR0, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500); > + PLA_TCR0, MCU_TYPE_PLA, tmp, sizeof(*tmp), > + USB_CTRL_GET_TIMEOUT); > if (ret > 0) > ocp_data = (__le32_to_cpu(*tmp) >> 16) & VERSION_MASK; > > -- > 2.42.0.758.gaed0368e0e-goog >
On 10/20/2023 2:06 PM, Douglas Anderson wrote: > According to the comment next to USB_CTRL_GET_TIMEOUT and > USB_CTRL_SET_TIMEOUT, although sending/receiving control messages is > usually quite fast, the spec allows them to take up to 5 seconds. > Let's increase the timeout in the Realtek driver from 500ms to 5000ms > (using the #defines) to account for this. > > This is not just a theoretical change. The need for the longer timeout > was seen in testing. Specifically, if you drop a sc7180-trogdor based > Chromebook into the kdb debugger and then "go" again after sitting in > the debugger for a while, the next USB control message takes a long > time. Out of ~40 tests the slowest USB control message was 4.5 > seconds. > > While dropping into kdb is not exactly an end-user scenario, the above > is similar to what could happen due to an temporary interrupt storm, > what could happen if there was a host controller (HW or SW) issue, or > what could happen if the Realtek device got into a confused state and > needed time to recover. > > This change is fairly critical since the r8152 driver in Linux doesn't > expect register reads/writes (which are backed by USB control > messages) to fail. > > Fixes: ac718b69301c ("net/usb: new driver for RTL8152") > Suggested-by: Hayes Wang <hayeswang@realtek.com> > Signed-off-by: Douglas Anderson <dianders@chromium.org> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 0c13d9950cd8..482957beae66 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -1212,7 +1212,7 @@ int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) ret = usb_control_msg(tp->udev, tp->pipe_ctrl_in, RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, - value, index, tmp, size, 500); + value, index, tmp, size, USB_CTRL_GET_TIMEOUT); if (ret < 0) memset(data, 0xff, size); else @@ -1235,7 +1235,7 @@ int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) ret = usb_control_msg(tp->udev, tp->pipe_ctrl_out, RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE, - value, index, tmp, size, 500); + value, index, tmp, size, USB_CTRL_SET_TIMEOUT); kfree(tmp); @@ -9494,7 +9494,8 @@ static u8 __rtl_get_hw_ver(struct usb_device *udev) ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, - PLA_TCR0, MCU_TYPE_PLA, tmp, sizeof(*tmp), 500); + PLA_TCR0, MCU_TYPE_PLA, tmp, sizeof(*tmp), + USB_CTRL_GET_TIMEOUT); if (ret > 0) ocp_data = (__le32_to_cpu(*tmp) >> 16) & VERSION_MASK;