Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2656374rdb; Mon, 5 Feb 2024 13:21:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IERfi6IpeqqKtLfk50bL1TS4n05R0yrtY7q7o7/XDP9rNTjM4HjXGFhAS5MvBO88caQsNbj X-Received: by 2002:ac8:5812:0:b0:42c:95b:2f4b with SMTP id g18-20020ac85812000000b0042c095b2f4bmr425234qtg.6.1707168085412; Mon, 05 Feb 2024 13:21:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707168085; cv=pass; d=google.com; s=arc-20160816; b=smcPOUdvyoXGwoJwNCI+SwBwtXvdPHN9coTXMTUOGBSDSyDUs4jAfxL4M1fpRemC9J t5Ji3KnZeJUcRJWLWiNrFpySnRwOMCFnFGCMJI7Yxknhol0KeeALHuv3yueCM6n4IUiF 1eFnkioPiLsch1xKhIgzyWYkxMbTkb+CTIaT+dV5w6b/iDF5JRojXBfnql7CPNDm0VQr tsurnMCSjgOR5x4SYSsxUdqofG4n3zvCUJXXgefpPO7aviX1Q5uebmJAkPKk3iN6X3w0 Vu6CbN23Ez3KaOm364UK23tCoAKRKsVL3uzU9F7WmrA+omatpYyiZVw8/N9Qeomerx6Q M2IA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:organization:autocrypt :references:in-reply-to:date:cc:to:reply-to:from:subject:message-id :dkim-signature; bh=6uTSFZRu5EsCFx15Z4ozMs0bf0vcy4h4g5kdhEEaAXw=; fh=rN8PhmqYty4EdCPi7RN5q4S8bNLKQ5kMDFp4VH/zrV8=; b=C0CnE4j1YRCb0dsEsUgj50YZiA49x2Yf5CmmyEXwBIUlzI9FfDBlLlw1WuwDeg3pjr qmAKFnRx44JDl+pkUiZbfOI0pLupuerI0a0a3yDx9hGAQ+qH6Vz1Mv4rcsZ/JmefO1h6 cGTsRmk1OdEaBwbpkYLmtvbQ9YOt8aTiNAZdrKp2UylRTz9atrhPdThN7VTUjNLQlTxU OX8VC/WCPoGls5xL3x3wpP1khh44SiD1mHGUdAkuqsnZAetKVIwoywIsX+L5b3wspG4r CHNQxHoDyjeEPOdEmTZSOfSjFYh73A0ff1Q6MktL6KjOV206JFmhdMzVlzHz8nLgw2Zr UgwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FJMZp2uH; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-53827-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53827-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUeIGhDdPWCEPXip1VmmolPd11u7KuxFlyORPg44G/aum4RAVVB6XSj4jVFKv9V9r851aq66o3jlfXtEeJZ4CGirJ7SP2XyKkoIg/BDPQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f5-20020a05622a104500b0042c2bd2a2fasi771096qte.241.2024.02.05.13.21.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:21:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53827-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FJMZp2uH; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-53827-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53827-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0164F1C230E5 for ; Mon, 5 Feb 2024 21:21:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 463DB5FF08; Mon, 5 Feb 2024 19:37:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FJMZp2uH" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A28E5FDAC; Mon, 5 Feb 2024 19:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707161840; cv=none; b=u/6eQU+6UAtblF1qWRtTePVhO/EldDAI1vmN/sm0NYA5AJ9F/sDtEihyHKGYDBha05wt4eOPcShqXo8e2cpvNwvjLJyrHzXD4U76VyDTEbHuBVNSowVz5z7oR9EauyWNyXs8ikRXohr45rqXFSgsIStKzfDGyMna5mZtg8mr66c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707161840; c=relaxed/simple; bh=lYOVq8gC/3CmtMF6bjXNprwIT8xsEyDvHUPhbIOenuc=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=scIds38DIcWSjg+kBZem2IG9ScJcZe5MG1keVfSOTUYmMGuYIxz0I0/o5uFTMOZ3KWAEymW2lQJ3H68K0EG/5QfoNi7dEeRUL8rJnMMCUq8yv2x+WAqbtVtF3OWxYlJvzwujnYbVgNJ+ag/IRxjQx4Gno8Rb1BezIEQk0XZ9qI8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FJMZp2uH; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707161838; x=1738697838; h=message-id:subject:from:reply-to:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=lYOVq8gC/3CmtMF6bjXNprwIT8xsEyDvHUPhbIOenuc=; b=FJMZp2uH3up1nIqyx5ljwXE7J8sQdLxvPSUVpa+HEjwUSAE/QxtUdcIY 68GS/aq8iDOxdwiYK75rL5evdh+xoGcM8IuR3/WT2Sn5/i0mF3t598x1U ZDVzWf8QI9JUGPvT6X5MyNnzubptp6JdXe4LM92AEH+5MJtS3cTZAJlkV YwX83hIBKospCbJBooCA2XThAYUEFvDEjuTMG/ovQEqOXZW57jkXGZH6j 07I7lT/itzyInM5zq+lqsu9rajG4+4PXbN84Xiknf/QVmEDSgDiE/M8Pv 4WsTraPJRjmk2kJ3X+wqFqH4QvR5k2ljZuJ8qgKmtz3+tojZjPRHcbbS/ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10975"; a="26039532" X-IronPort-AV: E=Sophos;i="6.05,245,1701158400"; d="scan'208";a="26039532" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 11:37:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,245,1701158400"; d="scan'208";a="5423366" Received: from linux.intel.com ([10.54.29.200]) by fmviesa003.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Feb 2024 11:37:17 -0800 Received: from [10.54.75.156] (debox1-desk1.jf.intel.com [10.54.75.156]) by linux.intel.com (Postfix) with ESMTP id 83366580D9C; Mon, 5 Feb 2024 11:37:16 -0800 (PST) Message-ID: Subject: Re: [PATCH v2] PCI: vmd: Enable PCI PM's L1 substates of remapped PCIe Root Port and NVMe From: "David E. Box" Reply-To: david.e.box@linux.intel.com To: Bjorn Helgaas , Jian-Hong Pan Cc: Johan Hovold , Mika Westerberg , Damien Le Moal , Niklas Cassel , Nirmal Patel , Jonathan Derrick , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux@endlessos.org Date: Mon, 05 Feb 2024 11:37:16 -0800 In-Reply-To: <20240203000510.GA738687@bhelgaas> References: <20240203000510.GA738687@bhelgaas> Autocrypt: addr=david.e.box@linux.intel.com; prefer-encrypt=mutual; keydata=mQENBF2w2YABCACw5TpqmFTR6SgsrNqZE8ro1q2lUgVZda26qIi8GeHmVBmu572RfPydisEpCK246rYM5YY9XAps810ZxgFlLyBqpE/rxB4Dqvh04QePD6fQNui/QCSpyZ6j9F8zl0zutOjfNTIQBkcar28hazL9I8CGnnMko21QDl4pkrq1dgLSgl2r2N1a6LJ2l8lLnQ1NJgPAev4BWo4WAwH2rZ94aukzAlkFizjZXmB/6em+lhinTR9hUeXpTwcaAvmCHmrUMxeOyhx+csO1uAPUjxL7olj2J83dv297RrpjMkDyuUOv8EJlPjvVogJF1QOd5MlkWdj+6vnVDRfO8zUwm2pqg25DABEBAAG0KkRhdmlkIEUuIEJveCA8ZGF2aWQuZS5ib3hAbGludXguaW50ZWwuY29tPokBTgQTAQgAOBYhBBFoZ8DYRC+DyeuV6X7Mry1gl3p/BQJdsNmAAhsDBQsJCAcCB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KHOzhfFKs3cMufwIIoQUPVqGVeH+u6Asun6ZpNRxdDONop+uEXHe6q6LzI/NnczqoZQLhM8d1XqokYax/IZ4= Organization: David E. Box Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.2 (3.50.2-1.fc39) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Fri, 2024-02-02 at 18:05 -0600, Bjorn Helgaas wrote: > On Fri, Feb 02, 2024 at 03:11:12PM +0800, Jian-Hong Pan wrote: > > The remapped PCIe Root Port and NVMe have PCI PM L1 substates > > capability, but they are disabled originally: > >=20 > > Here is an example on ASUS B1400CEAE: > >=20 > > Capabilities: [900 v1] L1 PM Substates > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 L1SubCap: PCI-PM_L1.2+ PCI-P= M_L1.1- ASPM_L1.2+ ASPM_L1.1- > > L1_PM_Substates+ > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 PortCommonModeRestoreTime=3D32us PortTPow= erOnTime=3D10us > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 L1SubCtl1: PCI-PM_L1.2- PCI-= PM_L1.1- ASPM_L1.2+ ASPM_L1.1- > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 T_CommonMode=3D0us LTR1.2_Threshold= =3D0ns > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 L1SubCtl2: T_PwrOn=3D10us > >=20 > > Power on all of the VMD remapped PCI devices and quirk max snoop LTR > > before enable PCI-PM L1 PM Substates by following "Section 5.5.4 of PCI= e > > Base Spec Revision 6.0". Then, PCI PM's L1 substates control are > > initialized & enabled accordingly. >=20 > > Also, update the comments of > > pci_enable_link_state() and pci_enable_link_state_locked() for > > kernel-doc, too. >=20 > The aspm.c changes should be in a separate patch.=C2=A0 Presumably the > aspm.c code change fixes a defect, and that defect can be described in > that patch.=C2=A0 That fix may be needed for non-VMD situations, and havi= ng > it in this vmd patch means it won't be as easy to find and backport. >=20 > Nit: rewrap commit log to fill 75 columns. >=20 > > @@ -751,11 +751,9 @@ static int vmd_pm_enable_quirk(struct pci_dev *pde= v, > > void *userdata) > > =C2=A0 if (!(features & VMD_FEAT_BIOS_PM_QUIRK)) > > =C2=A0 return 0; > > =C2=A0 > > - pci_enable_link_state_locked(pdev, PCIE_LINK_STATE_ALL); > > - > > =C2=A0 pos =3D pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_LTR); > > =C2=A0 if (!pos) > > - return 0; > > + goto out_enable_link_state; > > =C2=A0 > > =C2=A0 /* > > =C2=A0 * Skip if the max snoop LTR is non-zero, indicating BIOS has se= t > > it > > @@ -763,7 +761,7 @@ static int vmd_pm_enable_quirk(struct pci_dev *pdev= , > > void *userdata) > > =C2=A0 */ > > =C2=A0 pci_read_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, <r_re= g); > > =C2=A0 if (!!(ltr_reg & (PCI_LTR_VALUE_MASK | PCI_LTR_SCALE_MASK))) > > - return 0; > > + goto out_enable_link_state; > > =C2=A0 > > =C2=A0 /* > > =C2=A0 * Set the default values to the maximum required by the platfor= m > > to > > @@ -775,6 +773,14 @@ static int vmd_pm_enable_quirk(struct pci_dev *pde= v, > > void *userdata) > > =C2=A0 pci_write_config_dword(pdev, pos + PCI_LTR_MAX_SNOOP_LAT, ltr_re= g); > > =C2=A0 pci_info(pdev, "VMD: Default LTR value set by driver\n"); >=20 > You're not changing this part, and I don't understand exactly how LTR > works, but it makes me a little bit queasy to read "set the LTR value > to the maximum required to allow the deepest power management > savings" and then we set the max snoop values to a fixed constant. >=20 > I don't think the goal is to "allow the deepest power savings"; I > think it's to enable L1.2 *when the device has enough buffering to > absorb L1.2 entry/exit latencies*. >=20 > The spec (PCIe r6.0, sec 7.8.2.2) says "Software should set this to > the platform's maximum supported latency or less," so it seems like > that value must be platform-dependent, not fixed. >=20 > And I assume the "_DSM for Latency Tolerance Reporting" is part of the > way to get those platform-dependent values, but Linux doesn't actually > use that yet. This may indeed be the best way but we need to double check with our BIOS f= olks. AFAIK BIOS writes the LTR values directly so there hasn't been a need to us= e this _DSM. But under VMD the ports are hidden from BIOS which is why we add= ed it here. I've brought up the question internally to find out how Windows handl= es the DSM and to get a recommendation from our firmware leads. >=20 > I assume that setting the max values incorrectly may lead to either > being too conservative, so we don't use L1.2 when we could, or too > aggressive, so we use L1.2 when we shouldn't, and the device loses > data because it doesn't have enough internal buffering to absorb the > entry/exit delays. >=20 > This paper has a lot of background and might help answer some of my > questions: > https://www.intel.co.za/content/dam/doc/white-paper/energy-efficient-plat= forms-white-paper.pdf >=20 > > +out_enable_link_state: > > + /* > > + * Make PCI devices at D0 when enable PCI-PM L1 PM Substates from > > + * Section 5.5.4 of PCIe Base Spec Revision 6.0 > > + */ > > + pci_set_power_state_locked(pdev, PCI_D0); > > + pci_enable_link_state_locked(pdev, PCIE_LINK_STATE_ALL); >=20 > Hmmm.=C2=A0 PCIE_LINK_STATE_ALL includes ASPM L1.2.=C2=A0 We may do this = even if > the device doesn't have an LTR Capability.=C2=A0 ASPM L1.2 cannot work > without LTR. >=20 > I only took a quick look but was not convinced that > pci_enable_link_state() does the right thing when we enable > PCIE_LINK_STATE_ALL (including ASPM L1.2) on a device that doesn't > have LTR.=C2=A0 I think it *should* decline to set PCI_L1SS_CTL1_ASPM_L1_= 2, > but I'm not sure it does.=C2=A0 Can you double check that path?=C2=A0 May= be > that's another defect in aspm.c. It doesn't currently decline. The same scenario happens when the user selec= ts powersupersave. If a device advertises L1.2 with the capable registers set,= it should also have the LTR register present. But it doesn't hurt to check. David >=20 > > @@ -1164,6 +1164,8 @@ static int __pci_enable_link_state(struct pci_dev > > *pdev, int state, bool locked) > > =C2=A0 link->aspm_default |=3D ASPM_STATE_L1_1_PCIPM | > > ASPM_STATE_L1; > > =C2=A0 if (state & PCIE_LINK_STATE_L1_2_PCIPM) > > =C2=A0 link->aspm_default |=3D ASPM_STATE_L1_2_PCIPM | > > ASPM_STATE_L1; > > + if (state & ASPM_STATE_L1_2_MASK) > > + aspm_l1ss_init(link); > > =C2=A0 pcie_config_aspm_link(link, policy_to_aspm_state(link)); > > =C2=A0 > > =C2=A0 link->clkpm_default =3D (state & PCIE_LINK_STATE_CLKPM) ? 1 : 0;