From patchwork Thu May 30 23:43:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 802293 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35AB3183084 for ; Thu, 30 May 2024 23:43:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717112614; cv=none; b=DSSsiH3MwHRi1VTqHqtNP6vDXzhDKu9EXo+U4pVKbFNS0x26gGFwmXs7E/AoRBQOlNdXgTD2YkN22S+6Mh5noFgQjQSgaRtqYQhrKQY/08izcyvdy5Z4wnyWHYyV8HXod5VZoZW/f/dylzpN68vMokvapUOKmUNAAbJOTIZsaiw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717112614; c=relaxed/simple; bh=uUh0scWgAAnBxAOdDHx9RouN1dRcQ02724YXzEXjoLY=; h=Message-ID:From:To:Cc:Subject:Date:MIME-Version; b=OlL0BwKWIWprgrE4KlJZeHt31ZgzYKvKjjDN+FJDlRCg59xJxQcqo4ZBAlp6+eGbnwC5vEIdLZsJbUBtarBTFGHNyw2cQGLykGtxR/8Mv0CPRWx851PkfhiYYM3HzIHAgqxcCVSK/E4aDg4s0y/H9dOZmJd+DKaq1Zjq4pUFe3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=I1rKgK37; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="I1rKgK37" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1f60a502bb2so11365815ad.3 for ; Thu, 30 May 2024 16:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1717112611; x=1717717411; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:date:subject:cc:to:from :message-id:from:to:cc:subject:date:message-id:reply-to; bh=213yq+FHXchIlGeobquZB8jFxU/5d0H9yaCh+D4OtRk=; b=I1rKgK37fIlXWZIsGetzPmix8j3X1QZosRNbTiMumTfRBJYCsI1TJ/mmHzCtHOOAws MQr5/S2mct+n6XG66oO7eDXX9l8KEkqn+7lRS24rHrpCkIWxpKiu1gGq8Z3rZa8zjUp9 s7OPpAW9FhJTZg7Rstkpt9BuH2ZgVNPYyo1zY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717112611; x=1717717411; h=content-transfer-encoding:mime-version:date:subject:cc:to:from :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=213yq+FHXchIlGeobquZB8jFxU/5d0H9yaCh+D4OtRk=; b=aXVvJnj6rM1FJvY7aOHOEq6eW6Nwuml17oolCVHGJvOSV0nxhQtrXoAzfeoW2kR+4B NCyJKzWjupJVKFGhZjoP1bOhVvVZOtyj5anBj1ruQHp7Thnyl6HKpGfSTqOxSxCRQRTa aQ371o7q3aj6a2T2Ef8Shv0QRmGiAMSrgDUHNsmRpUx+SGN1geW/xC6o4wMrzNBPcoMe l/wD+bd4NWmsG7Z/ythoCuv1qYa+BRHmHbEsEMhxflGlG3Um8qGvkZSPp0tM2xRSbIdt DvRbx6EDseZ5MUHhpeEJpMmmX/VdCOJuSbfvF+UrQC9b5MiurYU2gZYKpaBFc+f/2rWY OKKQ== X-Forwarded-Encrypted: i=1; AJvYcCVmUfj5sMvP4BFKV3U7pUwpOMSzZgcVpC2uPD3FbT98x6oqpYHk8dDUHmHvSx/sVFRMk9RlnyqD3UHzsOBR3RExwRe3gHr3CfGr X-Gm-Message-State: AOJu0YwcsLibY5NStZjiLEdi1/EVRuh2fGPcR/3uVRczqGUBPTn/1pPZ QWyS/X9OROklg4BuErl7+4F7hxsciOXJqAE4YBeTrr/3+bbtaNNwA/5tLUjQFQ== X-Google-Smtp-Source: AGHT+IHIzulL1B1l4HrbVqXV+F8H37u4frOFnXNzNFoAa36TIVDnW/yMHkJcvalkHwod+UBLfL46Ig== X-Received: by 2002:a17:902:f646:b0:1f4:ae25:3d07 with SMTP id d9443c01a7336-1f6370e6510mr3732175ad.60.1717112611373; Thu, 30 May 2024 16:43:31 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:564b:72b6:4827:cf6a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f632416d90sm3459275ad.285.2024.05.30.16.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 16:43:30 -0700 (PDT) Message-ID: <66590f22.170a0220.8b5ad.1750@mx.google.com> X-Google-Original-Message-ID: <20240530164304.REPOST net-next.1.Ibeda5c0772812ce18953150da5a0888d2d875150@changeid> From: Douglas Anderson To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Hayes Wang Cc: danielgeorgem@google.com, Douglas Anderson , Andrew Lunn , Grant Grundler , Heiner Kallweit , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH REPOST net-next 1/2] r8152: If inaccessible at resume time, issue a reset Date: Thu, 30 May 2024 16:43:08 -0700 X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If we happened to get a USB transfer error during the transition to suspend then the usb_queue_reset_device() that r8152_control_msg() calls will get dropped on the floor. This is because usb_lock_device_for_reset() (which usb_queue_reset_device() uses) silently fails if it's called when a device is suspended or if too much time passes. Let's resolve this by resetting the device ourselves in r8152's resume() function. NOTE: due to timing, it's _possible_ that we could end up with two USB resets: the one queued previously and the one called from the resume() patch. This didn't happen in test cases I ran, though it's conceivably possible. We can't easily know if this happened since usb_queue_reset_device() can just silently drop the reset request. In any case, it's not expected that this is a problem since the two resets can't run at the same time (because of the device lock) and it should be OK to reset the device twice. If somehow the double-reset causes problems we could prevent resets from being queued up while suspend is running. Signed-off-by: Douglas Anderson --- Reposting now that the merge window is open as per [1]. [1] https://lore.kernel.org/r/75651199a933427a7fc3980ef8a2139f5f1f1695.camel@redhat.com drivers/net/usb/r8152.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 19df1cd9f072..6a3f4b2114ee 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -8554,6 +8554,19 @@ static int rtl8152_system_resume(struct r8152 *tp) usb_submit_urb(tp->intr_urb, GFP_NOIO); } + /* If the device is RTL8152_INACCESSIBLE here then we should do a + * reset. This is important because the usb_lock_device_for_reset() + * that happens as a result of usb_queue_reset_device() will silently + * fail if the device was suspended or if too much time passed. + * + * NOTE: The device is locked here so we can directly do the reset. + * We don't need usb_lock_device_for_reset() because that's just a + * wrapper over device_lock() and device_resume() (which calls us) + * does that for us. + */ + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) + usb_reset_device(tp->udev); + return 0; } From patchwork Thu May 30 23:43:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 800480 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4817183985 for ; Thu, 30 May 2024 23:43:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717112616; cv=none; b=VyX4COnFMsqivYKWrWBGKUiGJz7eEKmIk7Dt58sBTdybXqH5JFG3tVkMVhEgnOUyqcVm+cWHxYLMqVzLFsfvgb5UIq9q3wd6GgicfaB0dpJTpFALJ28GwISafrCQXmRlntdQMuXJPlSeGbp2zaIBzR8OHhJa8pzk5hnIIvGANOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717112616; c=relaxed/simple; bh=ltzXXLPD/ETo7voCPkE9iyg3r3LgEMh7nkLmfXKk4pY=; h=Message-ID:From:To:Cc:Subject:Date:In-Reply-To:References: MIME-Version; b=kvc66TKIjDrE/ee0ezR0U6OCI3J4Mxq7lT/lwxonpI87flKoRmvFxO9ilf/tIy3WWfv+rlcdHHUs32fDQGux2toTITBamfBJlCVamPpFqmzPMj0ycs2TKlSJ7uuIUYaLpEnwcxTgiRi4lDkJUOb0HAU0x5ez9LZbV0+zza9ddFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=HgqsFLjB; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="HgqsFLjB" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f48bd643a0so10892915ad.3 for ; Thu, 30 May 2024 16:43:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1717112614; x=1717717414; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to:date :subject:cc:to:from:message-id:from:to:cc:subject:date:message-id :reply-to; bh=o9pq2FYeJqKIzHZBODKgIJ4xCnulDhV4vBp41eJFOEo=; b=HgqsFLjBLfpvUEnQTNUmKyaS7rN6Vmhuc+ZPw92tpXqE016O/4K4zX/BggFkLPT3v7 Wk1iVPK+KrdsfE8DlfOmdILIeBpjPCj9fjoxExvAJ0O4GjKEWhCxuYn9rEWZ8Iz5l+lK aHZFqWPTYjgkSSV6i9kH8TH8L9gcvGSMg4+ZE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717112614; x=1717717414; h=content-transfer-encoding:mime-version:references:in-reply-to:date :subject:cc:to:from:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=o9pq2FYeJqKIzHZBODKgIJ4xCnulDhV4vBp41eJFOEo=; b=hWF2nErw5ahldIZckL6KjnkSNALbYuac+p9RuJ6LXuMmEEIVCWrnJtrF3SXr8CBV9h Q7VwkdhI7679dwl9lYWfyyQImbj4h75yFPSyyaAKEZmGCCOUJ6AXrKglu2ahbGsqoNRf UpoBfNOxp6nde/o7OlQ80WVt3+a3kT3F0xrTnZAWJRqMNcHcWb9glr2rsm75CSN6H91M hMVCArd/L+ncnqXubyOPJbobiMTU8DeHDvS3sbc3dCH3jxCJAqafmBGVHPSMqdLS0VSo MJ0uh9nLNbgq3dxoYgwWOx3dCZrLsQijRFzWOWcfYAMSOiTFbziyMX3JyFIMvWjozG+9 i/Uw== X-Forwarded-Encrypted: i=1; AJvYcCX5/v7vzTMUea8bcI+V2bmcywRQi9I3aTPtBRTPHTkjXXDwg8JqNTb9cL3J9CKPFytC26jRjBKG7TOUuAc6JZ9dS8WinjTs1AiC X-Gm-Message-State: AOJu0YxqCjRbmNIiYrkzrp+NuCb24o702PHyGxpUKFsgv/K/nurzoIFR 2tlfM+HhGmM+6QeLsqPCwfL2DGpkwd1+n8YZf1RlepLDPGhZ8BnoztQnQnBsNg== X-Google-Smtp-Source: AGHT+IFzh5XzJPXNr+dYh9ZG2MQMwUQ4xDLkV3daefC9PB62bsOX5ogl4Mw9hYuGxSfZLlxDMNS2jg== X-Received: by 2002:a17:902:e5d0:b0:1f6:d4b:350c with SMTP id d9443c01a7336-1f6370ba643mr3254985ad.56.1717112613789; Thu, 30 May 2024 16:43:33 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:564b:72b6:4827:cf6a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f632416d90sm3459275ad.285.2024.05.30.16.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 16:43:33 -0700 (PDT) Message-ID: <66590f25.170a0220.8b5ad.1752@mx.google.com> X-Google-Original-Message-ID: <20240530164304.REPOST net-next.2.Ic039534f7590752a2c403de4ac452e3cb72072f4@changeid> From: Douglas Anderson To: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Hayes Wang Cc: danielgeorgem@google.com, Douglas Anderson , Andrew Lunn , Grant Grundler , Heiner Kallweit , linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH REPOST net-next 2/2] r8152: Wake up the system if the we need a reset Date: Thu, 30 May 2024 16:43:09 -0700 X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog In-Reply-To: <20240530164304.REPOST net-next.1.Ibeda5c0772812ce18953150da5a0888d2d875150@changeid> References: <20240530164304.REPOST net-next.1.Ibeda5c0772812ce18953150da5a0888d2d875150@changeid> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If we get to the end of the r8152's suspend() routine and we find that the USB device is INACCESSIBLE then it means that some of our preparation for suspend didn't take place. We need a USB reset to get ourselves back in a consistent state so we can try again and that can't happen during system suspend. Call pm_wakeup_event() to wake the system up in this case. Signed-off-by: Douglas Anderson Acked-by: Hayes Wang --- drivers/net/usb/r8152.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 6a3f4b2114ee..09fe70bc45d4 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -8647,6 +8647,13 @@ static int rtl8152_system_suspend(struct r8152 *tp) tasklet_enable(&tp->tx_tl); } + /* If we're inaccessible here then some of the work that we did to + * get the adapter ready for suspend didn't work. Queue up a wakeup + * event so we can try again. + */ + if (test_bit(RTL8152_INACCESSIBLE, &tp->flags)) + pm_wakeup_event(&tp->udev->dev, 0); + return 0; }