Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2467382imw; Wed, 6 Jul 2022 06:30:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sVWWsIHi/KSonPT5hzuduUIy0LusVBXLn2VkBb3CKfmU8Iuyw7o7alvstuZM3NaOUFwbJ/ X-Received: by 2002:a05:6a00:1a16:b0:528:692e:6637 with SMTP id g22-20020a056a001a1600b00528692e6637mr16726999pfv.69.1657114244627; Wed, 06 Jul 2022 06:30:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657114244; cv=none; d=google.com; s=arc-20160816; b=mmx2DQO2b6c0UDKgQ6VADIz/H9sZZR2ufThyd/y/KJNOWqmSu97hY4G0/FRDG0thuU C/nTqvId6l2bZF9a4qu4QEri9vq+74jRjGpP9OI32pKyMI9PQXm50F2AzhjN+HIIXgRs fRLlmUZ+SvoaNg+e0lR9XofNszveA3hlQmIGGXNybaqlP8cwxO7iMEBEIsCwI4pL/3bH LJ+h5+Vo4vIbqqBNeXZ6fwcTd4UPhgSytQnpKbTPwnn95MAXAM8L/1RoRXRKlL6ssjtK NA5zgeGitGNz8lXODB3sugB3YyVdsy8TZsuymV5NymizY4ZbZUiEiIblYWz344rAbet6 Ivug== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Ij7XJmC/+XwLc9RCA+8oEtzYP6f2opNzC/i7DALyxf4=; b=Y6AGTHBMmjISCg//w7p8eUXAH6AaxqVxrCAlB5uP1sk5ICadu0Ap2jom4tpwWDsF6+ ibm7EuA0d3s9777VYNP3YnWXk9QBYfkpiuVhLGGdrnJX34UQ0lZeBPWQEttLma2HGCKO gkxs5q3hukblDeTuGiAUzLE9+YjseAj27/bXJCSbpSnr2IXg3iRMVM53hsziDcncdNtb 7LK5G3tLVP5+yRatCViwMbgaKvyT1QmneRsYan3WlF2StZzRSoACY6I0IdBomtznM72X WSyz7tOmgnzOXiu1LGVVUSbm4HhJwPrk4ydSQYk0DWOJwltTyFixm6sQNIR63U3YxQcY twlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=N4a6WjFi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bk13-20020a056a02028d00b004126975f09bsi4671978pgb.435.2022.07.06.06.30.32; Wed, 06 Jul 2022 06:30:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=N4a6WjFi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233204AbiGFMdr (ORCPT + 99 others); Wed, 6 Jul 2022 08:33:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231690AbiGFMdp (ORCPT ); Wed, 6 Jul 2022 08:33:45 -0400 Received: from smtp-relay-canonical-0.canonical.com (smtp-relay-canonical-0.canonical.com [185.125.188.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D399EE04; Wed, 6 Jul 2022 05:33:44 -0700 (PDT) Received: from localhost.localdomain (unknown [10.101.196.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id B0CE441692; Wed, 6 Jul 2022 12:33:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1657110822; bh=Ij7XJmC/+XwLc9RCA+8oEtzYP6f2opNzC/i7DALyxf4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=N4a6WjFi3HaggQEMc5n/WBnTOkNwycKmXj7W+LLP5Rz4J6dVDd4GLV4FnHAMculYC cux0bvryXmlasULy+7Ni9LuvBbB09oxeyf4PtCJ11nrfllWO6VjAzTY0E7hVhS6fTj mF9YuPnDu5IbgC4fMrGQ66QYwUe1lD1ON/SsBfDVOU0gsUYPpC+D6/pwCQf3sidhgN gMcz/yzneo98haN2J7DDew4Fp1jcFHQa9QGKotyzD53fKVctPFqeNr26BAyGRfEcgc G+LLBsrfRdZpnGuSazTS3bx06e/rGcnnuK6CU7zjmzTSZc8PXr9KwieRTL/P62FYaD mDLAdryM+I2Qg== From: Kai-Heng Feng To: bhelgaas@google.com Cc: mika.westerberg@linux.intel.com, koba.ko@canonical.com, Kai-Heng Feng , "David E . Box" , Sathyanarayanan Kuppuswamy , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] PCI: Disable upstream port PTM during suspend Date: Wed, 6 Jul 2022 20:32:44 +0800 Message-Id: <20220706123244.18056-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Intel Alder Lake platforms, Thunderbolt entering D3cold can cause some errors reported by AER: pcieport 0000:00:1d.0: AER: Uncorrected (Non-Fatal) error received: 0000:00:1d.0 pcieport 0000:00:1d.0: PCIe Bus Error: severity=Uncorrected (Non-Fatal), type=Transaction Layer, (Requester ID) pcieport 0000:00:1d.0: device [8086:7ab0] error status/mask=00100000/00004000 pcieport 0000:00:1d.0: [20] UnsupReq (First) pcieport 0000:00:1d.0: AER: TLP Header: 34000000 08000052 00000000 00000000 thunderbolt 0000:0a:00.0: AER: can't recover (no error_detected callback) xhci_hcd 0000:3e:00.0: AER: can't recover (no error_detected callback) pcieport 0000:00:1d.0: AER: device recovery failed In addition to that, it can also block system from suspending when a Thunderbolt dock is attached to the same system. The original approach [1] is to disable AER and DPC when link is in L2/L3 Ready, L2 and L3, but Bjorn identified the root cause is the Unsupported Request: - 08:00.0 sent a PTM Request Message (a Posted Request) - 00:1d.0 received the PTM Request Message - The link transitioned to DL_Down - Per sec 2.9.1, 00:1d.0 discarded the Request and reported an Unsupported Request - Or, per sec 6.21.3, if 00:1d.0 received a PTM Request when its own PTM Enable was clear, it would also be treated as an Unsupported Request And further: 'David did something like this [1], but just for Root Ports. That looks wrong to me because sec 6.21.3 says we should not have PTM enabled in an Upstream Port (i.e., in a downstream device like 08:00.0) unless it is already enabled in the Downstream Port (i.e., in the Root Port 00:1d.0).' So also disable upstream port PTM to make the PCI driver conform to the spec and solve the issue. [1] https://lore.kernel.org/all/20220408153159.106741-1-kai.heng.feng@canonical.com/ [2] https://lore.kernel.org/all/20220422222433.GA1464120@bhelgaas/ Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=215453 Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=216210 Suggested-by: Bjorn Helgaas Cc: David E. Box Cc: Sathyanarayanan Kuppuswamy Signed-off-by: Kai-Heng Feng --- drivers/pci/pci.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index cfaf40a540a82..8ba8a0e12946e 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -2717,7 +2717,8 @@ int pci_prepare_to_sleep(struct pci_dev *dev) * port to enter a lower-power PM state and the SoC to reach a * lower-power idle state as a whole. */ - if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) + if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT || + pci_pcie_type(dev) == PCI_EXP_TYPE_UPSTREAM) pci_disable_ptm(dev); pci_enable_wake(dev, target_state, wakeup); @@ -2775,7 +2776,8 @@ int pci_finish_runtime_suspend(struct pci_dev *dev) * port to enter a lower-power PM state and the SoC to reach a * lower-power idle state as a whole. */ - if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) + if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT || + pci_pcie_type(dev) == PCI_EXP_TYPE_UPSTREAM) pci_disable_ptm(dev); __pci_enable_wake(dev, target_state, pci_dev_run_wake(dev)); -- 2.36.1