Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp889195yba; Thu, 18 Apr 2019 11:15:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqy6A1QTTHRnUOO6K+30kIwV5ZaNnIb9rxzebwc0O28s+plNQymhhkvyzOD3NCxEwTng7y1E X-Received: by 2002:a63:da4e:: with SMTP id l14mr85769968pgj.96.1555611331823; Thu, 18 Apr 2019 11:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555611331; cv=none; d=google.com; s=arc-20160816; b=BovVE8Tv843kqZ6rlXaWb+eMnRMF/S1Ec+aLHlbvtXaNkxIH89xkKjI1sui6Wqu9mB 20RW//iqO2vMzGEE0eqHqqjBGj0LOuHUkFcZ1p411+NGu52vOWb+9CXTINbVNxWt03Pq cE4MZRawigxGCiSjyrqmxuAgjXY2KZUUnWOsZ0gZ1/ySgV4CVxNTT2JSvX6Sb+jRIQK9 BmDUl4XYlNpDvugyXv2n9+TljkaO0HTQpHGDmCevUtVe6Vv/MtRtSh0Ww7S6tJWKYGST e4BF06tj+YX2ydbHIfMAUjjxHfx3AKxT/OHSvoncq9kGbHuhQ6MCeBNuf6NwRJ7hyRV+ vlaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xcLwbuTPIgf+RdDBP0KtWYvnGoxu2FDrAygzsanbhj4=; b=pRJqatx0xv7MO1xQ5j3wm7LXy8+9nuXkzewNE4SBtiT0MMXCKgAPrmEbGj2zRMRuMt ASO1+ErBh4tGfYlfnmd20xvfp9r0Krstfborrp5l5fXATuGqebvRy4LEVtMSseTrobH7 i/9gdEAB4E+x5VpXTs7GfYYJYmPzUziWQEek33luW6VAYckN1NIhHtanHCgEjAVdOfZk KmKiCH/MJ1TFdIQD4G4W9mrXDK18eDYW6QvMa+VKbyoqMljSJBLIqYktPryboWeT9R3l MnbbjYnWHwg2HPGvwIOTpgBN3jamLfb3ZKLef9jzLNCoYu5AtGwQKLowUAFE1oi3SgNe 7nCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AMr4RXT0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m63si2803794pld.147.2019.04.18.11.15.17; Thu, 18 Apr 2019 11:15:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AMr4RXT0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404302AbfDRSMc (ORCPT + 99 others); Thu, 18 Apr 2019 14:12:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:45006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404281AbfDRSM3 (ORCPT ); Thu, 18 Apr 2019 14:12:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ACA6920675; Thu, 18 Apr 2019 18:12:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555611149; bh=SEKwVuizM7PcgHmpksIIZh0HPBrRpSX10k3pwBU4kYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AMr4RXT0oWpe7v7+9sIe/PXlf9rfjkRGTY8LnidAyCPnZjealTYJ+/RfxzHk13vKb xZN6vx5TgDWEsUp/EG3CflxmVS2+i+LGTvnnWgL7BpsgSJ1/tzAOHxESbxAtMBdiiJ 83kJ94i8gPMabGIRXk/QdVqcPBZY85Rq/CUe4HoY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bjorn Helgaas , Sasha Levin Subject: [PATCH 5.0 78/93] PCI/ASPM: Save LTR Capability for suspend/resume Date: Thu, 18 Apr 2019 19:57:56 +0200 Message-Id: <20190418160444.948574125@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190418160436.781762249@linuxfoundation.org> References: <20190418160436.781762249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit dbbfadf2319005cf528b0f15f12a05d4e4644303 ] Latency Tolerance Reporting (LTR) allows Endpoints and Switch Upstream Ports to report their latency requirements to upstream components. If ASPM L1 PM substates are enabled, the LTR information helps determine when a Link enters L1.2 [1]. Software must set the maximum latency values in the LTR Capability based on characteristics of the platform, then set LTR Mechanism Enable in the Device Control 2 register in the PCIe Capability. The device can then use LTR to report its latency tolerance. If the device reports a maximum latency value of zero, that means the device requires the highest possible performance and the ASPM L1.2 substate is effectively disabled. We put devices in D3 for suspend, and we assume their internal state is lost. On resume, previously we did not restore the LTR Capability, but we did restore the LTR Mechanism Enable bit, so devices would request the highest possible performance and ASPM L1.2 wouldn't be used. [1] PCIe r4.0, sec 5.5.1 Link: https://bugzilla.kernel.org/show_bug.cgi?id=201469 Signed-off-by: Bjorn Helgaas Signed-off-by: Sasha Levin --- drivers/pci/pci.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 5a94a3cf61cd..e91005d0f20c 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -1233,7 +1233,6 @@ static void pci_restore_pcie_state(struct pci_dev *dev) pcie_capability_write_word(dev, PCI_EXP_SLTCTL2, cap[i++]); } - static int pci_save_pcix_state(struct pci_dev *dev) { int pos; @@ -1270,6 +1269,45 @@ static void pci_restore_pcix_state(struct pci_dev *dev) pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]); } +static void pci_save_ltr_state(struct pci_dev *dev) +{ + int ltr; + struct pci_cap_saved_state *save_state; + u16 *cap; + + if (!pci_is_pcie(dev)) + return; + + ltr = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_LTR); + if (!ltr) + return; + + save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_LTR); + if (!save_state) { + pci_err(dev, "no suspend buffer for LTR; ASPM issues possible after resume\n"); + return; + } + + cap = (u16 *)&save_state->cap.data[0]; + pci_read_config_word(dev, ltr + PCI_LTR_MAX_SNOOP_LAT, cap++); + pci_read_config_word(dev, ltr + PCI_LTR_MAX_NOSNOOP_LAT, cap++); +} + +static void pci_restore_ltr_state(struct pci_dev *dev) +{ + struct pci_cap_saved_state *save_state; + int ltr; + u16 *cap; + + save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_LTR); + ltr = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_LTR); + if (!save_state || !ltr) + return; + + cap = (u16 *)&save_state->cap.data[0]; + pci_write_config_word(dev, ltr + PCI_LTR_MAX_SNOOP_LAT, *cap++); + pci_write_config_word(dev, ltr + PCI_LTR_MAX_NOSNOOP_LAT, *cap++); +} /** * pci_save_state - save the PCI configuration space of a device before suspending @@ -1291,6 +1329,7 @@ int pci_save_state(struct pci_dev *dev) if (i != 0) return i; + pci_save_ltr_state(dev); pci_save_dpc_state(dev); return pci_save_vc_state(dev); } @@ -1390,7 +1429,12 @@ void pci_restore_state(struct pci_dev *dev) if (!dev->state_saved) return; - /* PCI Express register must be restored first */ + /* + * Restore max latencies (in the LTR capability) before enabling + * LTR itself (in the PCIe capability). + */ + pci_restore_ltr_state(dev); + pci_restore_pcie_state(dev); pci_restore_pasid_state(dev); pci_restore_pri_state(dev); @@ -3020,6 +3064,11 @@ void pci_allocate_cap_save_buffers(struct pci_dev *dev) if (error) pci_err(dev, "unable to preallocate PCI-X save buffer\n"); + error = pci_add_ext_cap_save_buffer(dev, PCI_EXT_CAP_ID_LTR, + 2 * sizeof(u16)); + if (error) + pci_err(dev, "unable to allocate suspend buffer for LTR\n"); + pci_allocate_vc_save_buffers(dev); } -- 2.19.1