From patchwork Mon May 20 20:41:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13668657 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 564C913A3EC for ; Mon, 20 May 2024 20:41:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716237720; cv=none; b=uQ+eC8xxIW/PTCFq2k/9xjIXp8Ym+3PruQe/czDq8BoKwWRebjumN7MiAHSU4OUdiNaoieSTeo3flPeY1UQznwtF8Lct/5Moo+jf0/JOMi8ycJYS82h6IcKRJy24kCrwUpe6q52m6qiQuj6aj6R8E5eq1jw4qQEdNH1C0XPEmf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716237720; c=relaxed/simple; bh=KLAoNg3lNimMGEM1iK1E2E71QyftAe7H7PKPd5zQpd0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=YfMenHP3H6iS4Tx6ulQoR+OV9YjXG+vWzgotd+D5Z62tQahRPlQj8tm2i9lETE+J5bd0tNNtnAYmEfsD0+8uY+6Ut/5BZPht4ulhDk6Ggdd+SB1TdBHiEZVu5nGpqMkE2w6WfXRz4px+V5bwtJoQGG+Xz6IwYr04gbeXAUnnLr4= 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=c5qDFkTd; arc=none smtp.client-ip=209.85.214.177 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="c5qDFkTd" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1ed835f3c3cso20662875ad.3 for ; Mon, 20 May 2024 13:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1716237717; x=1716842517; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=P7tYjQOKUhhyypRv+20xcgSB/ZPEIGDyWUW6MmS8mUM=; b=c5qDFkTdGW/PkzxKKeC19A10gpemAfXqRD6QFIiBGcrWjQH1Yk+DMgRZ3sUkWVjUvl uLnSjKX+gueJ2JS0QjrZNiYu46IoGMT9W2buQcHovUkMTpVVJET65QI083rLJGQheHly WwaDX5m+tO054qE1Ukf/NgHLlcam90K0hLJGQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716237717; x=1716842517; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=P7tYjQOKUhhyypRv+20xcgSB/ZPEIGDyWUW6MmS8mUM=; b=GF4q/JwOo94yVA29fAF70/HT433SxA99HJ7gSAV5birjPO7ESkuo22ObOGNoYl9tse FKMlTnO3hbg4PzMz2JoSa1i1f+DfGaiJPivb3zc1zmgpASIFyc4j05OE9l7wZRc6CedW TR0suXY9a8dNqHhwn9joIRVLqiP5EvUE7Htyn1UfWYPVVQz8Jopg99jev+J/wp6i477h NB2Fhmx5QKio1f6HH8/T1c6TNhNK5iVm9jjDSuaCr36pvHMmnmLcev3MlEHcCyPJxHcA YyQ0nbRwxmUH9n3Q4nBjCpxDmoVrvY+wRrPNoj44d0WUTariYmgHS3bRT3eLxhnP1ycF Xyeg== X-Forwarded-Encrypted: i=1; AJvYcCXnhV9WyCJXwu7ngz4Uh5+8z91h7fm8Ja9RVt0isrPm2iggWwv25HQjpRf2mmdngA3rzXdJX0tohIQg7Po1TemiaKjy8Iz5 X-Gm-Message-State: AOJu0YwldmdMG1Au8Iyn3hCgO2qWBqZWS2EXo3yCLnFG+PjQvKHrg5Nd bjKv3OrVKqu7eKr0iOcgIP0e/LTdkz2UVH+gLQLjdvKHLRL+7UupPh5ROXZ6ww== X-Google-Smtp-Source: AGHT+IGUEKmCgcmIHfXp6npZuZGjuJx5A/FAe7BpLxOGHhZPiMoBvbnihDQpbFMwZRHpWh2syWfS+Q== X-Received: by 2002:a17:902:e54d:b0:1f3:590:71d9 with SMTP id d9443c01a7336-1f3059073f7mr34219075ad.2.1716237717581; Mon, 20 May 2024 13:41:57 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:cd20:112a:72ca:4425]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bbde9d7sm213068255ad.106.2024.05.20.13.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 13:41:57 -0700 (PDT) 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 net-next 1/2] r8152: If inaccessible at resume time, issue a reset Date: Mon, 20 May 2024 13:41:11 -0700 Message-ID: <20240520134108.net-next.1.Ibeda5c0772812ce18953150da5a0888d2d875150@changeid> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 --- 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 Mon May 20 20:41:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 13668658 X-Patchwork-Delegate: kuba@kernel.org 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 5297313A407 for ; Mon, 20 May 2024 20:42:00 +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=1716237722; cv=none; b=AnxeLqXvIZ0iAE2cPiFvIoOaVNSeab3CRThs+0WhS2Axjh7nWgZxraY/39ISkfVQyBXfch2Xwpq2KOR2Sgti5RW9rgsTrSkr7XWK1anhbtjcTXJE+7SGU1SrYOUPBOP7ef9YTO16/cpYskXmUsTLllheLjRTQO4daAS5HlWY+Do= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716237722; c=relaxed/simple; bh=KH7KLt1vLHj8lAyyx8nEvtd9Ch2hZ4E0zERhgbKhEpo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mKbtKHhtNZ8MnT68kIwV1aVJizPJB1E6YTd42yitHmvowE7a5pR8TG9+JN772mgizdgB/38xA65ovvIw4trmWeOjAIuh2Fa9SRrdsTC6hYCcFkkilIxrcfhLnSzcHD2MVi9odKSSa8JFdBLrZIQHmmqpaeElmYRd+UL3n4i5G9c= 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=IM2hdUYB; 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="IM2hdUYB" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1ee954e0aa6so57424535ad.3 for ; Mon, 20 May 2024 13:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1716237719; x=1716842519; 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=EAPtcTBq5rQklg7My1+KHMw3K3I6I7ZSFTklmvsLyz8=; b=IM2hdUYB3iWRPBR7kgABs1XQxgueTzVDUdNmzbFAYE7m7OZAFVOcUSoDbrAA7yTqM7 zc+c5geP7Q/Cj6TKfe9YOtcrYCsOq7d2oOLKxxnvp6yA7q3WPjdeEKAJGsKVKiGcsRmk Waoz7RNRxB/ZWK654A1OXFr8jYXHTxHLnmiNE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716237719; x=1716842519; 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=EAPtcTBq5rQklg7My1+KHMw3K3I6I7ZSFTklmvsLyz8=; b=fHRKNt53N6tloeThlZaDGhKEHUNApkgKWmL+xrLoTBQp227+aSu+jNri1UkvEX9vVb 68YgRcFckJTX1t9dxu8K7cZIPDdczNz9S4h0rKOjNHdYurHJ/Y9+VbpWLxdX7n6CxYjz 1BFHrGWIDleZ5CPB/mp2thcxE4/yBKFngMHnUv+3Mj9A7xa7zxOkoHg3WwBghzzQtta9 hIGnTPh4hlLMLXQmiF0hmnDiMZW2rPOatib18xDgqAKzTxP0jAZIYuTktagoUdZp7zal FpHu1cyn2lMvyxvOPsGn09oIvJ4KKmT9BBSKcb/FWY0HCkSis4wVF+YusAc2+6/J6KA3 NFLg== X-Forwarded-Encrypted: i=1; AJvYcCX3RDQUd9EE+XzUz4bbUw+orVEJBCettuaQQN6OF5GywWRclAGP5mJbwd4afzQEqRYCnmTJLhgq+SUyeik+sTUUcbtSLDUW X-Gm-Message-State: AOJu0YwEyEynP2phcaY+8r4k6YzJj8TD3jvoM8mCSq4iAYw7xOogY8v/ fLpuQepitpWcre3UlZ1cIDZx6U52bEZru43euzf1W4s5R/lEl2y3KsaWw4vWzQgkeC4bd4sFyzQ = X-Google-Smtp-Source: AGHT+IGox8QB8PBU2tVVtMM4gyfbOeKz51VVq/e4AHSre+WZ4yCg3glyJBr+5bnclNzM/WQaC0MSjg== X-Received: by 2002:a17:902:64d6:b0:1e4:5b89:dbfa with SMTP id d9443c01a7336-1f065fde55bmr228544205ad.41.1716237719595; Mon, 20 May 2024 13:41:59 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:cd20:112a:72ca:4425]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bbde9d7sm213068255ad.106.2024.05.20.13.41.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 13:41:58 -0700 (PDT) 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 net-next 2/2] r8152: Wake up the system if the we need a reset Date: Mon, 20 May 2024 13:41:12 -0700 Message-ID: <20240520134108.net-next.2.Ic039534f7590752a2c403de4ac452e3cb72072f4@changeid> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog In-Reply-To: <20240520134108.net-next.1.Ibeda5c0772812ce18953150da5a0888d2d875150@changeid> References: <20240520134108.net-next.1.Ibeda5c0772812ce18953150da5a0888d2d875150@changeid> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 --- 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; }