Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2646605imu; Thu, 29 Nov 2018 08:08:23 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vc45KlIpbm8oPfqFuPUs7ih1ZCYVLm9D9taf+0sVu4MOlmuMU7C/sP5Pu7UOqugGeNe0hK X-Received: by 2002:a62:5884:: with SMTP id m126mr1922673pfb.177.1543507703908; Thu, 29 Nov 2018 08:08:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543507703; cv=none; d=google.com; s=arc-20160816; b=IPb1YPFfEWaxTxX7Z0+I7TZ+RpgQ4yToHxPgoqY854d+5U7BroCfrJo6TEa9Mjgrz+ qYhxvRN5du+ekwTV4PiZ1I0A3rDEct1xRXLH0Lr315aI247OKm/7sykNX1AuA3lyJbXq WceJBht8lInfoMEF9kpDa9DwBViDARqZbTPLTgK7i3l3AePduYou8QdCsEziQEoIptl0 hjh1MACGu4DsVPoFH+z3F1UOUaAtwtAuwNZPltamyDTLACTo6fQqjqUoXC0eQ/LCzss0 g6xdfMwx5soG/3+89xOm8D5j4GXykq65lctQuhNH9GHi/WQrzJXpMHZdX/Qu8i5PrkcV hzAQ== 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=n2lcmaVdwAeQ4EagjOUAgM9etxwU/Qow1QLYGRnftQg=; b=QcYZCUEeZorKWYHS3kjPQBrGufxpC0zicNezUzXAuCA18VTqQ/a3CrK6kysyZ+Rf0k +WJbMDe6OfVMsCgRxfjddOFJ5ejtkao0+xqiT22v3c/zfy1rrD3MASNdlYth9f/m5w52 OKxnbDZgLi0u644O31SXlvAEbIWa0K8uynI/T3PdxTb64gLiDQRjrGwTZxeZC1hHO4mw /D6Pp9A0nJ7ab29gUDxLBlruViq2eYbZuhwlsKxW6lke3SVFK4pVZxPsxdw7JRW5fz8p /0K3h8hJKuIcuMh1IzbeGv5Rlz5D4N9Z7EPe3e/BfTmTnWisMtGo532UHDGh2TjycZpg t6JQ== 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 bf4si2393918plb.163.2018.11.29.08.07.53; Thu, 29 Nov 2018 08:08:23 -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 S1729129AbeK3DMX (ORCPT + 99 others); Thu, 29 Nov 2018 22:12:23 -0500 Received: from mga04.intel.com ([192.55.52.120]:2359 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728635AbeK3DMX (ORCPT ); Thu, 29 Nov 2018 22:12:23 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 29 Nov 2018 08:06:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,295,1539673200"; d="scan'208";a="94065035" Received: from lahna.fi.intel.com (HELO lahna) ([10.237.72.157]) by orsmga007.jf.intel.com with SMTP; 29 Nov 2018 08:06:26 -0800 Received: by lahna (sSMTP sendmail emulation); Thu, 29 Nov 2018 18:06:26 +0200 Date: Thu, 29 Nov 2018 18:06:25 +0200 From: Mika Westerberg To: Alexandru Gagniuc Cc: bhelgaas@google.com, austin_bolen@dell.com, alex_gagniuc@dellteam.com, keith.busch@intel.com, Shyam_Iyer@dell.com, lukas@wunner.de, Sinan Kaya , "Rafael J. Wysocki" , Oza Pawandeep , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] PCI: pciehp: Report degraded links via link bandwidth notification Message-ID: <20181129160625.GC3078@lahna.fi.intel.com> References: <20181129000829.14751-1-mr.nuke.me@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181129000829.14751-1-mr.nuke.me@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alexandru, On Wed, Nov 28, 2018 at 06:08:24PM -0600, Alexandru Gagniuc wrote: > A warning is generated when a PCIe device is probed with a degraded > link, but there was no similar mechanism to warn when the link becomes > degraded after probing. The Link Bandwidth Notification provides this > mechanism. > > Use the link bandwidth notification interrupt to detect bandwidth > changes, and rescan the bandwidth, looking for the weakest point. This > is the same logic used in probe(). > > Signed-off-by: Alexandru Gagniuc > --- > drivers/pci/hotplug/pciehp_hpc.c | 35 +++++++++++++++++++++++++++++++- > 1 file changed, 34 insertions(+), 1 deletion(-) > > diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c > index 7dd443aea5a5..834672000b59 100644 > --- a/drivers/pci/hotplug/pciehp_hpc.c > +++ b/drivers/pci/hotplug/pciehp_hpc.c > @@ -515,7 +515,8 @@ static irqreturn_t pciehp_isr(int irq, void *dev_id) > struct controller *ctrl = (struct controller *)dev_id; > struct pci_dev *pdev = ctrl_dev(ctrl); > struct device *parent = pdev->dev.parent; > - u16 status, events; > + struct pci_dev *endpoint; > + u16 status, events, link_status; Looks better if you write them in opposite order (reverse xmas-tree): u16 status, events, link_status; struct pci_dev *endpoint; > /* > * Interrupts only occur in D3hot or shallower and only if enabled > @@ -525,6 +526,17 @@ static irqreturn_t pciehp_isr(int irq, void *dev_id) > (!(ctrl->slot_ctrl & PCI_EXP_SLTCTL_HPIE) && !pciehp_poll_mode)) > return IRQ_NONE; > > + pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &link_status); > + Unnecessary empty line. > + if (link_status & PCI_EXP_LNKSTA_LBMS) { > + if (pdev->subordinate && pdev->subordinate->self) > + endpoint = pdev->subordinate->self; Hmm, I thought pdev->subordinate->self == pdev, no? > + else > + endpoint = pdev; > + __pcie_print_link_status(endpoint, false); > + pcie_capability_write_word(pdev, PCI_EXP_LNKSTA, link_status); > + } > + > /* > * Keep the port accessible by holding a runtime PM ref on its parent. > * Defer resume of the parent to the IRQ thread if it's suspended. > @@ -677,6 +689,24 @@ static int pciehp_poll(void *data) > return 0; > } > > +static bool pcie_link_bandwidth_notification_supported(struct controller *ctrl) > +{ > + int ret; > + u32 cap; > + > + ret = pcie_capability_read_dword(ctrl_dev(ctrl), PCI_EXP_LNKCAP, &cap); > + return (ret == PCIBIOS_SUCCESSFUL) && (cap & PCI_EXP_LNKCAP_LBNC); > +} > + > +static void pcie_enable_link_bandwidth_notification(struct controller *ctrl) > +{ > + u16 lnk_ctl; > + > + pcie_capability_read_word(ctrl_dev(ctrl), PCI_EXP_LNKCTL, &lnk_ctl); > + lnk_ctl |= PCI_EXP_LNKCTL_LBMIE; > + pcie_capability_write_word(ctrl_dev(ctrl), PCI_EXP_LNKCTL, lnk_ctl); > +} > + > static void pcie_enable_notification(struct controller *ctrl) > { > u16 cmd, mask; > @@ -713,6 +743,9 @@ static void pcie_enable_notification(struct controller *ctrl) > pcie_write_cmd_nowait(ctrl, cmd, mask); > ctrl_dbg(ctrl, "%s: SLOTCTRL %x write cmd %x\n", __func__, > pci_pcie_cap(ctrl->pcie->port) + PCI_EXP_SLTCTL, cmd); > + > + if (pcie_link_bandwidth_notification_supported(ctrl)) > + pcie_enable_link_bandwidth_notification(ctrl); Do we ever need to disable it? > } > > static void pcie_disable_notification(struct controller *ctrl) > -- > 2.17.1