Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5487870rwp; Mon, 17 Jul 2023 05:10:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlE72bvCYFdULGwFgFV+zQnygspxy3JaLkFvDZhY98UDOlO6jPKFPibjg2zlxbvMv8XDwPB4 X-Received: by 2002:a05:6402:164d:b0:51e:eba:55ba with SMTP id s13-20020a056402164d00b0051e0eba55bamr9725144edx.32.1689595851645; Mon, 17 Jul 2023 05:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689595851; cv=none; d=google.com; s=arc-20160816; b=O9tFPM/ZhEfQjKUCJBF+4hivA0YR8cd9AaX5YLsQyc99IiCtBzRZ+cmUKcZWlcz0gS BQx42P4MRex0P4nAqP++MhbxtnVGr2evFThPGQqyPrxFrer1/ST9h5/9Hv0GtqfrOKFo 7njYOFvB6fZ33Do7a7dPd9VFtngeleQb+KQK4xlbiPyD76p5e/p14LTbZbhIXzG7czaD zipj9jTvueVt/NsUzi2/9JoakJdRSze7hX41DxBpvYxhoGO7v+pX+OeH+RkW9kbDlwil vmM8JXpfRmZObV/fbC/nUP/IOXoyBFzOCZVarkQjhoaWdAW0eotlGzApZQegd7EsKkE8 Sjrw== 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=7vC2gLsqw4ZVczATEn/TH2VSaFwYpcTfhgh6Dzndk5k=; fh=QKw3joX01JEjx8KVsukA1EMqm0RR5E5JNjvmDaqkmZk=; b=bysRbAM+NQegJxaD8p12IZMegcRjJsPdMIr8pWM9ObOwX0XLi93rk8Q6t+OB3nTm3+ 6qoABhjdglnwU14hMNnEA020IpnFmMBdHtJHbNOG2kOClu/6PycTyx2+9V8tPIzTF/R+ IbgAOO3NyIsZAjTyvc0CGTUMGCgu56mknDzUslsNr7Yoxy7Sx0D68sFkwLnP5IdV/NV7 eaKG0sglMWMcXE48ul+uv4gDKimihmL+0hnsHsLgBCNZlVZddoW2F2JJiZXXYWV3twLC eAHp0saBzx7DWuAzaL8rOHhQa/FFHkjLT6f7Pya1FkqmEXl7OgxC3AbS60Zq9x33aiMO wxkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=F7Wl3my3; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020aa7da4e000000b00521937ee981si1379295eds.402.2023.07.17.05.10.27; Mon, 17 Jul 2023 05:10:51 -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=@intel.com header.s=Intel header.b=F7Wl3my3; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231157AbjGQMFy (ORCPT + 99 others); Mon, 17 Jul 2023 08:05:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230527AbjGQMFu (ORCPT ); Mon, 17 Jul 2023 08:05:50 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CC9B132; Mon, 17 Jul 2023 05:05:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689595543; x=1721131543; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w9fmnbavpFPn2k6FB22LLTiMoKztUNTZBdmD34m58vg=; b=F7Wl3my33DSmAvl35xhf9f+rbOa03e9DD/o5wyRFvDpG4WAbJnd+81pU ON/LmFOINlb+dQCfrr6FnmWvqL6bHJ95Gph/E/zRdH656oYSsuu/QYPYq c3RZ74Tl9d552SsogE4XMrmj6+vV1w3N3XlGzEwmtUbXpTIQQbepVA0kh o/toSO5MuKDsbykL2sc6C6sKIKqQsuR6DBb1k/2G2T63MUJubnvCPdZ7l MXh6CPaVJx4J/iqfXdKE0UUjeZuFrHjsH7R9nlbVVNIoeemsbIxzqojTQ zKRocwuBrmDEIdkhT90xPA9QHmvFKph/lwMExYfQ2E45Fo8ZQoCBluIjF A==; X-IronPort-AV: E=McAfee;i="6600,9927,10773"; a="432081530" X-IronPort-AV: E=Sophos;i="6.01,211,1684825200"; d="scan'208";a="432081530" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2023 05:05:43 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10773"; a="752875926" X-IronPort-AV: E=Sophos;i="6.01,211,1684825200"; d="scan'208";a="752875926" Received: from dkravtso-mobl1.ccr.corp.intel.com (HELO ijarvine-mobl2.ger.corp.intel.com) ([10.252.45.233]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2023 05:05:38 -0700 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= To: linux-pci@vger.kernel.org, Bjorn Helgaas , Lorenzo Pieralisi , Rob Herring , =?UTF-8?q?Krzysztof=20Wilczy=C5=84ski?= , Emmanuel Grumbach , "Rafael J . Wysocki" , Heiner Kallweit , Lukas Wunner , Andy Shevchenko , =?UTF-8?q?Stefan=20M=C3=A4tje?= , Greg Kroah-Hartman , Shaohua Li , linux-kernel@vger.kernel.org Cc: Dean Luick , =?UTF-8?q?Jonas=20Dre=C3=9Fler?= , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , stable@vger.kernel.org Subject: [PATCH v5 02/11] PCI: Make link retraining use RMW accessors for changing LNKCTL Date: Mon, 17 Jul 2023 15:04:54 +0300 Message-Id: <20230717120503.15276-3-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230717120503.15276-1-ilpo.jarvinen@linux.intel.com> References: <20230717120503.15276-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 Don't assume that the device is fully under the control of PCI core. Use RMW capability accessors in link retraining which do proper locking to avoid losing concurrent updates to the register values. Fixes: 4ec73791a64b ("PCI: Work around Pericom PCIe-to-PCI bridge Retrain Link erratum") Fixes: 7d715a6c1ae5 ("PCI: add PCI Express ASPM support") Suggested-by: Lukas Wunner Signed-off-by: Ilpo Järvinen Acked-by: Rafael J. Wysocki Cc: stable@vger.kernel.org --- pci/enumeration branch moves the link retraining code into PCI core and also conflicts with a link retraining fix in pci/aspm. The changelog (and patch splitting) takes the move into account by not referring to ASPM while the change itself is not based on pci/enumeration (as per Bjorn's preference). --- drivers/pci/pci.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 60230da957e0..f7315b13bb82 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4927,7 +4927,6 @@ static int pcie_wait_for_link_status(struct pci_dev *pdev, int pcie_retrain_link(struct pci_dev *pdev, bool use_lt) { int rc; - u16 lnkctl; /* * Ensure the updated LNKCTL parameters are used during link @@ -4939,17 +4938,14 @@ int pcie_retrain_link(struct pci_dev *pdev, bool use_lt) if (rc) return rc; - pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &lnkctl); - lnkctl |= PCI_EXP_LNKCTL_RL; - pcie_capability_write_word(pdev, PCI_EXP_LNKCTL, lnkctl); + pcie_capability_set_word(pdev, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_RL); if (pdev->clear_retrain_link) { /* * Due to an erratum in some devices the Retrain Link bit * needs to be cleared again manually to allow the link * training to succeed. */ - lnkctl &= ~PCI_EXP_LNKCTL_RL; - pcie_capability_write_word(pdev, PCI_EXP_LNKCTL, lnkctl); + pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, PCI_EXP_LNKCTL_RL); } return pcie_wait_for_link_status(pdev, use_lt, !use_lt); -- 2.30.2