From patchwork Thu Apr 7 17:17:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1614576 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KZ7PK4Tz7z9sG5 for ; Fri, 8 Apr 2022 03:17:56 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ncVlS-0003J7-VK; Thu, 07 Apr 2022 17:17:46 +0000 Received: from mail-pl1-f173.google.com ([209.85.214.173]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ncVlR-0003Id-Pd for kernel-team@lists.ubuntu.com; Thu, 07 Apr 2022 17:17:45 +0000 Received: by mail-pl1-f173.google.com with SMTP id n9so5582521plc.4 for ; Thu, 07 Apr 2022 10:17:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hyAPSBCvGd7cLHSZRr8RIN4B/2Ez04hGK/EjSJ+vPLc=; b=0UA6MouInTUC9JwrcbN5icr360T4nMrQ0IEvLuqmXRiSZfNKRzz2R8yuAav0aFoEe1 vN8Egne3Ezc1flr7/9L1QMEr6aD4O/2ohYzt0ilfkg0ZDH9XFvk7pq+g7l5JJcjhIYOh 63EJrlLNGYQ/w9cEhJfFXOLJhsHEuI9u0GQxSrYWKj8qE/0EzFzMaDuc4nRoLZsv91MK Aki5wZzH4I42sMMs55pIGxzeIjvmSzJvTLfd32VmhjW7X67sBs2VsKEv0RCGLTctnF5s 8uX5rVHumFKGtMd3a35s81MoSQaKskTFAKgxpAw6dia8uaVd3OX+0gmwZRHifHZXEAJO +RSg== X-Gm-Message-State: AOAM5313CUwVCPwHd5aV90C1m0Q2jQEmF/4W7DPlqoxCZRN9hLhfQQPa wxnCXRm3GGf5kpRpC9KbF5oJ+NaFuGc= X-Google-Smtp-Source: ABdhPJzgaMLwFQlpnqxv0GwOOJnsLNV6BYwxwamGG39wYUD2iz9M3uYk0GazyB9OsGe6KgVcZDyWQQ== X-Received: by 2002:a17:90a:5d08:b0:1ca:8aab:20c8 with SMTP id s8-20020a17090a5d0800b001ca8aab20c8mr16903198pji.172.1649351863622; Thu, 07 Apr 2022 10:17:43 -0700 (PDT) Received: from localhost (114-40-204-238.dynamic-ip.hinet.net. [114.40.204.238]) by smtp.gmail.com with ESMTPSA id bx22-20020a056a00429600b004fa936a64b0sm21474219pfb.196.2022.04.07.10.17.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 10:17:43 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/4][SRU][Jammy/Unstable/OEM-5.17] thunderbolt: Retry DROM reads for more failure scenarios Date: Fri, 8 Apr 2022 01:17:35 +0800 Message-Id: <20220407171739.1176275-2-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220407171739.1176275-1-vicamo.yang@canonical.com> References: <20220407171739.1176275-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.214.173; envelope-from=vicamo@gmail.com; helo=mail-pl1-f173.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Mario Limonciello BugLink: https://bugs.launchpad.net/bugs/1962349 Currently DROM reads are only retried in the case that parsing failed. However if the size or CRC fails, then there should also be a retry. This helps with reading the DROM on TBT3 devices connected to AMD Yellow Carp which will sometimes fail on the first attempt. Signed-off-by: Mario Limonciello Signed-off-by: Mika Westerberg (cherry picked from commit e87491a9fd4e33eaf18ef69d8295bb07b31452b2 linux-next) Signed-off-by: You-Sheng Yang --- drivers/thunderbolt/eeprom.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/thunderbolt/eeprom.c b/drivers/thunderbolt/eeprom.c index 470885e6f1c8..10cdbcb55df9 100644 --- a/drivers/thunderbolt/eeprom.c +++ b/drivers/thunderbolt/eeprom.c @@ -553,9 +553,9 @@ static int tb_drom_parse(struct tb_switch *sw) crc = tb_crc8((u8 *) &header->uid, 8); if (crc != header->uid_crc8) { tb_sw_warn(sw, - "DROM UID CRC8 mismatch (expected: %#x, got: %#x), aborting\n", + "DROM UID CRC8 mismatch (expected: %#x, got: %#x)\n", header->uid_crc8, crc); - return -EINVAL; + return -EILSEQ; } if (!sw->uid) sw->uid = header->uid; @@ -654,6 +654,7 @@ int tb_drom_read(struct tb_switch *sw) sw->drom = kzalloc(size, GFP_KERNEL); if (!sw->drom) return -ENOMEM; +read: res = tb_drom_read_n(sw, 0, sw->drom, size); if (res) goto err; @@ -662,7 +663,11 @@ int tb_drom_read(struct tb_switch *sw) header = (void *) sw->drom; if (header->data_len + TB_DROM_DATA_START != size) { - tb_sw_warn(sw, "drom size mismatch, aborting\n"); + tb_sw_warn(sw, "drom size mismatch\n"); + if (retries--) { + msleep(100); + goto read; + } goto err; } @@ -683,11 +688,9 @@ int tb_drom_read(struct tb_switch *sw) /* If the DROM parsing fails, wait a moment and retry once */ if (res == -EILSEQ && retries--) { - tb_sw_warn(sw, "parsing DROM failed, retrying\n"); + tb_sw_warn(sw, "parsing DROM failed\n"); msleep(100); - res = tb_drom_read_n(sw, 0, sw->drom, size); - if (!res) - goto parse; + goto read; } if (!res) From patchwork Thu Apr 7 17:17:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1614574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KZ7PK4XkRz9sGZ for ; Fri, 8 Apr 2022 03:17:56 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ncVlW-0003KT-48; Thu, 07 Apr 2022 17:17:50 +0000 Received: from mail-pf1-f170.google.com ([209.85.210.170]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ncVlT-0003J6-P6 for kernel-team@lists.ubuntu.com; Thu, 07 Apr 2022 17:17:47 +0000 Received: by mail-pf1-f170.google.com with SMTP id s8so6009971pfk.12 for ; Thu, 07 Apr 2022 10:17:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YIGBneODLI9RJHi/4OC4hwXRqAUVxi8f5REpzHCt7fI=; b=wnbAm07mIIOxd71t+yKYDXVeOIDxlCqjpluRAulwLQgAVtV0jYkHpFns0ds2NtDwk3 MtfGXtiCdZvGivllYabgAu3Hn2kFyb4CeYiqtenAbDitiT3fX9iSLHu8+DLTRss8W4Mu lNHxVi8l0+zUK6BNMhMheXV9qUEtNrtwxO3K0YW2K48qKB4OXHjFFjN7OxRqpHc8JwDy wcOKlibhSAQh41jyR5pinvWq73JG6yBuqkDjaYfOKjoQIVA0U29PxfZesI6CJZ/ZONsu 9fGVG6k89wHaiIdJxPM4DfO0RUoba8dzhglKsFZjrwakCU7bKRaVex5erCA1pR+Ozl52 RJiA== X-Gm-Message-State: AOAM532pA/LvuZPCW4w/185/Cy88BrIvMvIMg7n9rhcyzxu6dl91quQN 65qbLmh4oEHBJD5/Ih7Tt22dSw032Fs= X-Google-Smtp-Source: ABdhPJyy2C1TxgGbKY2gZ7fqAJyGfZZhNUNtrtXDAOmCW0V84vMbKL3NKRuF0igylx2VSSRJ8A4q3g== X-Received: by 2002:a63:fb44:0:b0:372:9ec8:745a with SMTP id w4-20020a63fb44000000b003729ec8745amr11945914pgj.551.1649351865655; Thu, 07 Apr 2022 10:17:45 -0700 (PDT) Received: from localhost (114-40-204-238.dynamic-ip.hinet.net. [114.40.204.238]) by smtp.gmail.com with ESMTPSA id 204-20020a6302d5000000b00385f29b02b2sm19923853pgc.50.2022.04.07.10.17.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 10:17:45 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/4][SRU][Jammy/Unstable/OEM-5.17] thunderbolt: Do not resume routers if UID is not set Date: Fri, 8 Apr 2022 01:17:36 +0800 Message-Id: <20220407171739.1176275-3-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220407171739.1176275-1-vicamo.yang@canonical.com> References: <20220407171739.1176275-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.210.170; envelope-from=vicamo@gmail.com; helo=mail-pf1-f170.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Mario Limonciello BugLink: https://bugs.launchpad.net/bugs/1962349 Routers might not have a UID set if the DROM read failed during initialization previously. Normally upon resume the UID is re-read to confirm it's the same device connected. * If the DROM read failed during init but then succeeded during resume it could either be a new device or faulty device * If the DROM read failed during init and also failed during resume it might be a different device plugged in all together. Detect this situation and prevent re-using the same configuration in these cirucmstances. Signed-off-by: Mario Limonciello Signed-off-by: Mika Westerberg (cherry picked from commit a283de3ec646f19b09f3c8e4c8f57c0e017c9b2b linux-next) Signed-off-by: You-Sheng Yang --- drivers/thunderbolt/switch.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index 13f9230104d7..308f88fb6a30 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -2927,6 +2927,10 @@ int tb_switch_resume(struct tb_switch *sw) return err; } + /* We don't have any way to confirm this was the same device */ + if (!sw->uid) + return -ENODEV; + if (tb_switch_is_usb4(sw)) err = usb4_switch_read_uid(sw, &uid); else From patchwork Thu Apr 7 17:17:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1614573 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KZ7PK3qgKz9sFt for ; Fri, 8 Apr 2022 03:17:57 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ncVlX-0003LP-B8; Thu, 07 Apr 2022 17:17:51 +0000 Received: from mail-pj1-f51.google.com ([209.85.216.51]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ncVlV-0003Jb-Mr for kernel-team@lists.ubuntu.com; Thu, 07 Apr 2022 17:17:49 +0000 Received: by mail-pj1-f51.google.com with SMTP id n6-20020a17090a670600b001caa71a9c4aso6928146pjj.1 for ; Thu, 07 Apr 2022 10:17:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=alV1UgH18lsJozNoGF1YXFjWEunLtFsoBWw0W9xM2Qk=; b=tPNfayiKAU7YYLouRmzKgVOrSwWEUH+g6lsaIMFxmZLcCvXuvhD+a1EaF2dQuuop7z LDOf+Det4OoTUiG7JkIt1K13XzTcvOpjrVdnh2lfmij63CUKCEeLaio/XRszcVl0co7Y yhEbFY6A+jrx/DXcy6DJWDNmjdU7SNhOhsSos/Vi9lhHpIoIqfV16q9OGaz7dJOZjgMi alefblaHFoTLs98HNJ0Ygt4iOih3FVfm0j2oK/DFjWhyfksYEDCvdQeJ08w6KAKyowuN 3CKHJGLA2CHurZZ1ZxUUvWK9aXOO7ivmWJW6zzaqHRBUUihS+0n7tRFN0OmyQstxIxFA wKww== X-Gm-Message-State: AOAM5310lVG0quTofrWqUyShXbnEE0QcLiUAQ1/3OJWJ4yIY4KQ2WGaO fUz7mQpA8vrc4F2qi4bfM0sajglTARA= X-Google-Smtp-Source: ABdhPJyakCb5GIhiUdLvr5gRXebPXx0P8bR56teYNSOy2ygIG5z7Tm1JgwpENHnokXVSpRhHZjPzpA== X-Received: by 2002:a17:902:e791:b0:151:dbbd:aeae with SMTP id cp17-20020a170902e79100b00151dbbdaeaemr15026677plb.171.1649351867522; Thu, 07 Apr 2022 10:17:47 -0700 (PDT) Received: from localhost (114-40-204-238.dynamic-ip.hinet.net. [114.40.204.238]) by smtp.gmail.com with ESMTPSA id my18-20020a17090b4c9200b001c75aeac7fdsm9630037pjb.27.2022.04.07.10.17.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 10:17:47 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/4][SRU][Jammy/Unstable/OEM-5.17] thunderbolt: Do not make DROM read success compulsory Date: Fri, 8 Apr 2022 01:17:37 +0800 Message-Id: <20220407171739.1176275-4-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220407171739.1176275-1-vicamo.yang@canonical.com> References: <20220407171739.1176275-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.216.51; envelope-from=vicamo@gmail.com; helo=mail-pj1-f51.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Mario Limonciello BugLink: https://bugs.launchpad.net/bugs/1962349 The USB4 specification doesn't make any requirements that reading a device router's DROM is needed for the operation of the device. Other connection manager solutions don't necessarily read it or gate the usability of the device on whether it was read. So make failures when reading the DROM show warnings but not fail the initialization of the router. Signed-off-by: Mario Limonciello Signed-off-by: Mika Westerberg (cherry picked from commit 6915812bbd109787ebdb865561dc9164d4b01f56 linux-next) Signed-off-by: You-Sheng Yang --- drivers/thunderbolt/switch.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c index 308f88fb6a30..fbe2617fde50 100644 --- a/drivers/thunderbolt/switch.c +++ b/drivers/thunderbolt/switch.c @@ -2731,10 +2731,8 @@ int tb_switch_add(struct tb_switch *sw) /* read drom */ ret = tb_drom_read(sw); - if (ret) { - dev_err(&sw->dev, "reading DROM failed\n"); - return ret; - } + if (ret) + dev_warn(&sw->dev, "reading DROM failed: %d\n", ret); tb_sw_dbg(sw, "uid: %#llx\n", sw->uid); tb_check_quirks(sw); From patchwork Thu Apr 7 17:17:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: You-Sheng Yang X-Patchwork-Id: 1614577 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KZ7PN5dlgz9sFt for ; Fri, 8 Apr 2022 03:18:00 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1ncVla-0003Pd-JX; Thu, 07 Apr 2022 17:17:54 +0000 Received: from mail-pg1-f182.google.com ([209.85.215.182]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ncVlX-0003Kh-V7 for kernel-team@lists.ubuntu.com; Thu, 07 Apr 2022 17:17:52 +0000 Received: by mail-pg1-f182.google.com with SMTP id c2so5473198pga.10 for ; Thu, 07 Apr 2022 10:17:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ivyfvm4QvDdeosUL9T3OXmATvIRruVwk8ZuG5mpIv2o=; b=Rxn58c95wA8culce0iLNVL6sr1j5k11c6jwpdagNPzhBm5yRF3mRI9VFphSDQN9o5A KNupilhES5yMtAWrByggG1Ois60aLm82UjKsWw2egDP0aN8xPVNsaVPj8R1KCEVuNNO8 F0AoR/TBBttn/KH6p0Wnb4FbjB0ZybUe0OQeoekeYlWfGI1URtb8cn7qqfJGltjSXzVr VQdR5eaJ8RltXvI6IVv3XNAnqbJ46tQPmf+u7nPCQeXQh9vBq3OkW274Fs3I61VZYYAV Yn+0sYGzaI6ruP51HrDOBdX4zSaUrwmVmQ//7bR8S1Rgqe4wrDiW2qn0RHyk801OThQs 22Gg== X-Gm-Message-State: AOAM532YUDvFNHZBNphaT7kbR/LZtgjqoQT+zpVV3I6bophKFfhGE0uZ Sbbvmu6Q2rUSiDXCSTvRuewifHReeh0= X-Google-Smtp-Source: ABdhPJwdolb/om/gAEuTSYmB7iTuF/00CMVyhDNCOrvUfF+9hdcYoJrnwGtcLui0t9Bzla2GfBc5yQ== X-Received: by 2002:a65:5ac2:0:b0:399:dea:cd1f with SMTP id d2-20020a655ac2000000b003990deacd1fmr12048494pgt.80.1649351869368; Thu, 07 Apr 2022 10:17:49 -0700 (PDT) Received: from localhost (114-40-204-238.dynamic-ip.hinet.net. [114.40.204.238]) by smtp.gmail.com with ESMTPSA id kb13-20020a17090ae7cd00b001c7de069bacsm10007873pjb.42.2022.04.07.10.17.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 10:17:49 -0700 (PDT) From: You-Sheng Yang To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/4][SRU][Jammy] PCI/ACPI: Allow D3 only if Root Port can signal and wake from D3 Date: Fri, 8 Apr 2022 01:17:38 +0800 Message-Id: <20220407171739.1176275-5-vicamo.yang@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220407171739.1176275-1-vicamo.yang@canonical.com> References: <20220407171739.1176275-1-vicamo.yang@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.182; envelope-from=vicamo@gmail.com; helo=mail-pg1-f182.google.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Mario Limonciello BugLink: https://bugs.launchpad.net/bugs/1962349 acpi_pci_bridge_d3(dev) returns "true" if "dev" is a hotplug bridge that can handle hotplug events while in D3. Previously this meant either: - "dev" has a _PS0 or _PR0 method (acpi_pci_power_manageable()), or - The Root Port above "dev" has a _DSD with a "HotPlugSupportInD3" property with value 1. This did not consider _PRW, which tells us about wakeup GPEs (ACPI v6.4, sec 7.3.13). Without a wakeup GPE, from an ACPI perspective the Root Port has no way of generating wakeup signals, so hotplug events will be lost if we use D3. Similarly, it did not consider _S0W, which tells us the deepest D-state from which a device can wake itself (sec 7.3.20). If _S0W tells us the device cannot wake from D3, hotplug events will again be lost if we use D3. Some platforms, e.g., AMD Yellow Carp, supply "HotPlugSupportInD3" without _PRW or with an _S0W that says the Root Port cannot wake from D3. On those platforms, we previously put bridges in D3hot, hotplug events were lost, and hotplugged devices would not be recognized without manually rescanning. Allow bridges to be put in D3 only if the Root Port can generate wakeup GPEs (wakeup.flags.valid), it can wake from D3 (_S0W), AND it has the "HotPlugSupportInD3" property. Neither Windows 10 nor Windows 11 puts the bridge in D3 when the firmware is configured this way, and this change aligns the handling of the situation to be the same. [bhelgaas: commit log, tidy "HotPlugSupportInD3" check and comment] Link: https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/07_Power_and_Performance_Mgmt/device-power-management-objects.html?highlight=s0w#s0w-s0-device-wake-state Link: https://docs.microsoft.com/en-us/windows-hardware/drivers/pci/dsd-for-pcie-root-ports#identifying-pcie-root-ports-supporting-hot-plug-in-d3 Link: https://lore.kernel.org/r/20220401034003.3166-1-mario.limonciello@amd.com Fixes: 26ad34d510a87 ("PCI / ACPI: Whitelist D3 for more PCIe hotplug ports") Signed-off-by: Mario Limonciello Signed-off-by: Bjorn Helgaas Reviewed-by: Rafael J. Wysocki (cherry picked from commit dff6139015dc68e93be3822a7bd406a1d138628b linux-next) Signed-off-by: You-Sheng Yang --- drivers/pci/pci-acpi.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/drivers/pci/pci-acpi.c b/drivers/pci/pci-acpi.c index 260a06fb78a6..813e0d25e841 100644 --- a/drivers/pci/pci-acpi.c +++ b/drivers/pci/pci-acpi.c @@ -976,9 +976,11 @@ static bool acpi_pci_power_manageable(struct pci_dev *dev) static bool acpi_pci_bridge_d3(struct pci_dev *dev) { - const union acpi_object *obj; - struct acpi_device *adev; struct pci_dev *rpdev; + struct acpi_device *adev; + acpi_status status; + unsigned long long state; + const union acpi_object *obj; if (!dev->is_hotplug_bridge) return false; @@ -987,12 +989,6 @@ static bool acpi_pci_bridge_d3(struct pci_dev *dev) if (acpi_pci_power_manageable(dev)) return true; - /* - * The ACPI firmware will provide the device-specific properties through - * _DSD configuration object. Look for the 'HotPlugSupportInD3' property - * for the root port and if it is set we know the hierarchy behind it - * supports D3 just fine. - */ rpdev = pcie_find_root_port(dev); if (!rpdev) return false; @@ -1001,11 +997,34 @@ static bool acpi_pci_bridge_d3(struct pci_dev *dev) if (!adev) return false; - if (acpi_dev_get_property(adev, "HotPlugSupportInD3", - ACPI_TYPE_INTEGER, &obj) < 0) + /* + * If the Root Port cannot signal wakeup signals at all, i.e., it + * doesn't supply a wakeup GPE via _PRW, it cannot signal hotplug + * events from low-power states including D3hot and D3cold. + */ + if (!adev->wakeup.flags.valid) return false; - return obj->integer.value == 1; + /* + * If the Root Port cannot wake itself from D3hot or D3cold, we + * can't use D3. + */ + status = acpi_evaluate_integer(adev->handle, "_S0W", NULL, &state); + if (ACPI_SUCCESS(status) && state < ACPI_STATE_D3_HOT) + return false; + + /* + * The "HotPlugSupportInD3" property in a Root Port _DSD indicates + * the Port can signal hotplug events while in D3. We assume any + * bridges *below* that Root Port can also signal hotplug events + * while in D3. + */ + if (!acpi_dev_get_property(adev, "HotPlugSupportInD3", + ACPI_TYPE_INTEGER, &obj) && + obj->integer.value == 1) + return true; + + return false; } static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)