Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2752488imu; Thu, 29 Nov 2018 09:39:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/VGu8AexM2+Z6hPUWfTPlJ+34jPSnzkOs91CUZszQj13ZSRmFYkA/Z0QRO/UYs9qYu56AP7 X-Received: by 2002:a17:902:28e9:: with SMTP id f96mr2368213plb.169.1543513168841; Thu, 29 Nov 2018 09:39:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543513168; cv=none; d=google.com; s=arc-20160816; b=svrj+6cjjC8urVIFlQfCI7yVJt8klEOsDqL/lyos6TuTivGx5mGoQj0fe7qNzEfVaT 7erN4F4hUBsnC3elT+cHjltXQOx/6uWSNcWeChzNTpNiECjJYqDjiYp/B2przMPM9nfq /cOrICqV4KxKiovTYKyMe261zjpvi94m7+ms6q409XUTPb1b0JIMk7KnnjuGcbhhzlOF +tieRDdBWCfUqDSwVqPu5tn77q+0UIpjDKluVJjjEK2fDT/Qc+SJTMmo/96k2dyu3cUK 2WOG4BDV8YkDAmbUHDpHGOaBaPTSPuT0xhkTTs80sGUkndBJdIUPALtmMfbngbpImZk3 vIbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mbF8jgAYqfFEyo0TJlZbb997fm3x4D6CCpcWt6df7Iw=; b=cGK19xnYaITFRne+V/7XvJOxCQYjkP5d4TF6PNaHR0kUBdOZi3sow4BMbvJw5LYE/R uBaer91oVyjm3Z0RtxXUp8ptdQzbDW1IwsvE5udZkBLLWUSdkR+GVDYfxM3wUXEYhx9d 7tE/NmcLFHgHBUy8ZYSayY+Uyt+4RD8dqLrkd8fO+97T2nJv9Ng25UYC65AlK9hZvm/c KeqEbhx4yyXyA0gXJEarDrz8TvFeEijoYHHFyBU4Bxqw7uqOZNBZneKzVZiB3yJbBWnf ABbnxZGwCmAimA8/pK4sexqfWeRMFKpol+HLx4F/UMU4aVGsUbUOZjw9j/MlnSQSInwK Hn7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eosdVTlw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n4si2606198pgm.487.2018.11.29.09.39.11; Thu, 29 Nov 2018 09:39:28 -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; dkim=pass header.i=@kernel.org header.s=default header.b=eosdVTlw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730624AbeK3EmE (ORCPT + 99 others); Thu, 29 Nov 2018 23:42:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:46310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729320AbeK3EmE (ORCPT ); Thu, 29 Nov 2018 23:42:04 -0500 Received: from localhost (unknown [64.22.249.253]) (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 715762145D; Thu, 29 Nov 2018 17:35:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543512955; bh=45zONuEEIypRmhWIQjwcM10CFq021tG7aO2mMTvw5jg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eosdVTlw8gNwbr7Llcv7GeuA69npxTMQ5PbHCkMUvDcFoyaD189v5XVQumT/zdC8z VW59ZUrgnb8Lngyl3UC0uQqV8y4qscsA0PCGvHfnpyGi4TlSIplw1sziL2WL0eL2pI C5LLgRq+BEEpCF7PdLnr7Vjne72vbr98KDv01Kxs= Date: Thu, 29 Nov 2018 11:35:53 -0600 From: Bjorn Helgaas To: Alexandru Gagniuc Cc: austin_bolen@dell.com, alex_gagniuc@dellteam.com, keith.busch@intel.com, Shyam_Iyer@Dell.com, lukas@wunner.de, Mika Westerberg , 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: <20181129173553.GD178809@google.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> 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 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(). I like the concept of this. What I don't like is the fact that it's tied to pciehp, since I don't think the concept of Link Bandwidth Notification is related to hotplug. So I think we'll only notice this for ports that support hotplug. Maybe it's worth doing it this way anyway, even if it could be generalized in the future? > 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; > > /* > * 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); > + > + if (link_status & PCI_EXP_LNKSTA_LBMS) { > + if (pdev->subordinate && pdev->subordinate->self) > + endpoint = pdev->subordinate->self; > + 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); > } > > static void pcie_disable_notification(struct controller *ctrl) > -- > 2.17.1 >