Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp562982ybx; Tue, 5 Nov 2019 01:55:48 -0800 (PST) X-Google-Smtp-Source: APXvYqyHfqNWiDSeH+rHwwKlIDUQ2ZVUHEgWG8rbOyKjJzw53J6PyAu72IUASIUrMtYwUx8mpnQ8 X-Received: by 2002:a05:6402:1146:: with SMTP id g6mr29847106edw.215.1572947747984; Tue, 05 Nov 2019 01:55:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572947747; cv=none; d=google.com; s=arc-20160816; b=r3k8NFNY2cGHKSSgN80WFT724xCFS6QsTLq3l03+wdYGXIdNWHWhLMQB+2aXaJY5De 1rt1AdIP9KL2vkAEkTHqnxBtZx42H3iGfLXB0tf4JzMlLVquIkscAUhZIbeg2S1hvHVP svk25dURhbTG9UyaUXOtlnpFTFfrM0+Dz8S9I0eTiCJDjJBcf7va9t1bVnrFwpFlHoAN m0+p/NdcKl2j2Xf/OYIoH9iIFZjyJZsGVJmI57bQd2E2nlmpnq81EMATFsu5DWpa4oCT dgI/HHANXGGYXm8NE4lHOH7MFI3lDTz1BDx11h+Q/eNnK3/A8GaRHzjyJ7jrV5P13I/F ZBHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=uyjHMRWnRXA7NTgx4WoXyjRK63u3KfdPKXXCwMlMvlE=; b=NebaCD0S18iDzza7+LTNheP07SVMetWFkKZGSeUoeEgIMzjBDywTO3yU9mO8t6CtFY 3mv5LfK8txyBkkkMSEdnasTtTT9fnuY86CEeHihEPRIU46aPZBcFNBZQDHUBYpL1Go8w YcI6+eETG+Lzg5hh9znLAtxuOegXph3D3r1Y1YRq9DdEJjGfAkOyURS/VoFqpltJZBrL WcBqkOgRFmD+daUy+DrPZX70FJCSmU0NuWkJE8ZXUuuzXpwVM6PuK0fTt8dwrWR7MCd7 gZx2O1Oxb9U7TnzyJWDCUpqIyCpexlIhgq+nB8pSiDg4/43R4l5NC1SI/rrW03EEIMWl 95sA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ks2si11778288ejb.396.2019.11.05.01.55.23; Tue, 05 Nov 2019 01:55:47 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388083AbfKEJye (ORCPT + 99 others); Tue, 5 Nov 2019 04:54:34 -0500 Received: from mga11.intel.com ([192.55.52.93]:3948 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730571AbfKEJyd (ORCPT ); Tue, 5 Nov 2019 04:54:33 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Nov 2019 01:54:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,270,1569308400"; d="scan'208";a="212507068" Received: from lahna.fi.intel.com (HELO lahna) ([10.237.72.163]) by fmsmga001.fm.intel.com with SMTP; 05 Nov 2019 01:54:29 -0800 Received: by lahna (sSMTP sendmail emulation); Tue, 05 Nov 2019 11:54:28 +0200 Date: Tue, 5 Nov 2019 11:54:28 +0200 From: Mika Westerberg To: Bjorn Helgaas Cc: "Rafael J. Wysocki" , Len Brown , Lukas Wunner , Keith Busch , Alex Williamson , Alexandru Gagniuc , Kai-Heng Feng , Paul Menzel , Nicholas Johnson , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/2] PCI: Add missing link delays required by the PCIe spec Message-ID: <20191105095428.GR2552@lahna.fi.intel.com> References: <20191101111918.GL2593@lahna.fi.intel.com> <20191105000000.GA126282@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191105000000.GA126282@google.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 04, 2019 at 06:00:00PM -0600, Bjorn Helgaas wrote: > > > > > The outline of the pci_pm_resume_noirq() part of this patch is: > > > > > > > > > > pci_pm_resume_noirq > > > > > if (!dev->skip_bus_pm ...) # <-- condition 1 > > > > > pci_pm_default_resume_early > > > > > pci_power_up > > > > > if (platform_pci_power_manageable()) # _PS0 or _PR0 exist? > > > > > platform_pci_set_power_state > > > > > pci_platform_pm->set_state > > > > > acpi_pci_set_power_state(PCI_D0) # acpi_pci_platform_pm.set_state > > > > > acpi_device_set_power(ACPI_STATE_D0) # <-- eval _PS0 > > > > > + if (d3cold) # <-- condition 2 > > > > > + pci_bridge_wait_for_secondary_bus > > > The reason why pci_bridge_wait_for_secondary_bus() is called almost the > > last is that I figured we want to resume the root/downstream port > > completely first before we start delaying for the device downstream. > > For understandability, I think the wait needs to go in some function > that contains "PCI_D0", e.g., platform_pci_set_power_state() or > pci_power_up(), so it's connected with the transition from D3cold to > D0. > > Since pci_pm_default_resume_early() is the only caller of > pci_power_up(), maybe we should just inline pci_power_up(), e.g., > something like this: > > static void pci_pm_default_resume_early(struct pci_dev *pci_dev) > { > pci_power_state_t prev_state = pci_dev->current_state; > > if (platform_pci_power_manageable(pci_dev)) > platform_pci_set_power_state(pci_dev, PCI_D0); > > pci_raw_set_power_state(pci_dev, PCI_D0); > pci_update_current_state(pci_dev, PCI_D0); > > pci_restore_state(pci_dev); > pci_pme_restore(pci_dev); > > if (prev_state == PCI_D3cold) > pci_bridge_wait_for_secondary_bus(dev); > } OK, I'll see if this works. > I don't understand why we call both platform_pci_set_power_state() and > pci_raw_set_power_state(). platform_pci_set_power_state() deals with the ACPI methods such as calling _PS0 after D3hot. To transition the device from D3hot to D0 you need the PMCSR write which is done in pci_raw_set_power_state(). > I thought platform_pci_set_power_state() > should put the device in D0, so we shouldn't need the PCI_PM_CTRL > update in pci_raw_set_power_state(), although we probably do need > things like pci_restore_bars() and pcie_aspm_pm_state_change(). > > And in fact, it seems wrong that if platform_pci_set_power_state() > puts the device in D0 and the device lacks a PM capability, we bail > out of pci_raw_set_power_state() before calling pci_restore_bars(). > > Tangent: I think "pci_pm_default_resume_early" is the wrong name for > this because "default" suggests that this is what we fall back to if a > driver or arch doesn't supply a more specific method. But here we're > doing mandatory things that cannot be overridden, so I think something > like "pci_pm_core_resume_early()" would be more accurate. > > > Need to call it before port services (pciehp) is resumed, though. > > I guess this is because pciehp_resume() looks at PCI_EXP_LNKSTA and > will be confused if the link isn't up yet? Yes. > > If you think it is fine to do the delay before we have restored > > everything I can move it inside pci_power_up() or call it after > > pci_pm_default_resume_early() as above. I think at least we should make > > sure all the saved registers are restored before so that the link > > activation check actually works. > > What needs to be restored to make pcie_wait_for_link_delay() work? I'm not entirely sure. I think that pci_restore_state() at least should be called so that the PCIe capability gets restored. Maybe not event that because Data Link Layer Layer Active always reflects the DL_Active or not and it does not need to be enabled separately. > And what event does the restore need to be ordered with? Not sure I follow you here.