From patchwork Thu Oct 12 19:25:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 152131 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1455253vqb; Thu, 12 Oct 2023 12:31:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEdNFxX6WGa5prODyG71yM8lFtd9ynodRSN/qwMtd84URZcyPRp/DZ6flNzGmyolbwflBF4 X-Received: by 2002:a05:6602:360e:b0:79a:c487:2711 with SMTP id bc14-20020a056602360e00b0079ac4872711mr24549366iob.0.1697139110547; Thu, 12 Oct 2023 12:31:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697139110; cv=none; d=google.com; s=arc-20160816; b=q8wGqIbY/T2Cb6R7Q9MMpnBNh/AzkNLta0buYB+UQKfkxhg2ZT4eoWuUWF0Pjwx+z1 teIqqCfrFp3WoN2upQnATVc3RiNsWWr4X4yjO/4YBCTDfMWIxdBQkhRNYqfCpqClcvug MXisaLpmvJHcVBeDVfeHF8DdCAv2gmGd8FChpcXfBIyhP9UNOMPAdD/9WeOA4kfdT22V GMhqg8dyLGH4t5vL/+XrqoQ3AlqdjqurYkjCdZNU3YOkUaBw7cjPx3M4OIOS/+Lk5oI1 oIEAaWmO0tYat/YX6PtzLYlXVDAGxgI+A18bjsMEw3AxKng+OiGBuEV5bRpHmJjDmRZB xkYg== 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=NbvzQqP0LAVibFSc2uogz4x5ZKRmyFttXMYHpoYS+M4=; fh=B0Kr+W4P+gDWCh4uaZww8C7+cggdkGoCsVYEV5mipv8=; b=JbxtoPWA4VdNpxfjMnHKFIS+6eO95ff9Ocmn7Bh1VrEjBbggUeFAvMMvxG1Gr62NHU zMpyfzMXEVDuE1puwNUSgZgNH2B2iYtpNpWd0rk+S9oLKZu8JFKcbrwhgJvN9dezgEww tugQLme3CgnAWPnBFewkkpp6OpWLMPyGDT4OW2mVBB3OMtGUTTYgVb9BdVQctuamzfVI 2TzEOZSg9R0qEdfH2+ORpmi/kO4MbHR2//EBF6Hu59uBwX2wBOuLklYdjPioud/Uuqt2 1O2gE1EYSDLBm+VcL0junDzI0L54M7ZioTj5xqwFFld9OTf5fD9NKopc4NOLaWd4g8bT 8j/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZKyBR9cU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id q2-20020a63f942000000b005775a0cd009si2920313pgk.331.2023.10.12.12.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:31:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZKyBR9cU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id BDF7180A32DA; Thu, 12 Oct 2023 12:30:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442186AbjJLTa2 (ORCPT + 19 others); Thu, 12 Oct 2023 15:30:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442170AbjJLTaW (ORCPT ); Thu, 12 Oct 2023 15:30:22 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F549CC for ; Thu, 12 Oct 2023 12:30:18 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-690d8c05784so1130112b3a.2 for ; Thu, 12 Oct 2023 12:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697139018; x=1697743818; 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=NbvzQqP0LAVibFSc2uogz4x5ZKRmyFttXMYHpoYS+M4=; b=ZKyBR9cUkEwA/LMbDou152prn3jqubQEGGjLUARcLLnm0F8vWYtVANBYVDiLdrH8kG wCV+DLkaWoxHy22+6i+Bb9rILNZ5hv1WD+JfwFf8IYmoRpWTjBvGEHIFFTCjYKxy7eaR BGLxcG6cYjXPbEmAW6PKG1gByySvPV2cmro6k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697139018; x=1697743818; 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=NbvzQqP0LAVibFSc2uogz4x5ZKRmyFttXMYHpoYS+M4=; b=a9ffIPEvDbJwnoGDqwvkJtczykBRS0o9oTKS5l6mJV0dUrL1BiOAke8VQ4I60B/RYm 9hSEJkku7gPuLDR7MRzUvNuO2HirPez1eNMapM8XOBEdlVYVz99d+xoVeRHc4BJNAOga 8ZillrYTZHX/IBT8LzTjZVwgKaBufgqABTLQ8m/87eARPYo8MLqreh4lsV3i5O2793im /eYMraHNKuJudlVesikkytLDvcH2HCUb7P2I7zf64pHOGPI5bFWp80DPv7Gy6Oo0VU8w cN/yTeYTSsPMN94Jj2UZA2qmomI5nwV/0E9fEt620TnEe7+JO4aRnxVB9L5Fiex2fwbk 2OWg== X-Gm-Message-State: AOJu0Yy4Sly3Xr9vDn/scLq4TBMzfweb5KStn7G80nEw33OhSQU5A31Y DvY5BhIlU1RAi6pVrn9CC6Sevw== X-Received: by 2002:a05:6a21:789c:b0:14b:8b82:867f with SMTP id bf28-20020a056a21789c00b0014b8b82867fmr26000299pzc.50.1697139017857; Thu, 12 Oct 2023 12:30:17 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:7c85:4a99:f03e:6f30]) by smtp.gmail.com with ESMTPSA id b3-20020a639303000000b0057c25885fcfsm2075720pge.10.2023.10.12.12.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:30:17 -0700 (PDT) From: Douglas Anderson To: Jakub Kicinski , Hayes Wang , "David S . Miller" Cc: Alan Stern , Simon Horman , Edward Hill , Laura Nao , linux-usb@vger.kernel.org, Grant Grundler , Douglas Anderson , =?utf-8?q?Bj=C3=B8rn_Mork?= , Eric Dumazet , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 1/5] r8152: Increase USB control msg timeout to 5000ms as per spec Date: Thu, 12 Oct 2023 12:25:00 -0700 Message-ID: <20231012122458.v3.1.I6e4fb5ae61b4c6ab32058cb12228fd5bd32da676@changeid> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231012192552.3900360-1-dianders@chromium.org> References: <20231012192552.3900360-1-dianders@chromium.org> MIME-Version: 1.0 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 agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:30:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779579340056616606 X-GMAIL-MSGID: 1779579340056616606 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 Signed-off-by: Douglas Anderson --- (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; From patchwork Thu Oct 12 19:25:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 152127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1454836vqb; Thu, 12 Oct 2023 12:31:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF4EmxM6bmtx/fASCek/EfVfDWC+xxWaNOU06t8bfJVmgdyINxvZ/1DhHOtlVzrnJ2iF8mv X-Received: by 2002:a05:6a20:9393:b0:16c:b95c:6d38 with SMTP id x19-20020a056a20939300b0016cb95c6d38mr17906392pzh.2.1697139066980; Thu, 12 Oct 2023 12:31:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697139066; cv=none; d=google.com; s=arc-20160816; b=fvnDLMU+HE/L+T/DtSw601BWgYuJWhWWDE3vo9DuouExkwchf8Hz3M7XxTXXiMfxqt V15tpP5aB2zEvEmYyLxt6vpyrsgZboQI4RWMvjIW+iYlWRZuFC3DVgzTAgzbqfuJQ8nd UlgECxpwAu0U2DKl6paZAVfa3VhJjQ4PGhI/0vV5+UzDqptF+j+ur1mphCY7OvBBul2Q K/UyOk0sYdSEE9wPyCpOu83TQskB9IcCe9KEZLAG08TP3VcUDD8yOLVxAM4dqNaH/MlE UoGlXkwmNAKB4QSJe9j5M8PTUjcR9VEiTz/6I92IRq1Ay58KJ+K7sbvUc8q+kwVK3sRB 27qg== 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=5zajPA0tvu72pt5bpzc8dJBpNP+YUOKi2eBcYHy9Hcw=; fh=B0Kr+W4P+gDWCh4uaZww8C7+cggdkGoCsVYEV5mipv8=; b=weUEJKw7K+PhEwzsAbBri/wMYPHevlSDtbbwe8BJTvGZlT17OCfPHWDprnn9bEckt1 de+0rx+vZt8ipi2Ss0zv31ckeCk7wZ/zViO5EfzBEwj2YtrH17OkGjc/XbxRT0Ht4xkn UxROtXrqgLwdo6zisl8GmNUwuNOoyFohytZsCqWFKS+8PRI4hWKuJnpecEC8bphEa40Q y4X22pKg8bwi6mokGROEEMuX3dQcRRhvCqaA6VXASC+b0/yvRIFRCEq4lwYYAQbpXcV1 QM70a65M2LycfTfLFsp35PoWRQPBTpyz7fN9FnBjL2k6blVzzC3AnhpfN4MXK0IjRHlf 3/3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Si8r9BfD; 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 l12-20020a17090aec0c00b0027d0b9c0b90si2739452pjy.153.2023.10.12.12.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:31:06 -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=Si8r9BfD; 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 6DA29808E667; Thu, 12 Oct 2023 12:30:44 -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 S1442181AbjJLTaY (ORCPT + 19 others); Thu, 12 Oct 2023 15:30:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1441868AbjJLTaV (ORCPT ); Thu, 12 Oct 2023 15:30:21 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47CC8B7 for ; Thu, 12 Oct 2023 12:30:20 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-690bccb0d8aso1153077b3a.0 for ; Thu, 12 Oct 2023 12:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697139020; x=1697743820; 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=5zajPA0tvu72pt5bpzc8dJBpNP+YUOKi2eBcYHy9Hcw=; b=Si8r9BfDBfRo/07TbOXurfEXpVpk2YVQaEi60b/Lj35WBoQdbwBuUobcM0M7rBFdlL sMM4fyZVD+slnoSxaOzShM1AcItMD/fSw614qhQ909HzAtyDgrSzSLHJ53hXjjsb79Rt Te7FbWESWFO1+nLSINfB/pCqI2mjvVa+s/SRc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697139020; x=1697743820; 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=5zajPA0tvu72pt5bpzc8dJBpNP+YUOKi2eBcYHy9Hcw=; b=Fyu7CQilhRzg+1OLgtlYfu8+0Itiowda6cl5TkCCbaUVvP4lgpEM4oTCVLu4hsUbhC mH5hex19sHcROAaTiWuGhlnJ1mjjzR5R4jSzdk+i9zdO77qwBwh3vdZu2Ux7Hxpojq4M 8Stl3srJm6Xfd4D7OhLsXhL5WGLNeyugl2ptWSyxCdoQdOV+rtS+2lknSnba8NdmIokC 3wqu6dO3ulmUl58YXwRSa/6EGJZKi5KbqSIn/RvgHYkxF4ntGU8OBP3iYrdf5Zm2esgW S9hP6iNpJo9M8S48G/wM+IKIJP1MZVcEOBxv77kLZtKP2IYPhTP6TBY9VBPxTl0xRDmW iRzw== X-Gm-Message-State: AOJu0YxrFzsvG8aMKFPRhVoPuMXqMZz0iwvwIcB1A946Ny7GWtWduiP+ E3pCTvnB4a7LxZRhc5PtttpoJw== X-Received: by 2002:a05:6a20:6a23:b0:13e:9dba:ea52 with SMTP id p35-20020a056a206a2300b0013e9dbaea52mr27470979pzk.13.1697139019812; Thu, 12 Oct 2023 12:30:19 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:7c85:4a99:f03e:6f30]) by smtp.gmail.com with ESMTPSA id b3-20020a639303000000b0057c25885fcfsm2075720pge.10.2023.10.12.12.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:30:19 -0700 (PDT) From: Douglas Anderson To: Jakub Kicinski , Hayes Wang , "David S . Miller" Cc: Alan Stern , Simon Horman , Edward Hill , Laura Nao , linux-usb@vger.kernel.org, Grant Grundler , Douglas Anderson , =?utf-8?q?Bj=C3=B8rn_Mork?= , Eric Dumazet , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 2/5] r8152: Check for unplug in rtl_phy_patch_request() Date: Thu, 12 Oct 2023 12:25:01 -0700 Message-ID: <20231012122458.v3.2.I300ed6c3269c77756bdd10dd0d6f97db85470186@changeid> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231012192552.3900360-1-dianders@chromium.org> References: <20231012192552.3900360-1-dianders@chromium.org> MIME-Version: 1.0 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: 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]); Thu, 12 Oct 2023 12:30:44 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779579294227625262 X-GMAIL-MSGID: 1779579294227625262 If the adapter is unplugged while we're looping in rtl_phy_patch_request() we could end up looping for 10 seconds (2 ms * 5000 loops). Add code similar to what's done in other places in the driver to check for unplug and bail. Signed-off-by: Douglas Anderson --- (no changes since v2) Changes in v2: - ("Check for unplug in rtl_phy_patch_request()") new for v2. drivers/net/usb/r8152.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 482957beae66..fff2f9e67b5f 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -4046,6 +4046,9 @@ static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait) for (i = 0; wait && i < 5000; i++) { u32 ocp_data; + if (test_bit(RTL8152_UNPLUG, &tp->flags)) + break; + usleep_range(1000, 2000); ocp_data = ocp_reg_read(tp, OCP_PHY_PATCH_STAT); if ((ocp_data & PATCH_READY) ^ check) From patchwork Thu Oct 12 19:25:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 152128 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1454837vqb; Thu, 12 Oct 2023 12:31:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMYIFA1Q/pNImdHfyKGkCAAIvVlPriPB6de4fSxRpDpRia8e7gSFPFhc+3wy+BxgIYgg9x X-Received: by 2002:a17:90a:2dc5:b0:27c:e2d5:abb6 with SMTP id q5-20020a17090a2dc500b0027ce2d5abb6mr8715355pjm.0.1697139067157; Thu, 12 Oct 2023 12:31:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697139067; cv=none; d=google.com; s=arc-20160816; b=MYDAVurewvt8MtGiD8Dh6sAxuDqqGiyva3SLuyR6e1kNsPYnXTJkAF8dbPbFVz2Gsm IFM1ZpPrwRVb7ntaBFGSDizdTGo3ck/jjfQCBMDF3Nv5Y1WxM75QS0ylvDyzmkBrd7Qn ZmeDl1v4UMTRmvv6FOL9Jt8bq/K3Jid6p9z637zN2kwftE3VpDbZMR3s9rwfaqUzksk+ 3kq5P7n9G1Mt7vqpZFG35ha+245xAgSuxF3QSk1LMc2MsPju+YtNSKeRBJJAwCRHuVZw xsqhVNkMAKOYXl5ZSweabL3JZ5LeOtsr52EIzB2xr8F/DShcmlOkXdem0CglCi+y7Ooo V/bQ== 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=wIBdQHfHPM91+b5JonQNYSwOG95FePEogJzP0FDSRh4=; fh=B0Kr+W4P+gDWCh4uaZww8C7+cggdkGoCsVYEV5mipv8=; b=HnVsE+CY4oNc1d9nE4PWIZMOJD31XHE/pjdSryifFooh3xhylWsXCfR6WbEkq2ivbO JvgCEX9WSwcG7bg1sp0vc9IVJI0u9AFGjo+GabpnwxCv1md9b0X+dzBrUF0cMDhMVVTO upEoqHcS5RsC/zdqXj9lZaD2YxeVBnP7e6tNkjV53HPfB3K9RpEUn4mvlVaxYyG+XrVC fcPl+yMvbaJELeTvA8XEm0+MEytiP5KaW8WQgWGW7vUQOp68xR48X1SIzAsnOIZ2IH2B zPV07Eik2gZKqFvyk1YOKAJiMKIaYeWAHC35R6BoWwv7RMl7yv6hauAcF4x08Wu4Wxhs YR+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Lo4hCg8M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id lw9-20020a17090b180900b0026d034f6baesi174272pjb.117.2023.10.12.12.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:31:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Lo4hCg8M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 3CEB3808E665; Thu, 12 Oct 2023 12:30:56 -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 S1442223AbjJLTac (ORCPT + 19 others); Thu, 12 Oct 2023 15:30:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442172AbjJLTaX (ORCPT ); Thu, 12 Oct 2023 15:30:23 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38677BB for ; Thu, 12 Oct 2023 12:30:22 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-69101022969so1210473b3a.3 for ; Thu, 12 Oct 2023 12:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697139022; x=1697743822; 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=wIBdQHfHPM91+b5JonQNYSwOG95FePEogJzP0FDSRh4=; b=Lo4hCg8MjbZ3rjVctuJwOHfdaEbxxPjqg2YWMAVzsSb3nN11ID0NyQsfSnrivseRfd qlus7Z5tDflBYlebtyxxR1gWj9UesmXyTFDKydhLvmZO+OoC5H5tQ8MqFTrSJ/wSizjl BnxHR+d9dsvcIDl/L6uwd59u7d/uhHtknxc8g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697139022; x=1697743822; 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=wIBdQHfHPM91+b5JonQNYSwOG95FePEogJzP0FDSRh4=; b=ZmLsIRuZlvdTUciyvDSD6vGfGhFfTRCzkJKZA1s4N2xOk8nHgNLvJzfwTX2JYTx1FA 7zrB0XQG/LfN4O0l+e68kCMPuR1tWnOLg91hXLUVKkHmpeM9ypfjVuKMbVsZgb906toW j6RPCCeXo76UVgB1qFjyVvDiJz2STpgRdQFlM8gALkyjb+Qz9F193YLhFWqNSsJtLLHY rqm0ppuD3M2TLqgi8U5bDFXqMkL6W8p8bKi4epPEufeMKcjuQGQWFSanbagrm5JRyQ9i U3f6svFui291YFAmuINl6EPf9vBeaPrmByGA/cgM0lZsoiCIlZnBRb5DSry5iaSzcQgl UR+w== X-Gm-Message-State: AOJu0YwH8tsVaYNJMKQyiljDL6kz1rTFBD9r4aIRG/bE5ms44NQJE7zP WubcR0WD2paV+j9/ekpbLU08zQ== X-Received: by 2002:a05:6a20:9385:b0:161:3120:e840 with SMTP id x5-20020a056a20938500b001613120e840mr31028866pzh.2.1697139021715; Thu, 12 Oct 2023 12:30:21 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:7c85:4a99:f03e:6f30]) by smtp.gmail.com with ESMTPSA id b3-20020a639303000000b0057c25885fcfsm2075720pge.10.2023.10.12.12.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:30:21 -0700 (PDT) From: Douglas Anderson To: Jakub Kicinski , Hayes Wang , "David S . Miller" Cc: Alan Stern , Simon Horman , Edward Hill , Laura Nao , linux-usb@vger.kernel.org, Grant Grundler , Douglas Anderson , =?utf-8?q?Bj=C3=B8rn_Mork?= , Eric Dumazet , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 3/5] r8152: Check for unplug in r8153b_ups_en() / r8153c_ups_en() Date: Thu, 12 Oct 2023 12:25:02 -0700 Message-ID: <20231012122458.v3.3.I6405b1587446c157c6d6263957571f2b11f330a7@changeid> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231012192552.3900360-1-dianders@chromium.org> References: <20231012192552.3900360-1-dianders@chromium.org> MIME-Version: 1.0 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: 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]); Thu, 12 Oct 2023 12:30:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779579294223903799 X-GMAIL-MSGID: 1779579294223903799 If the adapter is unplugged while we're looping in r8153b_ups_en() / r8153c_ups_en() we could end up looping for 10 seconds (20 ms * 500 loops). Add code similar to what's done in other places in the driver to check for unplug and bail. Signed-off-by: Douglas Anderson --- (no changes since v2) Changes in v2: - ("Check for unplug in r8153b_ups_en() / r8153c_ups_en()") new for v2. drivers/net/usb/r8152.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index fff2f9e67b5f..888d3884821e 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -3663,6 +3663,8 @@ static void r8153b_ups_en(struct r8152 *tp, bool enable) int i; for (i = 0; i < 500; i++) { + if (test_bit(RTL8152_UNPLUG, &tp->flags)) + return; if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & AUTOLOAD_DONE) break; @@ -3703,6 +3705,8 @@ static void r8153c_ups_en(struct r8152 *tp, bool enable) int i; for (i = 0; i < 500; i++) { + if (test_bit(RTL8152_UNPLUG, &tp->flags)) + return; if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & AUTOLOAD_DONE) break; From patchwork Thu Oct 12 19:25:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 152129 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1454927vqb; Thu, 12 Oct 2023 12:31:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzy1jxZkcxhdiZUu2q8vUUW6zPLiVDQ6ZgZ/0ummQMNMfbxw/GQfCEIxA+wF3kczVVW75U X-Received: by 2002:a05:6a21:a5a0:b0:15d:a247:d20c with SMTP id gd32-20020a056a21a5a000b0015da247d20cmr32637804pzc.6.1697139075373; Thu, 12 Oct 2023 12:31:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697139075; cv=none; d=google.com; s=arc-20160816; b=ILVT/rYhJat2luBsq2fghl02LMSinZsdNt8f0Wgd2tGexd0MWbg8HTZr4RHT4HakiA v2IdafdC6BSmz8vXSDu0k2SVam1lGiKHkIONcB4/WFp2T/Z/qcDFnJEC//6qaNPsfmtt sAsgT6LtM+Sam1dqIQlDG+pfA0FB4oMvtVJq92Fpr2/jMdoLrs74b1mn9ektHE+XZ8uc ijpSH4ugJ1AV9iOtdYCUpNN1BXfh0rWrAcBNNyYUy5/QHwlUhMQ6WCGAkSNbmtpNIb8E DR/8SIfwoF3/ZwR23W/g+tiAQQIrTKR1PC6ZmmkGviaq5/FPM9bLkRAL7JxTTCj+xKg+ CZOw== 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=rvAOP+HUnUGGrfOG0k5XMcWZrEhafNqXV9zZLzOfkdk=; fh=B0Kr+W4P+gDWCh4uaZww8C7+cggdkGoCsVYEV5mipv8=; b=RyUWH15laI+CMrJiBoJcerrqWnZYpALX7TOq5Xru9GfOZX4es8tNMPcxgFn2CH3uao sErySMY0Hnv3Cmrhs3VYPJ50hlwr4xq/jeMmxgjrt5+OyJa2FB77n+j6j0Xm9WHr17Si kaOXZ9yG+EoL5WFFX/RmANBfhKRwvZU1NutchNSi1A8d7LKoomBQb5C1FJeEPnXwqCXj LDbLRknyO3oGU/SXnEcUeHuzRFbUHEB9hlk7XdKTjrcRAzfcLVCLjELXssyUnYtizfJt ZcviwoqTHc5OUwhhNtjUzj59BLJWEYjZo+sSzWaSmQ9FEBLP5VX6Ev4OKGxPEuFw7v0J yzow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=d0bPCYkZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id p24-20020a637418000000b0057c9e0c7bb8si2858940pgc.312.2023.10.12.12.31.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:31:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=d0bPCYkZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 1687E8158305; Thu, 12 Oct 2023 12:31:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442222AbjJLTag (ORCPT + 19 others); Thu, 12 Oct 2023 15:30:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442196AbjJLTa2 (ORCPT ); Thu, 12 Oct 2023 15:30:28 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65199E1 for ; Thu, 12 Oct 2023 12:30:24 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-694f75deb1aso1954185b3a.0 for ; Thu, 12 Oct 2023 12:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697139024; x=1697743824; 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=rvAOP+HUnUGGrfOG0k5XMcWZrEhafNqXV9zZLzOfkdk=; b=d0bPCYkZfPMEZpdNDkf2Lla3MTkfJ0G9WUSthvtfJ0lXYZ2n9YLC4UkBONls2iijcx GwwHp5fMDE4pHlSmVIh01jfosrBIX+mv51WIq/jTVJW8DhNQ8rvvzhVRSNYCDyLymBxa bLRuuRwe+faPlI5yHDleuno9bMgX49urnLWow= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697139024; x=1697743824; 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=rvAOP+HUnUGGrfOG0k5XMcWZrEhafNqXV9zZLzOfkdk=; b=JJumCsJ2JflM5o5vMXfAGo+WU4JY4o7Xir1qEemUqenqd8dK1PW3PzeG3iuAH/Y3ut s05vMvHmSioL1LnicHkpN+d89CBcaEdBFB81lv1+g1GalFXjzTfyHbN0x/XoBw8ITAaB 7XvbzLb3/JVm/qnXYET12ZR2x64SFazs8CLfwxwiPZnY29rZJOcN1Mr8cEFw1bm84Ihe 07aT+TLFrj9bXa8QSPThW7bV/M4laYHzK4DNtbn2gMbk0/2sJShWbS9BQKCVsJGs11Ej AoHvlHkzxUGyRx2zn61/Te2xJn/AyVNgBJfp5RuqPGF0fSgJyveet+xv2TNAbXQk4ClV 0skA== X-Gm-Message-State: AOJu0Yx+kclXE1F9kVxaOrqf6+piRTwy1tkHw+bN/MAPBoO0Aswso/I+ vciyVju20JY8qCfdB3w/KplY0Q== X-Received: by 2002:a05:6a20:1584:b0:15e:6909:533c with SMTP id h4-20020a056a20158400b0015e6909533cmr29303915pzj.30.1697139023718; Thu, 12 Oct 2023 12:30:23 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:7c85:4a99:f03e:6f30]) by smtp.gmail.com with ESMTPSA id b3-20020a639303000000b0057c25885fcfsm2075720pge.10.2023.10.12.12.30.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:30:23 -0700 (PDT) From: Douglas Anderson To: Jakub Kicinski , Hayes Wang , "David S . Miller" Cc: Alan Stern , Simon Horman , Edward Hill , Laura Nao , linux-usb@vger.kernel.org, Grant Grundler , Douglas Anderson , =?utf-8?q?Bj=C3=B8rn_Mork?= , Eric Dumazet , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 4/5] r8152: Rename RTL8152_UNPLUG to RTL8152_INACCESSIBLE Date: Thu, 12 Oct 2023 12:25:03 -0700 Message-ID: <20231012122458.v3.4.Iaacab4e73761e7bd9bb622b30a804c5d20bd5b4c@changeid> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231012192552.3900360-1-dianders@chromium.org> References: <20231012192552.3900360-1-dianders@chromium.org> MIME-Version: 1.0 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 pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:31:10 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779579301919346292 X-GMAIL-MSGID: 1779579301919346292 Whenever the RTL8152_UNPLUG is set that just tells the driver that all accesses will fail and we should just immediately bail. A future patch will use this same concept at a time when the driver hasn't actually been unplugged but is about to be reset. Rename the flag in preparation for the future patch. This is a no-op change and just a search and replace. Signed-off-by: Douglas Anderson --- (no changes since v2) Changes in v2: - ("Rename RTL8152_UNPLUG to RTL8152_INACCESSIBLE") new for v2. drivers/net/usb/r8152.c | 96 ++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 888d3884821e..151c3c383080 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -764,7 +764,7 @@ enum rtl_register_content { /* rtl8152 flags */ enum rtl8152_flags { - RTL8152_UNPLUG = 0, + RTL8152_INACCESSIBLE = 0, RTL8152_SET_RX_MODE, WORK_ENABLE, RTL8152_LINK_CHG, @@ -1245,7 +1245,7 @@ int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) static void rtl_set_unplug(struct r8152 *tp) { if (tp->udev->state == USB_STATE_NOTATTACHED) { - set_bit(RTL8152_UNPLUG, &tp->flags); + set_bit(RTL8152_INACCESSIBLE, &tp->flags); smp_mb__after_atomic(); } } @@ -1256,7 +1256,7 @@ static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size, u16 limit = 64; int ret = 0; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return -ENODEV; /* both size and indix must be 4 bytes align */ @@ -1300,7 +1300,7 @@ static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 byteen_start, byteen_end, byen; u16 limit = 512; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return -ENODEV; /* both size and indix must be 4 bytes align */ @@ -1537,7 +1537,7 @@ static int read_mii_word(struct net_device *netdev, int phy_id, int reg) struct r8152 *tp = netdev_priv(netdev); int ret; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return -ENODEV; if (phy_id != R8152_PHY_ID) @@ -1553,7 +1553,7 @@ void write_mii_word(struct net_device *netdev, int phy_id, int reg, int val) { struct r8152 *tp = netdev_priv(netdev); - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; if (phy_id != R8152_PHY_ID) @@ -1758,7 +1758,7 @@ static void read_bulk_callback(struct urb *urb) if (!tp) return; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; if (!test_bit(WORK_ENABLE, &tp->flags)) @@ -1850,7 +1850,7 @@ static void write_bulk_callback(struct urb *urb) if (!test_bit(WORK_ENABLE, &tp->flags)) return; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; if (!skb_queue_empty(&tp->tx_queue)) @@ -1871,7 +1871,7 @@ static void intr_callback(struct urb *urb) if (!test_bit(WORK_ENABLE, &tp->flags)) return; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; switch (status) { @@ -2615,7 +2615,7 @@ static void bottom_half(struct tasklet_struct *t) { struct r8152 *tp = from_tasklet(tp, t, tx_tl); - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; if (!test_bit(WORK_ENABLE, &tp->flags)) @@ -2658,7 +2658,7 @@ int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags) int ret; /* The rx would be stopped, so skip submitting */ - if (test_bit(RTL8152_UNPLUG, &tp->flags) || + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags) || !test_bit(WORK_ENABLE, &tp->flags) || !netif_carrier_ok(tp->netdev)) return 0; @@ -3058,7 +3058,7 @@ static int rtl_enable(struct r8152 *tp) static int rtl8152_enable(struct r8152 *tp) { - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return -ENODEV; set_tx_qlen(tp); @@ -3145,7 +3145,7 @@ static int rtl8153_enable(struct r8152 *tp) { u32 ocp_data; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return -ENODEV; set_tx_qlen(tp); @@ -3177,7 +3177,7 @@ static void rtl_disable(struct r8152 *tp) u32 ocp_data; int i; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) { + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { rtl_drop_queued_tx(tp); return; } @@ -3631,7 +3631,7 @@ static u16 r8153_phy_status(struct r8152 *tp, u16 desired) } msleep(20); - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) break; } @@ -3663,7 +3663,7 @@ static void r8153b_ups_en(struct r8152 *tp, bool enable) int i; for (i = 0; i < 500; i++) { - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & AUTOLOAD_DONE) @@ -3705,7 +3705,7 @@ static void r8153c_ups_en(struct r8152 *tp, bool enable) int i; for (i = 0; i < 500; i++) { - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; if (ocp_read_word(tp, MCU_TYPE_PLA, PLA_BOOT_CTRL) & AUTOLOAD_DONE) @@ -4050,8 +4050,8 @@ static int rtl_phy_patch_request(struct r8152 *tp, bool request, bool wait) for (i = 0; wait && i < 5000; i++) { u32 ocp_data; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) - break; + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) + return -ENODEV; usleep_range(1000, 2000); ocp_data = ocp_reg_read(tp, OCP_PHY_PATCH_STAT); @@ -6009,7 +6009,7 @@ static int rtl8156_enable(struct r8152 *tp) u32 ocp_data; u16 speed; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return -ENODEV; r8156_fc_parameter(tp); @@ -6067,7 +6067,7 @@ static int rtl8156b_enable(struct r8152 *tp) u32 ocp_data; u16 speed; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return -ENODEV; set_tx_qlen(tp); @@ -6253,7 +6253,7 @@ static int rtl8152_set_speed(struct r8152 *tp, u8 autoneg, u32 speed, u8 duplex, static void rtl8152_up(struct r8152 *tp) { - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; r8152_aldps_en(tp, false); @@ -6263,7 +6263,7 @@ static void rtl8152_up(struct r8152 *tp) static void rtl8152_down(struct r8152 *tp) { - if (test_bit(RTL8152_UNPLUG, &tp->flags)) { + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { rtl_drop_queued_tx(tp); return; } @@ -6278,7 +6278,7 @@ static void rtl8153_up(struct r8152 *tp) { u32 ocp_data; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; r8153_u1u2en(tp, false); @@ -6318,7 +6318,7 @@ static void rtl8153_down(struct r8152 *tp) { u32 ocp_data; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) { + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { rtl_drop_queued_tx(tp); return; } @@ -6339,7 +6339,7 @@ static void rtl8153b_up(struct r8152 *tp) { u32 ocp_data; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; r8153b_u1u2en(tp, false); @@ -6363,7 +6363,7 @@ static void rtl8153b_down(struct r8152 *tp) { u32 ocp_data; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) { + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { rtl_drop_queued_tx(tp); return; } @@ -6400,7 +6400,7 @@ static void rtl8153c_up(struct r8152 *tp) { u32 ocp_data; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; r8153b_u1u2en(tp, false); @@ -6481,7 +6481,7 @@ static void rtl8156_up(struct r8152 *tp) { u32 ocp_data; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; r8153b_u1u2en(tp, false); @@ -6554,7 +6554,7 @@ static void rtl8156_down(struct r8152 *tp) { u32 ocp_data; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) { + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { rtl_drop_queued_tx(tp); return; } @@ -6692,7 +6692,7 @@ static void rtl_work_func_t(struct work_struct *work) /* If the device is unplugged or !netif_running(), the workqueue * doesn't need to wake the device, and could return directly. */ - if (test_bit(RTL8152_UNPLUG, &tp->flags) || !netif_running(tp->netdev)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags) || !netif_running(tp->netdev)) return; if (usb_autopm_get_interface(tp->intf) < 0) @@ -6731,7 +6731,7 @@ static void rtl_hw_phy_work_func_t(struct work_struct *work) { struct r8152 *tp = container_of(work, struct r8152, hw_phy_work.work); - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; if (usb_autopm_get_interface(tp->intf) < 0) @@ -6858,7 +6858,7 @@ static int rtl8152_close(struct net_device *netdev) netif_stop_queue(netdev); res = usb_autopm_get_interface(tp->intf); - if (res < 0 || test_bit(RTL8152_UNPLUG, &tp->flags)) { + if (res < 0 || test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { rtl_drop_queued_tx(tp); rtl_stop_rx(tp); } else { @@ -6891,7 +6891,7 @@ static void r8152b_init(struct r8152 *tp) u32 ocp_data; u16 data; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; data = r8152_mdio_read(tp, MII_BMCR); @@ -6935,7 +6935,7 @@ static void r8153_init(struct r8152 *tp) u16 data; int i; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; r8153_u1u2en(tp, false); @@ -6946,7 +6946,7 @@ static void r8153_init(struct r8152 *tp) break; msleep(20); - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) break; } @@ -7075,7 +7075,7 @@ static void r8153b_init(struct r8152 *tp) u16 data; int i; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; r8153b_u1u2en(tp, false); @@ -7086,7 +7086,7 @@ static void r8153b_init(struct r8152 *tp) break; msleep(20); - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) break; } @@ -7157,7 +7157,7 @@ static void r8153c_init(struct r8152 *tp) u16 data; int i; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; r8153b_u1u2en(tp, false); @@ -7177,7 +7177,7 @@ static void r8153c_init(struct r8152 *tp) break; msleep(20); - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; } @@ -8006,7 +8006,7 @@ static void r8156_init(struct r8152 *tp) u16 data; int i; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_ECM_OP); @@ -8027,7 +8027,7 @@ static void r8156_init(struct r8152 *tp) break; msleep(20); - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; } @@ -8102,7 +8102,7 @@ static void r8156b_init(struct r8152 *tp) u16 data; int i; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_ECM_OP); @@ -8136,7 +8136,7 @@ static void r8156b_init(struct r8152 *tp) break; msleep(20); - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; } @@ -9165,7 +9165,7 @@ static int rtl8152_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) struct mii_ioctl_data *data = if_mii(rq); int res; - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return -ENODEV; res = usb_autopm_get_interface(tp->intf); @@ -9267,7 +9267,7 @@ static const struct net_device_ops rtl8152_netdev_ops = { static void rtl8152_unload(struct r8152 *tp) { - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; if (tp->version != RTL_VER_01) @@ -9276,7 +9276,7 @@ static void rtl8152_unload(struct r8152 *tp) static void rtl8153_unload(struct r8152 *tp) { - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; r8153_power_cut_en(tp, false); @@ -9284,7 +9284,7 @@ static void rtl8153_unload(struct r8152 *tp) static void rtl8153b_unload(struct r8152 *tp) { - if (test_bit(RTL8152_UNPLUG, &tp->flags)) + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) return; r8153b_power_cut_en(tp, false); From patchwork Thu Oct 12 19:25:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 152130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp1454989vqb; Thu, 12 Oct 2023 12:31:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7+UO82J+3fH8ZLQIWUITXqFedVyaYL8frGE6JZ+GS24dYg3b4sHkqJnhyaB7+GHkC+YC8 X-Received: by 2002:a17:902:ce84:b0:1c3:a4f2:7c99 with SMTP id f4-20020a170902ce8400b001c3a4f27c99mr27773045plg.4.1697139082397; Thu, 12 Oct 2023 12:31:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697139082; cv=none; d=google.com; s=arc-20160816; b=S/QxM6eAOGLXhMeLJTfNysHnSVBJxZ8GipqwGiOCIh4nCuvJ5S0TeNQ2zvhY8rxcgL 3luqmn9soyCVSy8rronIWuj/C3fbuQ19QdsmqodFFLsy9T5DOhRq5Z+Zyi+XPZjGONjo ubeqw5aYFhru07YOI55Htt+MQzHV9cxR2UPZIgtOtMUykjtUYP1AVzEGS/EW5Lr/5b8n BLDvDjbRa95JNDHhVJfuarWWnMe0DPkNOn6s9/hwuLzBMzBCUmNRJECLqYjeZB163XVI JW66unDd6dhVVLlbR/gqQ97bxV0q3WjED9TzD999q5GX4cz83YH70ZA9da6dYXO1jmD+ J4Hw== 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=Gcf2QHQ6TL/y4ldUWtXd1iY7HrL3wUwUVRkcf9G8sDo=; fh=B0Kr+W4P+gDWCh4uaZww8C7+cggdkGoCsVYEV5mipv8=; b=LwWjg9jtaYfdRT1jHju77T+mguZpcS1f6yZsClvx+Dmc+hGlWAKIO3w9mr065+RMZI fv0Bp027tcSkLtHKo58ao5+IjzK74WVe8ZEIfAmWBTpqZoYfDMeCcQCf7AK9qUonju+A uI+AJw1J82IlvRb9AsHgITJutJiGISbgeg0MtqePANOHTP1GjD4qPWn53G3mtWAT8pLI bgUP1U95kWjB8ecYcY95xbNO/6S5V8VpqJdHVI0ce9gjfoPLDJZ6jNcSw3KhBP1s0VFT wsKz8waNNfnlnRS991dmOdFncBqqKfCHTJK40z+4z6Y7ADG0CN+A1Q3G8idXhAIwBco1 Nr/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="K/clFkMd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ij25-20020a170902ab5900b001bdc664cd69si2626375plb.153.2023.10.12.12.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:31:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="K/clFkMd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id E155E81143E9; Thu, 12 Oct 2023 12:31:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442280AbjJLTal (ORCPT + 19 others); Thu, 12 Oct 2023 15:30:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442234AbjJLTaa (ORCPT ); Thu, 12 Oct 2023 15:30:30 -0400 Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 861BBCF for ; Thu, 12 Oct 2023 12:30:26 -0700 (PDT) Received: by mail-oo1-xc29.google.com with SMTP id 006d021491bc7-57b6a7e0deeso777630eaf.2 for ; Thu, 12 Oct 2023 12:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1697139026; x=1697743826; 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=Gcf2QHQ6TL/y4ldUWtXd1iY7HrL3wUwUVRkcf9G8sDo=; b=K/clFkMd+XPolG0iAYTBF2zlEmF/6bHk3q/JPxGQIz+FKYm3hXETmsvhsawRxfavV+ BU8s10SGfdnAmqllT7Z87ZQ6ITKyrPt1p6wrQv2fluQHgdB7cPV8T2ME5jKVa2mTIHay faYbRwVQvYjXa9ppr3+iBX4CTS9mGEQzi96qw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697139026; x=1697743826; 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=Gcf2QHQ6TL/y4ldUWtXd1iY7HrL3wUwUVRkcf9G8sDo=; b=Yr8dSXnXVXqCKODo2YjlHYPimtqeD5NuFVJRi1vkNyt/h6kTZdokEoBYvEIs9TlqZG 2U+NgIdn5N1HzhqDh0ZgymGSRa9fakHvMKC6ggGsmeNA/QSIfMizLhIOr20MdJpKsONc Mq6jamsfsZVxY5NYYeFFSJa8WhWRz/x+4xKd9W+ZcYG4T3kg3JLyxSqYgRsJC7cZXtRk ctLjOK/+kxBvxXJJJkHpBu4lDzj/jxkM16nNBOoC1Zhb5x174c1Nig/12ifz/dGSPEIu QibTWP//HRgUTzrrM8pqGDoOoXSU6WwkOmd8GPeqjfkGmuT8naySG1a3psFM5+WEeENd eUYQ== X-Gm-Message-State: AOJu0Ywp/yLHMV1RBuPlDmD/ncZhFi5xsCDm1skFWUbBI/Arg0A6MgQR OWJ1efqrWMzrTMzx3G7nGT84dQ== X-Received: by 2002:a05:6358:7e07:b0:134:e301:2c21 with SMTP id o7-20020a0563587e0700b00134e3012c21mr27381283rwm.15.1697139025586; Thu, 12 Oct 2023 12:30:25 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:7c85:4a99:f03e:6f30]) by smtp.gmail.com with ESMTPSA id b3-20020a639303000000b0057c25885fcfsm2075720pge.10.2023.10.12.12.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 12:30:25 -0700 (PDT) From: Douglas Anderson To: Jakub Kicinski , Hayes Wang , "David S . Miller" Cc: Alan Stern , Simon Horman , Edward Hill , Laura Nao , linux-usb@vger.kernel.org, Grant Grundler , Douglas Anderson , =?utf-8?q?Bj=C3=B8rn_Mork?= , Eric Dumazet , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 5/5] r8152: Block future register access if register access fails Date: Thu, 12 Oct 2023 12:25:04 -0700 Message-ID: <20231012122458.v3.5.Ib2affdbfdc2527aaeef9b46d4f23f7c04147faeb@changeid> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231012192552.3900360-1-dianders@chromium.org> References: <20231012192552.3900360-1-dianders@chromium.org> MIME-Version: 1.0 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 howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Thu, 12 Oct 2023 12:31:16 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779579310831843651 X-GMAIL-MSGID: 1779579310831843651 Even though the functions to read/write registers can fail, most of the places in the r8152 driver that read/write register values don't check error codes. The lack of error code checking is problematic in at least two ways. The first problem is that the r8152 driver often uses code patterns similar to this: x = read_register() x = x | SOME_BIT; write_register(x); ...with the above pattern, if the read_register() fails and returns garbage then we'll end up trying to write modified garbage back to the Realtek adapter. If the write_register() succeeds that's bad. Note that as of commit f53a7ad18959 ("r8152: Set memory to all 0xFFs on failed reg reads") the "garbage" returned by read_register() will at least be consistent garbage, but it is still garbage. It turns out that this problem is very serious. Writing garbage to some of the hardware registers on the Ethernet adapter can put the adapter in such a bad state that it needs to be power cycled (fully unplugged and plugged in again) before it can enumerate again. The second problem is that the r8152 driver generally has functions that are long sequences of register writes. Assuming everything will be OK if a random register write fails in the middle isn't a great assumption. One might wonder if the above two problems are real. You could ask if we would really have a successful write after a failed read. It turns out that the answer appears to be "yes, this can happen". In fact, we've seen at least two distinct failure modes where this happens. On a sc7180-trogdor Chromebook if you drop into kdb for a while and then resume, you can see: 1. We get a "Tx timeout" 2. The "Tx timeout" queues up a USB reset. 3. In rtl8152_pre_reset() we try to reinit the hardware. 4. The first several (2-9) register accesses fail with a timeout, then things recover. The above test case was actually fixed by the patch ("r8152: Increase USB control msg timeout to 5000ms as per spec") but at least shows that we really can see successful calls after failed ones. On a different (AMD) based Chromebook with a particular adapter, we found that during reboot tests we'd also sometimes get a transitory failure. In this case we saw -EPIPE being returned sometimes. Retrying worked, but retrying is not always safe for all register accesses since reading/writing some registers might have side effects (like registers that clear on read). Let's fully lock out all register access if a register access fails. When we do this, we'll try to queue up a USB reset and try to unlock register access after the reset. This is slightly tricker than it sounds since the r8152 driver has an optimized reset sequence that only works reliably after probe happens. In order to handle this, we avoid the optimized reset if probe didn't finish. When locking out access, we'll use the existing infrastructure that the driver was using when it detected we were unplugged. This keeps us from getting stuck in delay loops in some parts of the driver. Signed-off-by: Douglas Anderson Reviewed-by: Grant Grundler --- Originally when looking at this problem I thought that the obvious solution was to "just" add better error handling to the driver. This _sounds_ appealing, but it's a massive change and touches a significant portion of the lines in this driver. It's also not always obvious what the driver should be doing to handle errors. If you feel like you need to be convinced and to see what it looked like to add better error handling, I put up my "work in progress" patch when I was investigating this at: https://crrev.com/c/4937290 There is still some active debate between the two approaches, though, so it would be interesting to hear if anyone had any opinions. Changes in v3: - Fixed v2 changelog ending up in the commit message. - farmework -> framework in comments. Changes in v2: - Reset patch no longer based on retry patch, since that was dropped. - Reset patch should be robust even if failures happen in probe. - Switched booleans to bits in the "flags" variable. - Check for -ENODEV instead of "udev->state == USB_STATE_NOTATTACHED" drivers/net/usb/r8152.c | 176 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 159 insertions(+), 17 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 151c3c383080..fce7c58f8142 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -773,6 +773,8 @@ enum rtl8152_flags { SCHEDULE_TASKLET, GREEN_ETHERNET, RX_EPROTO, + IN_PRE_RESET, + PROBED_WITH_NO_ERRORS, }; #define DEVICE_ID_LENOVO_USB_C_TRAVEL_HUB 0x721e @@ -953,6 +955,8 @@ struct r8152 { u8 version; u8 duplex; u8 autoneg; + + unsigned int reg_access_reset_count; }; /** @@ -1200,6 +1204,91 @@ static unsigned int agg_buf_sz = 16384; #define RTL_LIMITED_TSO_SIZE (size_to_mtu(agg_buf_sz) - sizeof(struct tx_desc)) +/* If register access fails then we block access and issue a reset. If this + * happens too many times in a row without a successful access then we stop + * trying to reset and just leave access blocked. + */ +#define REGISTER_ACCESS_MAX_RESETS 3 + +static void rtl_set_inaccessible(struct r8152 *tp) +{ + set_bit(RTL8152_INACCESSIBLE, &tp->flags); + smp_mb__after_atomic(); +} + +static void rtl_set_accessible(struct r8152 *tp) +{ + clear_bit(RTL8152_INACCESSIBLE, &tp->flags); + smp_mb__after_atomic(); +} + +static +int r8152_control_msg(struct r8152 *tp, unsigned int pipe, __u8 request, + __u8 requesttype, __u16 value, __u16 index, void *data, + __u16 size, const char *msg_tag) +{ + struct usb_device *udev = tp->udev; + int ret; + + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) + return -ENODEV; + + ret = usb_control_msg(udev, pipe, request, requesttype, + value, index, data, size, + USB_CTRL_GET_TIMEOUT); + + /* No need to issue a reset report an error if the USB device got + * unplugged; just return immediately. + */ + if (ret == -ENODEV) + return ret; + + /* If the write was successful then we're done */ + if (ret >= 0) { + tp->reg_access_reset_count = 0; + return ret; + } + + dev_err(&udev->dev, + "Failed to %s %d bytes at %#06x/%#06x (%d)\n", + msg_tag, size, value, index, ret); + + /* Block all future register access until we reset. Much of the oode + * in the driver doesn't check for errors. Notably, many parts of the + * driver do a read/modify/write of a register value without + * confirming that the read succeeded. Writing back modified garbage + * like this can fully wedge the adapter, requiring a power cycle. + */ + rtl_set_inaccessible(tp); + + /* Failing to access registers in pre-reset is not surprising since we + * wouldn't be resetting if things were behaving normally. The register + * access we do in pre-reset isn't truly mandatory--we're just reusing + * the disable() function and trying to be nice by powering the + * adapter down before resetting it. Thus, if we're in pre-reset, + * we'll return right away and not try to queue up yet another reset. + * We know the post-reset is already coming. + * + * We'll also return right away if we haven't finished probe. At the + * end of probe we'll queue the reset just to make sure it doesn't + * timeout. + */ + if (test_bit(IN_PRE_RESET, &tp->flags) || + !test_bit(PROBED_WITH_NO_ERRORS, &tp->flags)) + return ret; + + if (tp->reg_access_reset_count < REGISTER_ACCESS_MAX_RESETS) { + usb_queue_reset_device(tp->intf); + tp->reg_access_reset_count++; + } else if (tp->reg_access_reset_count == REGISTER_ACCESS_MAX_RESETS) { + dev_err(&udev->dev, + "Tried to reset %d times; giving up.\n", + REGISTER_ACCESS_MAX_RESETS); + } + + return ret; +} + static int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) { @@ -1210,9 +1299,10 @@ int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) if (!tmp) return -ENOMEM; - ret = usb_control_msg(tp->udev, tp->pipe_ctrl_in, - RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, - value, index, tmp, size, USB_CTRL_GET_TIMEOUT); + ret = r8152_control_msg(tp, tp->pipe_ctrl_in, + RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, + value, index, tmp, size, "read"); + if (ret < 0) memset(data, 0xff, size); else @@ -1233,9 +1323,9 @@ int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) if (!tmp) return -ENOMEM; - ret = usb_control_msg(tp->udev, tp->pipe_ctrl_out, - RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE, - value, index, tmp, size, USB_CTRL_SET_TIMEOUT); + ret = r8152_control_msg(tp, tp->pipe_ctrl_out, + RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE, + value, index, tmp, size, "write"); kfree(tmp); @@ -1244,10 +1334,8 @@ int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data) static void rtl_set_unplug(struct r8152 *tp) { - if (tp->udev->state == USB_STATE_NOTATTACHED) { - set_bit(RTL8152_INACCESSIBLE, &tp->flags); - smp_mb__after_atomic(); - } + if (tp->udev->state == USB_STATE_NOTATTACHED) + rtl_set_inaccessible(tp); } static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size, @@ -8265,6 +8353,19 @@ static int rtl8152_pre_reset(struct usb_interface *intf) if (!tp) return 0; + /* We can only use the optimized reset if we made it to the end of + * probe without any register access fails, which sets + * `PROBED_WITH_NO_ERRORS` to true. If we didn't have that then return + * an error here which tells the USB framework to fully unbind/rebind + * our driver. + */ + mutex_lock(&tp->control); + if (!test_bit(PROBED_WITH_NO_ERRORS, &tp->flags)) { + mutex_unlock(&tp->control); + return -EIO; + } + mutex_unlock(&tp->control); + netdev = tp->netdev; if (!netif_running(netdev)) return 0; @@ -8277,7 +8378,9 @@ static int rtl8152_pre_reset(struct usb_interface *intf) napi_disable(&tp->napi); if (netif_carrier_ok(netdev)) { mutex_lock(&tp->control); + set_bit(IN_PRE_RESET, &tp->flags); tp->rtl_ops.disable(tp); + clear_bit(IN_PRE_RESET, &tp->flags); mutex_unlock(&tp->control); } @@ -8293,6 +8396,10 @@ static int rtl8152_post_reset(struct usb_interface *intf) if (!tp) return 0; + mutex_lock(&tp->control); + rtl_set_accessible(tp); + mutex_unlock(&tp->control); + /* reset the MAC address in case of policy change */ if (determine_ethernet_addr(tp, &sa) >= 0) { rtnl_lock(); @@ -9494,17 +9601,30 @@ static u8 __rtl_get_hw_ver(struct usb_device *udev) __le32 *tmp; u8 version; int ret; + int i; tmp = kmalloc(sizeof(*tmp), GFP_KERNEL); if (!tmp) return 0; - ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), - RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, - PLA_TCR0, MCU_TYPE_PLA, tmp, sizeof(*tmp), - USB_CTRL_GET_TIMEOUT); - if (ret > 0) - ocp_data = (__le32_to_cpu(*tmp) >> 16) & VERSION_MASK; + /* Retry up to 3 times in case there is a transitory error. We do this + * since retrying a read of the version is always safe and this + * function doesn't take advantage of r8152_control_msg() which would + * queue up a reset upon error. + */ + for (i = 0; i < 3; i++) { + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), + RTL8152_REQ_GET_REGS, RTL8152_REQT_READ, + PLA_TCR0, MCU_TYPE_PLA, tmp, sizeof(*tmp), + USB_CTRL_GET_TIMEOUT); + if (ret > 0) { + ocp_data = (__le32_to_cpu(*tmp) >> 16) & VERSION_MASK; + break; + } + } + + if (i != 0 && ret > 0) + dev_warn(&udev->dev, "Needed %d retries to read version\n", i); kfree(tmp); @@ -9784,7 +9904,29 @@ static int rtl8152_probe(struct usb_interface *intf, else device_set_wakeup_enable(&udev->dev, false); - netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION); + mutex_lock(&tp->control); + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) { + /* If the device is marked inaccessible before probe even + * finished then one of two things happened. Either we got a + * USB error during probe or the user already unplugged the + * device. + * + * If we got a USB error during probe then we skipped doing a + * reset in r8152_control_msg() and deferred it to here. This + * is because the queued reset will give up after 1 second + * (see usb_lock_device_for_reset()) and we want to make sure + * that we queue things up right before probe finishes. + * + * If the user already unplugged the device then the USB + * framework will call unbind right away for us. The extra + * reset we queue up here will be harmless. + */ + usb_queue_reset_device(tp->intf); + } else { + set_bit(PROBED_WITH_NO_ERRORS, &tp->flags); + netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION); + } + mutex_unlock(&tp->control); return 0;